-
October 6th, 2019, 13:14 #1
Access window object via dynamic var naming
Afternoon Folks,
Another one that's getting to me.
Code:for _,v in pairs(savedDiceRoll) do i = i + 1; if i == 1 then setDiceIcons(["dice" .. 1], v) elseif i == 2 then setDiceIcons(dice2, v) elseif i == 3 then setDiceIcons(dice3, v) elseif i == 4 then setDiceIcons(dice4, v) elseif i == 5 then setDiceIcons(dice5, v) elseif i == 6 then setDiceIcons(dice6, v) elseif i == 7 then setDiceIcons(dice7, v) elseif i == 8 then setDiceIcons(dice8, v) elseif i == 9 then setDiceIcons(dice9, v) elseif i == 10 then setDiceIcons(dice10, v) else end end
Any thoughts on how to do this would be ace!
Cheers,
MBMRuleset and much more content built for FGU.
Come join me on Twitter at: https://twitter.com/MadBeardMan to see what I'm up to!
-
October 6th, 2019, 13:54 #2
- Join Date
- Jun 2013
- Location
- Isanti, MN
- Posts
- 2,922
Create a table and index into it.
-
October 6th, 2019, 14:47 #3Ruleset and much more content built for FGU.
Come join me on Twitter at: https://twitter.com/MadBeardMan to see what I'm up to!
-
October 6th, 2019, 15:47 #4
- Join Date
- Jun 2013
- Location
- Isanti, MN
- Posts
- 2,922
Code:local myTable = { dice1, dice2, dice3, dice4, dice5 }; local diceToSet = myTable[i]; setDiceIcon(diceToSet, v);
-
October 6th, 2019, 16:34 #5
Amazing! Thanks so very much. Not quite what I'd do in other languages but works a treat!
WillpowerRolls.jpg
Now onto allow the Dice to be re-rolled.
Cheers,
MBMRuleset and much more content built for FGU.
Come join me on Twitter at: https://twitter.com/MadBeardMan to see what I'm up to!
-
October 6th, 2019, 17:52 #6
Sounds like you already have a solution but I thought I'd throw out the "getControls()" option for at least review. I found it quiet useful. You can grab all the controls within a window/scope and match them how you like.
You can also use something like this perhaps.
Code:local sMatrixNumberName = "thac" .. i; -- control name for the THACO label local cnt = self[sMatrixNumberName]; -- get the control for this, stringcontrol named thac-10 .. thac10 cnt.setValue(nTHAC); -- set new to hit AC value
I've a hard time following exactly what you're trying to go for so it might be off in left field but I thought I would mention it.---
Fantasy Grounds AD&D Reference Bundle, AD&D Adventure Bundle 1, AD&D Adventure Bundle 2
Documentation for AD&D 2E ruleset.
Custom Maps (I2, S4, T1-4, Barrowmaze,Lost City of Barakus)
Note: Please do not message me directly on this site, post in the forums or ping me in FG's discord.
-
October 6th, 2019, 18:04 #7
That's actually what I was after, the 'self' part returns the var as an object, which is what I was wanting.
I went with Andraax's suggestion and it's just as good, thanks though, it's great to know what I want to do, can be done.
Here's my final code, this populates a window with 10 dice and sets them to the correct dice graphic (as shown in my last post).
Code:function onInit() -- let's read the saved nodeWin = getDatabaseNode() local savedDiceRoll = DB.getChildren(nodeWin, 'savedroll') local i = 0; local myTable = { dice1, dice2, dice3, dice4, dice5, dice6, dice7, dice8, dice9, dice10 }; for _,v in pairs(savedDiceRoll) do i = i + 1; local diceToSet = myTable[i]; setDiceIcons(diceToSet, v); end end function setDiceIcons(dice, v) local result = DB.getValue(v, 'result', 0) if result == 10 then dice.setStateIcons(0, "wp_spend_critical") dice.setStateIcons(1, "wp_spend_critical_check") elseif result >= 6 then dice.setStateIcons(0, "wp_spend_success") dice.setStateIcons(1, "wp_spend_success_check") else dice.setStateIcons(0, "wp_spend") dice.setStateIcons(1, "wp_spend_check") end dice.setVisible(true) end
MBMRuleset and much more content built for FGU.
Come join me on Twitter at: https://twitter.com/MadBeardMan to see what I'm up to!
-
October 6th, 2019, 20:03 #8
Just to let you know, you could just do it with
Code:for _,v in pairs(savedDiceRoll) do i = i + 1; setDiceIcons(window["dice" .. i], v) end
"Alright, you primitive screwheads, listen up: THIS... is my BOOMSTICK!" -- Ash Williams, Army of Darkness
Post your SavageWorlds ruleset feature requests and issue reports here!
-
October 6th, 2019, 20:13 #9
Hi Ikael,
Thanks for that suggestion, I tried something similar before and got the error:
Script Error: [string "campaign/scripts/charsheet_willpower_spend...."]:18: attempt to index global 'window' (a nil value)
Which I don't understand as we are inside a window....
Cheers,
MBMRuleset and much more content built for FGU.
Come join me on Twitter at: https://twitter.com/MadBeardMan to see what I'm up to!
-
October 6th, 2019, 20:28 #10"Alright, you primitive screwheads, listen up: THIS... is my BOOMSTICK!" -- Ash Williams, Army of Darkness
Post your SavageWorlds ruleset feature requests and issue reports here!
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks