PDA

View Full Version : Iterating through those procedural controls...



GrimmSpector
March 3rd, 2016, 18:01
So i've used the code from other threads to setup a bunch of "pips" on a character sheet, they display beautifully, and I can edit their appearance by referencing the control directly, i.e.:

window.standard1.setHealth("pip_filled");

No problems there, but what I need to do is iterate through a number as conditions change, so I won't know how many we're doing, here's a sample:



for i=1,window.standard_current.getValue() do
window.'standard .. tostring(i)'.setHealth(somevalue);
end


Effectively calling "window.standard1.setHealth(value)" then calling "window.standard2.setHealth(value)' for every value of i in the loop, with i being the number in the control object reference.

Now obviously i can't pass a string into an object reference, not by any method I'm aware of, except one, using the lua function loadstring:


f = loadstring("standard" .. tostring(i));
window.f.setHealth(somevalue);


The end result is a dynamic grid of pips whose images change to represent various conditions for the player on their character sheet. It would also be implemented in the vehicles in the ruleset.

Now this should allow me to iterate through, however, the loadstring function doesn't appear to be available in FG, that I can find. I'm not sure if there's a way to make it accessible. Or if someone can point me towards another method. In the meantime I may look into it's implementation and see if I can find some other solution.

darrenan
March 3rd, 2016, 18:12
Could you put all your controls into a windowlist (https://www.fantasygrounds.com/refdoc/windowlist.xcp)?

Moon Wizard
March 3rd, 2016, 18:44
Try using:



window["standard" .. tostring(i)].setHealth(somevalue);


Regards,
JPG

GrimmSpector
March 3rd, 2016, 19:38
Try using:



window["standard" .. tostring(i)].setHealth(somevalue);


Regards,
JPG

Perfect, makes my life much easier, thanks Moon Wizard!