Risking dumb question of the week, who do I get the second line to interpret as the variable
on mouseUp
put "hello" into station3
put 3 into x
answer station & x // I'd like a concatenation to be interpreted as the variable station3 to answer as "hello" but it's station3 the string
answer station3 // this works, but is just here for example
end mouseUp
thanks!
String as Variable
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
-
- VIP Livecode Opensource Backer
- Posts: 10052
- Joined: Sat Apr 08, 2006 7:05 am
- Contact:
Re: String as Variable
Arrays are an excellent fit for problems involving variables with names that can't be known in advance, e.g.:
Code: Select all
on mouseUp
put "hello" into station[3]
put 3 into x
answer station[x]
end mouseUp
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
Re: String as Variable
Hi.
What Richard said.
He said what he said because an array separates the elements of the variable you are trying to reconstruct, that is, the "station" from the "3".
The "do command is much more old-fashioned. It works by forcing another level of evaluation, which can drill into what would normally be an impenetrable concatenation:
"Do" deconstructs the contents of the variable out of its combined form. You can still, as Richard pointed out, manage the "3", or any other instance of the "concatenated" variable using this method as well. It is less modern, though.
Craig Newman
What Richard said.
He said what he said because an array separates the elements of the variable you are trying to reconstruct, that is, the "station" from the "3".
The "do command is much more old-fashioned. It works by forcing another level of evaluation, which can drill into what would normally be an impenetrable concatenation:
Code: Select all
on mouseUp
put "hello" into station3
put 3 into x
do "answer" && "station" & x
end mouseUp
Craig Newman
Re: String as Variable
Thanks, they both work!