Set many variables at once

Find quick help here to get you started with Hollywood
Post Reply
amyren
Posts: 352
Joined: Thu May 02, 2019 11:53 am

Set many variables at once

Post by amyren »

If I have many bool variables named variable_1, variable_2, variable_3 etc. and I want to set all of them to either true or false.
Is there a simple way to do this without using a single line for each variable?
I tried a few things, but ended up making 50 lines just to get it done.

The example below does not work, since the StringToVariable command is not existing, but it shows what I was looking for.

Code: Select all

for i = 1 to 50
variablename$ = "varialble_"..i
StringToVariable(variablename$) = False
User avatar
jPV
Posts: 600
Joined: Sat Mar 26, 2016 10:44 am
Location: RNO
Contact:

Re: Set many variables at once

Post by jPV »

Just use tables:

Code: Select all

myvar = {}
For Local i = 1 To 50
    Local variablename$ = "variable_"..i
    myvar[variablename$] = False
Next
DebugPrint(myvar.variable_2)
DebugPrint(myvar["variable_2"])
Or skip the string indices and use numbers:

Code: Select all

myvar = {}
For Local i = 1 To 50
    myvar[i] = False
Next
DebugPrint(myvar[2])
amyren
Posts: 352
Joined: Thu May 02, 2019 11:53 am

Re: Set many variables at once

Post by amyren »

Thank you:)
Post Reply