[Closed] For loop inside rolloutcreator
Hello smart people,
I have ui created with rollout creator
I have button 1 2 3 4 5
when i press p, i want the script to press each button according to the for loop.
rci = rolloutCreator “myRollout” “My Rollout”
rci.begin()rci.addcontrol #button #pressall “p” paramStr:(“align: #right”)
for i = 1 to 5 do
(
local samplebutton = (“Sbtn_”+ (i as string)) as namerci.addcontrol #button samplebutton (i as string)
rci.addHandler (“Sbtn_”+ (i as string)) #pressed codeStr:(“format @button %\n@ ” + i as string)
)rci.addHandler #pressall #pressed codeStr:(“for i = 1 to 5 do(Sbtn_i.pressed())”)
rci.end()
createdialog myRollout
and then the error said
– [stack level: 0]
– In i loop
– Parameters:
– i: 1
– Locals:
– Sbtn_i: undefined
– i: 1
– Externals:
– owner: undefined
I’m not sure why i : 1 , but Sbtn_i is undefined.
First see the rci.str, of course “Sbtn_i” is undefined.
You want to raise pressed event on buttons, But first you should know how to access them correctly.
One way is by name. for example : 'Sbtn_5'
Another way is to loop throw Rollout.controls, for example:
foundedButton = undefined
for c in myRollout.controls while foundedButton == undefined where c.name == "Sbtn_44" do foundedButton = c
-- if foundedButton != undefined do ...
Thank you MZ and sorry for the late reply, I just have time check the thread today.
However, I tried with the different approach and it did works.
In case someone is having the same problem,
I put all the buttons into an array and it did works.
in the for loop, i added:
btnarr[i] = “Sbtn_”+ (i as string)
out of the for loop, i changed the code to:
rci.addHandler #pressall #pressed codeStr:(“for i in btnarr do(btnarr[i].pressed())”)