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

GameMaker view_wport vs. view_set_wport

J

J_Dev

Guest
What is the difference between using these? The documentation declares the first (view_wport) as a variable and the second (view_set_wport) as a function.
But, for example, view_wport can be used to set and get the port width without using the functions. So why use the functions if I can just set/get using the variable? It feels redundant unless I'm missing something?
 
K

kevins_office

Guest
They are kind of redundant.
Using view_set_wport() is changing the variable view_wport for you.
This is done in several places in GML, alarms are another example.
You can do (variable) alarm[0] = 1; or you can do (function) alarm_set(0, 1);

If you are familiar with OOP like Java, its the same idea as having a private variable that cant be accessed outside of the class, so you create methods for people to change those variables.
However in GML the variable is public so you can use the method or access the variable directly.

I did read somewhere once that GML is taking baby steps to maybe going that route someday.
Meaning they have been adding those functions because maybe someday you wont have direct access to the variables in future versions of GML.
But for now either way, changing variables directly, or using the function, will work the same. Your preference.
I personally use the functions because then i don't have to look at the odd variable color in the IDE. :)
 
J

J_Dev

Guest
They are kind of redundant.
Using view_set_wport() is changing the variable view_wport for you.
This is done in several places in GML, alarms are another example.
You can do (variable) alarm[0] = 1; or you can do (function) alarm_set(0, 1);

If you are familiar with OOP like Java, its the same idea as having a private variable that cant be accessed outside of the class, so you create methods for people to change those variables.
However in GML the variable is public so you can use the method or access the variable directly.

I did read somewhere once that GML is taking baby steps to maybe going that route someday.
Meaning they have been adding those functions because maybe someday you wont have direct access to the variables in future versions of GML.
But for now either way, changing variables directly, or using the function, will work the same. Your preference.
I personally use the functions because then i don't have to look at the odd variable color in the IDE. :)
Thanks, that explained it for me!
 
Top