Dungeons & Dragons 2024 Core Rulebooks Pre-Order
Page 1 of 2 12 Last

Thread: Function Issue

  1. #1

    Function Issue

    I'm trying to move calculations out of the objects and into functions, but I'm having a bit of trouble.


    Here, I'm trying to pass three values into the function, the character id, a value being manipulated and the name of the object whose value I need to set.

    Here's what I have in the function

    Code:
    function calculateAbilityMod(nodeChar, strMod, numCurrent)
    
    	local nResult =0;
    	
    	if numCurrent < 10 then
    		nResult = math.ceil((nScore - 10) / 2);
    	elseif numCurrent > 10 then
    		nResult = math.floor((nScore - 10) / 2);
    	else
    		nResult = 0;
    	end
    
    	nodeChar.getChild(strMod).setValue(nResult);
    	
    	return true;
    	
    end
    Here's what I have in the triggers:

    Code:
    function onValueChanged()
    	--values passed> nodeChar, strMod, numCurrent
    	local nodeChar = window.getDatabaseNode();
    	local strMod = "numStrengthMod";
    	local numCurrent = nodeChar.getChild("numStrengthCurrent").getValue();
    	
    	charManager.calculateAbilityMod(nodeChar, strMod, numCurrent);
    end
    I've confirmed the variables are being passed into the function properly, but it's not setting the value in the target.
    I don't think I'm handling the strMod value properly... I need this value so the function knows which stat modifier to update...

  2. #2
    Trenloe's Avatar
    Join Date
    May 2011
    Location
    Colorado, USA
    Posts
    33,701
    Please provide the XML of the control anchored to the numStrengthMod DB field.
    Private Messages: My inbox is forever filling up with PMs. Please don't send me PMs unless they are actually private/personal messages. General FG questions should be asked in the forums - don't be afraid, the FG community don't bite and you're giving everyone the chance to respond and learn!

  3. #3
    Quote Originally Posted by Trenloe View Post
    Please provide the XML of the control anchored to the numStrengthMod DB field.
    There is no code added to numStrengthMod. That's the target I want to set the value of. Or are you talking about the XML setting up that number field?

  4. #4
    damned's Avatar
    Join Date
    Mar 2011
    Location
    Australia
    Posts
    26,832
    Blog Entries
    1
    above this line

    Code:
    nodeChar.getChild(strMod).setValue(nResult);
    add

    Code:
    Debug.chat(nodeChar, strMod, nResult);
    I suspect that you should be using nodeChar where you have used strMod

  5. #5
    Quote Originally Posted by damned View Post
    above this line

    Code:
    nodeChar.getChild(strMod).setValue(nResult);
    add

    Code:
    Debug.chat(nodeChar, strMod, nResult);
    I suspect that you should be using nodeChar where you have used strMod

    Here's what I got with the debug. Everything looks right.....

    s'nodeChar: ' | databasenode = { charsheet.id-00001 }
    s'strMod: ' | s'numStrengthMod'
    s'numCurtrent: ' | #17

  6. #6
    Trenloe's Avatar
    Join Date
    May 2011
    Location
    Colorado, USA
    Posts
    33,701
    Quote Originally Posted by bloodylemming View Post
    Or are you talking about the XML setting up that number field?
    Yes, the XML for the configuration of the number field.
    Private Messages: My inbox is forever filling up with PMs. Please don't send me PMs unless they are actually private/personal messages. General FG questions should be asked in the forums - don't be afraid, the FG community don't bite and you're giving everyone the chance to respond and learn!

  7. #7
    Quote Originally Posted by Trenloe View Post
    Yes, the XML for the configuration of the number field.
    It's automatically generated, as I'm using Ruleset Wizard to do the layout, but here's the entry from the XML.

    Code:
    </number>
          <number name="numStrengthMod">
            <bounds>131,43,35,35</bounds>
            <readonly />
            <font>reference-b</font>
    </number>

  8. #8
    damned's Avatar
    Join Date
    Mar 2011
    Location
    Australia
    Posts
    26,832
    Blog Entries
    1
    Quote Originally Posted by bloodylemming View Post
    Here's what I got with the debug. Everything looks right.....

    s'nodeChar: ' | databasenode = { charsheet.id-00001 }
    s'strMod: ' | s'numStrengthMod'
    s'numCurtrent: ' | #17

    Show what the data in the database looks like please.
    This is in a charsheet - so find the db.xml and find <charsheet><id-00001> and copy everything from the <id-000001> to the </id-00001> tag and share here.

  9. #9
    Quote Originally Posted by damned View Post
    Show what the data in the database looks like please.
    This is in a charsheet - so find the db.xml and find <charsheet><id-00001> and copy everything from the <id-000001> to the </id-00001> tag and share here.
    Code:
    <id-00001>
    			<abilitylist />
    			<Checkbox1 type="number">0</Checkbox1>
    			<chkCharisma type="number">0</chkCharisma>
    			<chkConstitution type="number">0</chkConstitution>
    			<chkDexterity type="number">0</chkDexterity>
    			<chkIntelligence type="number">0</chkIntelligence>
    			<chkStrength type="number">0</chkStrength>
    			<chkWisdom type="number">0</chkWisdom>
    			<numCharismaCurrent type="number">10</numCharismaCurrent>
    			<numCharismaMod type="number">0</numCharismaMod>
    			<numCharismaScore type="number">10</numCharismaScore>
    			<numConstitutionCurrent type="number">16</numConstitutionCurrent>
    			<numConstitutionMod type="number">3</numConstitutionMod>
    			<numConstitutionScore type="number">16</numConstitutionScore>
    			<numDexterityCurrent type="number">14</numDexterityCurrent>
    			<numDexterityMod type="number">2</numDexterityMod>
    			<numDexterityScore type="number">14</numDexterityScore>
    			<numExperience type="number">0</numExperience>
    			<numFamiliarBonus type="number">0</numFamiliarBonus>
    			<numHeight type="number">0</numHeight>
    			<numIntelligenceCurrent type="number">8</numIntelligenceCurrent>
    			<numIntelligenceMod type="number">-1</numIntelligenceMod>
    			<numIntelligenceScore type="number">8</numIntelligenceScore>
    			<numLevel type="number">1</numLevel>
    			<numNextLevel type="number">0</numNextLevel>
    			<numNonProficiencyBonus type="number">0</numNonProficiencyBonus>
    			<numProficiencyBonus type="number">1</numProficiencyBonus>
    			<numSpeed type="number">0</numSpeed>
    			<numSpellcastingBonus type="number">0</numSpellcastingBonus>
    			<numStrengthCurrent type="number">17</numStrengthCurrent>
    			<numStrengthMod type="number">4</numStrengthMod>
    			<numStrengthScore type="number">18</numStrengthScore>
    			<numWeight type="number">0</numWeight>
    			<numWisdomCurrent type="number">7</numWisdomCurrent>
    			<numWisdomMod type="number">-1</numWisdomMod>
    			<numWisdomScore type="number">7</numWisdomScore>
    			<token type="token"></token>
    			<txtWounds type="formattedtext">
    				<p />
    			</txtWounds>
    		</id-00001>

  10. #10

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