Hi, All.
Apologies if this si well known, but I googled and searched, maybe ineffectively.
In a sentence-parsing script, I would like to be able to calculate the name of a variable to be set, but I cannot place an expression in the 'set' block, like I can in the costume block. Kind of like pointers and casts.
for example
change to [(join "costume" counter)]
lets the script calculate which costume to change to based on user input or elapsed time or whatever.
however
set (join "varname" index) to c
doesn't seem to exist.
Any ideas?
thanks!
Bill
Offline
You can use a list.
Offline
@lukanater: Thank you! I want to dynamically choose which of several pre-exisiting variables I am setting
@ProgramCAT: thank you, was wondering if there was a way to pass a variable name to set rather than using a list, but could use list instead.
Offline
You can't insert expressions as variable names.
Offline
First of all, it is generally frowned upon to calculate and use variable names in any language. In JavaScript, it is literally a sin to use "eval('var thing'+index+' = 0;')".
You should use a list. Create a list called "myVars", then use the following script:
when gf clicked repeat (number of variables you need) add [null] to [myVars v] endThen you use these blocks to edit them:
say (item (index) of [myVars v]) replace item (index) of [myVars v] with (join [Hey, this ] [works! Thanks, Hardmath123!])Hope this helped!
Last edited by Hardmath123 (2012-03-29 09:20:23)
Offline
whf4 wrote:
yes, thank you, I knew you could do this with lists. Not sure I concur with your global horror of calculating variable names, but I agree an indexed array is cleaner.
In a language like JavaScript, a malicious user could hack the program quite easily indeed.
Offline
whf4 wrote:
yes, thank you, I knew you could do this with lists. Not sure I concur with your global horror of calculating variable names, but I agree an indexed array is cleaner.
it's not THAT bad, but it's a really bad thing to do if there's an alternative like lists.
Offline