The syntax is VAR("VARIABLE NAME")
This implies that the parameter to VAR must always be a string literal, which is false. More correct to say the syntax is VAR(string value).
What is VAR?
VAR is an essential command and a useful function. VAR is what you use to initialize variables (very important in an OPTION STRICT program) and what you can use to dynamically manipulate variables.How do I use VAR?
Let's start with the most important: it as a command. It is fairly simple. All you need to do is say VAR [parameters]. The parameters are just the variables you would like to declare (e.g. VAR NAME$,AGE%,EXAGE). See, it is simple! You can have 1 item or many (e.g. VAR NAME$,AGE%:VAR EXAGE) and they can be different types. You can also set the initial value on the same line (e.g. VAR AGE%=9001 'IT'S OVER 9000!). Now for the tricky part: it as a function. The syntax is VAR(STRING REPRESENTING VARIABLE). Though a simple syntax, it's uses are interesting. If you try putting in your already defined NAME$, you would say VAR("NAME$")="Johnson". Note the quotation marks; without them, it will try setting the variable (that's blank unless you've already set NAME$ to something) to "Johnson" and give you an error. VAR can also be used to access and modify variables in other slots. The syntax for doing that is VAR(SLOT:VARIABLE STRING). It's all one string though, so it would be, with the NAME$ example, VAR("1:NAME$")="Lyndon B. Johnson". The slot does not need to be a string literal; just like the variable string, it can be stored in a variable (like so):VAR SLOT$="1" VAR VARIABLE$="HANDS" ?FORMAT$("SLOT %S HAS %D HANDS",SLOT$,VAR(SLOT$+":"+VARIABLE$))This generally won't do anything unless you've already ran slot 1 and it ran back to slot (whatever one this is in). It's syntax gets off when you get to arrays. Say if you tried
DIM RATINGS[0] PUSH RATINGS,9 'FANTASTIC! VAR RVAR$="RATINGS" ?FORMAT$("THE RATING FOR THIS MOVIE WAS %D",VAR(RVAR$+"[0]"))Well, I'll congratulate you on making a really interesting system, but alas, it will not work. See, instead of getting the first element in the RATINGS array, it tried to get the value of the variable RATINGS[0] However, if we say ?LEN(VAR("RATINGS")), it will say 1, and if we do this:
DIM RATINGS[0] DIM LIKES[0] PUSH RATINGS,9 PUSH LIKES,6 VAR("RATINGS")=VAR("LIKES")it will work and RATINGS[0] will equal 6.