GameMaker [SOLVED] Accessors accessing variables within the instance

G

gameon

Guest
I have completed, for the most part, my editable text box which is simply a 1D array. I have for the past few days been doing everything I can to restructure the whole thing for faster read times and smaller readable lines. (Getting it to work was first priority)

One of the main ideas was using the accessor (@) in my scripts for direct reading and returning results. I noticed in my code that sometimes I used the local vars and other times I used the instance vars to return the correct output. I knew about accessing the array directly, it seems that I can also access the instance variables within the array too. Here is one case statement in my switch for scr_delete as an example. The only difference is using line and tline.

Instance vars in create:
Code:
case"0010":
txt[@ line + 1] = txt[@ line]
txt[@ line] = "";
VS:

Local temp vars:
Code:
txt[@ tline + 1] = txt[@ tline]
txt[@ tline] = "";
Both line and tline seem to work as they are the same number. Is there any difference between using instance vars and local varss with the accessor within the script?
 

samspade

Member
I don't know if I fully understand your question. The scope of a variable (global, instance, local) does not change the value the variable holds. if line = 0, and tline = 0; then txt[@ line] and txt[@ tline] both are txt[@ 0].

Also, all* scripts run in instances. So a script will have access to the instance variables of whatever instance it is running in.

*Basically 99%+ of code in GM runs in an instance (exceptions are room creation code, layer scripts, and probably a few things I forgot about).
 
G

gameon

Guest
Ahh, yeah. Could have worded that better. Made sense at the time...not sure how. I just wanted to make sure that using the instance vars wasn't going to be a problem I wasn't aware of.

This line answered it:

Also, all* scripts run in instances. So a script will have access to the instance variables of whatever instance it is running in.
@samspade
Do I detect a Myst Fan? Many thanks.
 

samspade

Member
Ahh, yeah. Could have worded that better. Made sense at the time...not sure how. I just wanted to make sure that using the instance vars wasn't going to be a problem I wasn't aware of.

This line answered it:



@samspade
Do I detect a Myst Fan? Many thanks.
Very much so.
 
Top