STAR TREK 2d20
  1. #1

    First time extention writing

    I'm in the process of writing my first extension. Which will display the XP points needed for the next level (see below screenshot), I have everything working the writing of the calc back to the database.

    Here is the code for the function
    Code:
    function onButtonPress()
    	local nodeWin      = window.getDatabaseNode();
    
    	local curXp        = DB.getValue(nodeWin, "exp");
    	local curNextLevel = DB.getValue(nodeWin, "expneeded");
    	local curXpNeeded  = curNextLevel - curXp;
    
    	DB.setValue(nodeWin, "expnextlevel", "number", "curXpNeeded");
    
    	Debug.console("(XP)        : ", DB.getValue(nodeWin, "exp"));
    	Debug.console("(Next Level): ", DB.getValue(nodeWin, "expneeded"));
    	Debug.console("(XP Needed) : ", curXpNeeded);
    										
    end
    And here is the Console window output
    Code:
    Script Warning: setValue: Recursive node event or call terminated (charsheet.id-00001.expnextlevel)
    
    Runtime Notice: s'(XP) : ' | #0
    Runtime Notice: s'(Next Level): ' | #1000
    Runtime Notice: s'(XP Needed) : ' | #1000
    Here are the DB entries
    Code:
    <exp type="number">1</exp>
    <expneeded type="number">1000</expneeded>
    <expnextlevel type="number">0</expnextlevel>
    To me everything looks correct.

    Attached Images Attached Images

  2. #2
    damned's Avatar
    Join Date
    Mar 2011
    Location
    Australia
    Posts
    26,649
    Blog Entries
    1
    Hey KlatuB

    What is your question?
    Regarding the error - something else is probably running an onUpdate on expnextlevel causing some sort of loop.

  3. #3
    Damned,

    I did forget to actually ask a question, I wanted to know if the function looked correct.

    To rule out an extension conflict (had a couple of others open), I closed FG and I turned them all off but the this one.

    The 1st time I clicked the button (lollipop), I got
    Code:
    Script Error: [string "calcXpNeeded"]:1: bad argument #4 to 'setValue' (number expected, got string)
    The 2dn time I clicked the button (lollipop), I got

    Code:
    Script Warning: setValue: Recursive node event or call terminated (charsheet.id-00001.expnextlevel)
    Runtime Notice: s'(XP) : ' | #1
    Runtime Notice: s'(Next Level): ' | #1000
    Runtime Notice: s'(XP Needed) : ' | #999
    Now I can't reproduce the original error. My question is what am I doing wrong, I'm attaching the extension for anyone more knowledgeable to look at to see what the issue is.
    Attached Files Attached Files

  4. #4
    damned's Avatar
    Join Date
    Mar 2011
    Location
    Australia
    Posts
    26,649
    Blog Entries
    1
    This error: (number expected, got string) means pretty much exactly what it says - you are trying to use a string somewhere that you should be using a number

    Code:
    			<script>
    				function onButtonPress()
    					local nodeWin      = window.getDatabaseNode();
    					Debug.console("nodeWin: ", nodeWin);
    
    					local curXp        = DB.getValue(nodeWin, "exp");
    					local curNextLevel = DB.getValue(nodeWin, "expneeded");
    					local curXpNeeded  = tonumber(curNextLevel) - tonumber(curXp);
    
    					DB.setValue(nodeWin, "expnextlevel", "number", curXpNeeded);
    
    					Debug.console("(XP)        : ", DB.getValue(nodeWin, "exp"));
    					Debug.console("(Next Level): ", DB.getValue(nodeWin, "expneeded"));
    					Debug.console("(XP Needed) : ", curXpNeeded);
    										
    				end
    			</script>
    Some suggestions...
    Make it calculate any time you change the level, XP or Next Level values.
    Make it calculate when you open that window as well.

    You might also look at automatically setting the Next level values every time the Level changes.

    And lastly the lollipop is a magnifying glass

    Please do post your extension when done.

  5. #5
    Actually the fact that FG doesn't do this automatically for some reason always aggravated my friends (and me to a lesser extent). An extension that does this would be greatly appreciated!!

  6. #6
    I will be posting the finished extension shortly in a new thread

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
  •  
5E Product Walkthrough Playlist

Log in

Log in