-
July 16th, 2018, 10:10 #1
Cycler Behaviour and Default Values
Hi team,
Im trying to create a string-cycler with numeric values - eg Descriptions shown but Numbers stored.
How do I eliminate the blank value that always appears in all my cyclers?
This is an issue as Im running an onValueChanged script on the cycler and it does some math so when it gets around to the blank value it generates a script error.
Samples of code:
Code:<template name="cycler_cover"> <button_stringcycler> <parameters> <labels>None|Light|Heavy|Entrenched</labels> <defaultlabelres mergerule="replace">None</defaultlabelres> <values>0|2|4|6</values> </parameters> </button_stringcycler> </template>
Code:<cycler_cover name="five" source="five"> <anchored to="combatframe" position="insidetopright" offset="20,112" width="64" /> <default>0</default> <script> function onValueChanged() local rActor = ActorManager.getActor("pc", window.getDatabaseNode()); local nodeWin = window.getDatabaseNode(); local nReflexes = nodeWin.getChild("abilities.reflexes.tempmodifier").getValue(); local nEquipment = nodeWin.getChild("four").getValue(); local nCover = nodeWin.getChild("five").getValue(); local nDefence = nReflexes+nEquipment+nCover+10; nodeWin.getChild("defence").setValue(nDefence); end </script> </cycler_cover>
-
July 16th, 2018, 10:16 #2
Not sure if you can remove the blank value itself but to play safe you could do something like
nCover = nCover == "" and 0 or tonumber(nCover)"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!
-
July 16th, 2018, 12:08 #3
-
July 16th, 2018, 13:25 #4
https://lua-users.org/wiki/TernaryOperator
More importantly, you could make blank value to represent zero. You will anyways need to convert string values into numbers to use them arithmetically. So when you read the value you could convert blank into zero, unless the controller allows you to skip blank, which I am not sure you could do."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!
-
July 16th, 2018, 13:58 #5
I have tried a couple of statements but it looks like the problem is possibly different.
If i do a /save while the cycler is on a blank value then the field is removed from the db altogether
<defence type="number">20</defence>
<four type="number">0</four>
<health type="number">15</health>
If the cycler is on any of the values including None / 0 then it saves the value.
<defence type="number">16</defence>
<five type="string">2</five>
<four type="number">0</four>
<health type="number">15</health>
If there is no way to stop the blank values being shown - and thus the field being removed - is there a way to check if the field is present?
-
July 16th, 2018, 14:03 #6
FG does remove any and all blank string typed databasenodes to save space. You could read the value safely with DB.getValue(nodeWin, "five", "")
Alternatively you can check if node exists with
if nodeWin.getChild("five") then
...
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!
-
July 16th, 2018, 15:30 #7
Aki thank you for your assistance.
This is what I ended up with - yes its ugly - but it only took me 6 hours.
Code:local sCover = nodeWin.getChild("five").getValue(); if not sCover then local sCover = 0; end local nCover = tonumber(sCover); if nCover == nil then nCover = 0; end
-
July 16th, 2018, 16:05 #8
some smart alec just came along and did:
Code:local sCover = DB.getValue(nodeWin,"five","0"); local nCover = tonumber(sCover) or 0;
Code:local sCover = nodeWin.getChild("five").getValue(); local nCover = tonumber(sCover) or 0;
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks