• 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!

How would a persongo about using a type of sub variable or creating something stored in something

A

Ancestralsoul

Guest
I am curious and new and while I haven't gotten that far I'd like to eventually store a variable in a variable or something. Like would a macro variable work for that? Or do you just put a variable inside a variable...a sample or example would be nice.
 

chamaeleon

Member
Is this what you mean?
Code:
hello = 55;
world = hello;

cat = world;
show_message(cat); // will display '55'
Very doubtful. I suspect what is looked for is a way to store a reference so that if you were to charge the value of hello displaying cat would show the change. Gms does not support this in a general sense.
 
A

Ancestralsoul

Guest
Very doubtful. I suspect what is looked for is a way to store a reference so that if you were to charge the value of hello displaying cat would show the change. Gms does not support this in a general sense.
What do you mean in a general sense? :) I know it's possible if your making an rpg in game maker, you need to store the characters level so he would apply the function of his attack damage variable so it's random damage but limited upon his level.
 
For something like that you'd just do something like the following:

Code:
level = 5;

damage = irandom_range(minimum amount,maximum amount) * level;
The only thing to watch out for is to make sure you set the level variable first, or else you'll get an error when you try to calculate damage.
 

chamaeleon

Member
What do you mean in a general sense? :) I know it's possible if your making an rpg in game maker, you need to store the characters level so he would apply the function of his attack damage variable so it's random damage but limited upon his level.
Instances and data structures, for instance, use references (their ids), and passing those along between variables doesn't make copies, but allow you to work with the one concrete copy that exist regardless of how you store or assign it.

Functions exist to get and set global and instance variables by name given as a string. Abstractions could be created using data structures. But none of this should be necessary for you if you use instances and data structures in the usual manner, more than likely, especially if you're new to GMS.
 

Joe Ellis

Member
One way of several instances accessing one shared value is to create an array with only one index\slot. (array[0] = value)
So then with any instance you can set a variable to the array id, and rather than copying the value and creating a new variable like it would with a normal variable, it will just get the id of the array itself and hold that in the variable. So then the array can be edited [@ 0] and because all instances are referring to this one array they'll all read the same value if they read from it
 
Top