Thread: First time extention writing
-
September 21st, 2018, 02:19 #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
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
Code:<exp type="number">1</exp> <expneeded type="number">1000</expneeded> <expnextlevel type="number">0</expnextlevel>
-
September 21st, 2018, 03:02 #2
Hey KlatuB
What is your question?
Regarding the error - something else is probably running an onUpdate on expnextlevel causing some sort of loop.
-
September 21st, 2018, 21:40 #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)
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
-
September 22nd, 2018, 01:44 #4
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>
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.
-
September 23rd, 2018, 03:01 #5
- Join Date
- Feb 2017
- Posts
- 607
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!!
-
September 23rd, 2018, 17:20 #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