• Hey! Guest! The 39th GMC Jam will take place between November 26th, 12:00 UTC and November 30th, 12:00 UTC. Why not join in! Click here to find out more!
  • 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.

 Suggestion - Enable Explicit

csanyk

Member
I would like that. Variable declaration by assignment is prone to errors due to typos when updating the variable's value later, and declaring a new variable with the misspelled name instead.
 

Mike

nobody important
GMC Elder
Unfortunately this is a runtime thing. There is no way to know a variable is declared or not in a script because it has no idea where its being called from, or what instances are being used inside it. This is only known at runtime, hence a runtime crash if you try to read from undefined variables.

So just can't happen I'm afraid....
 

csanyk

Member
Unfortunately this is a runtime thing. There is no way to know a variable is declared or not in a script because it has no idea where its being called from, or what instances are being used inside it. This is only known at runtime, hence a runtime crash if you try to read from undefined variables.

So just can't happen I'm afraid....
I guess this is why other languages do variable scoping, because then it is knowable at compile time whether the variable has been declared or not in the current scope, so then variables can be explicitly declared.

(I actually look at shortcomings in GML like this as instructive. It has helped me to appreciate why other languages have the features that they do, like private variables, etc. If you never encounter a problem that is prevented entirely by another language's features, then you may not quite appreciate the feature that prevents that problem.)
 
Top