DICE PACKS BUNDLE
  1. #1
    damned's Avatar
    Join Date
    Mar 2011
    Location
    Australia
    Posts
    26,684
    Blog Entries
    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]

    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>
    Any suggestions?

  2. #2
    Ikael's Avatar
    Join Date
    Jan 2008
    Location
    Finland/Joensuu
    Posts
    2,384
    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!

  3. #3
    damned's Avatar
    Join Date
    Mar 2011
    Location
    Australia
    Posts
    26,684
    Blog Entries
    1
    Quote Originally Posted by Ikael View Post
    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)
    Hi Aki

    I am not sure I follow your code?

  4. #4
    Ikael's Avatar
    Join Date
    Jan 2008
    Location
    Finland/Joensuu
    Posts
    2,384
    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!

  5. #5
    damned's Avatar
    Join Date
    Mar 2011
    Location
    Australia
    Posts
    26,684
    Blog Entries
    1
    Quote Originally Posted by Ikael View Post
    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.
    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?

  6. #6
    Ikael's Avatar
    Join Date
    Jan 2008
    Location
    Finland/Joensuu
    Posts
    2,384
    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!

  7. #7
    damned's Avatar
    Join Date
    Mar 2011
    Location
    Australia
    Posts
    26,684
    Blog Entries
    1
    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

  8. #8
    damned's Avatar
    Join Date
    Mar 2011
    Location
    Australia
    Posts
    26,684
    Blog Entries
    1
    some smart alec just came along and did:

    Code:
    							local sCover = DB.getValue(nodeWin,"five","0");
    							local nCover = tonumber(sCover) or 0;
    or

    Code:
    							local sCover = nodeWin.getChild("five").getValue();
    							local nCover = tonumber(sCover) or 0;
    which is I think what you were steering me towards Aki.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Starfinder Playlist

Log in

Log in