Daan1el asked us:
"When i start my game i have created a meny, here you can choose between 2 buttons(objects), a Warriorbutton or a Magebutton.
Here is where i need help: When i click the warriorbutton i want the game to change room and the Warrior(object) shall be placed in the new room and the mage(object) shall not be there."
This is a typical situation for which you would use a global variable. Local variables can only be used within the same object, but global variables, once set, can be used by any object throughout the game, and it doesn't matter in which room.
In the left mouse button event that you've already created in order to go to another room, you will have to assign a value to a global variable in order to indicate if the user chose 1) mage or 2) warrior. So this is an example of a piece of code that would've worked:
global.type = 1; //for mage
room_goto_next();
Now in the next room we need something to interpret this so we put another piece of code in any of the already existing objects that will tell it to create an instance of either mage or warrior. For example:
if (global.type == 1) instance_create(x,y,mage);
else instance_create(x,y,warrior);
Note that global variables work like normal variables but are preceded by global..
.
Users logged in:
Comments
Loading comments...