How to draw a something that is stored not in the drawing object, but somewhere else. That was a question that I recieved... and I have not written about it earlier. I guess it's needed; therefore this will be an article on how to do it. It's particularly useful if you have a controller object or something like that. How to do it though, is very simple, for with "stored" I assume it means in a variable. If so, there are two ways to do it: either you adress the variable or you make the variable global. You will be able to read about this in other articles, however, I will make a fast repetition. Global variables works such that if it is initialized in one object it will exist for all. Local variables only exists for the object that initializes it. Global variables has the prefix global. .
global.variable = "value"; //global variable
variable = "value"; // Local variable
One solution is therefore to store the value in a global variable, and then simply draw it; draw_text(x,y,global.variable)... however, if you have many objects of the same kind you might run into trouble, since they might overwrite eachother. That's when you need a local variable, since the only exist for one single instance. You call local variables like this:
(id).variable //For one particular instance
object0.variable //If you only have one instance, or it doesn't matter
object0, of course, is the name of the object where you can locate the variable. id might be a little tricky to find, but you can view it in the room editor and there is several functions that returns the ID of a certain object. Anyhow, this will be how you can draw the different values, depending on how your variable is initialized:
draw_text(x,y,(id).variable);
draw_text(x,y,global.variable);
.
Users logged in:
Comments
Loading comments...