• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!
  • Hello [name]! Thanks for joining the GMC. Before making any posts in the Tech Support forum, can we suggest you read the forum rules? These are simple guidelines that we ask you to follow so that you can get the best help possible for your issue.

how do I use Gamemaker 8.1 variables

S

sevenelevenx8

Guest
so i have an hp variable for a player and in the create event I put relative so it wont reset the variables when I switch rooms but it says Unknown variable when i start the game.
 

Alexx

Member
if you want a variable to have global scope across rooms, you can set it as a global value, for example:
Code:
global.hp = 50;
I guess in your case you would set this in the menu room or splash screen room.
 
S

sevenelevenx8

Guest
wait can I do that in drag and drop or do I have to use code because I don't know how to use code (ps I have the lite version)
 
S

sevenelevenx8

Guest
how dose just naming it global make it global + if i don't set it to relative won't it reset the variable
 

Alexx

Member
relative means something else.
You use relative so you can change the value relative to its current value.
For example if hp has been set as 50:
if you add 5 relative the new value would be 55.
if you just put 5 the new value would be 5.

You should really look up some tututorial videos or books.
Setting variables is a fundamental you need to understand. Until you grasp the basics, you will struggle.
 
S

sevenelevenx8

Guest
but where would i put it because in the create event it would just reset the variable difference from previous rooms causing it to go to the base amount
 
S

sevenelevenx8

Guest
I tried to look this stuff up but i didn't see anything to help my specific problem
 

Alexx

Member
but where would i put it because in the create event it would just reset the variable difference from previous rooms causing it to go to the base amount
Correct.
So just set the starting once at game start, not in each room.
Ideally have a room with one object that sets the initial values needed for the game, then go to the first 'game' room.
 
S

sevenelevenx8

Guest
K thanks that should work and just to verify in drag and drop i have to name it global hp then set it to whatever number then it will just apply to all objects?
 

Alexx

Member
Try it and see what happens!
It won't apply to all objects as such, it will be accessible to read and change.

Also please don't bump your topics!
 
Top