Thread: Strings in the wrong place
-
January 19th, 2014, 19:15 #1
Strings in the wrong place
Bit of a strange one this time.
I have a common diceroll script attached to a basicnumber.
Code:<basicnumber name="phy_score" source="stats.phy.score"> <anchored> <to>statframe</to> <position>insidetopleft</position> <offset>75,30</offset> <size> <width>32</width> <height>20</height> </size> </anchored> <script> local rollwidget; function onInit() rollwidget = addBitmapWidget("indicator_dice"); if rollwidget then rollwidget.setPosition("insidetopright", -5, 2); rollwidget.setSize(15,15); rollwidget.setColor("AAFFFFFF"); end end function action(draginfo) local rActor = ActorManager.getActor("pc", window.getDatabaseNode()); ActionAbility.performRoll(draginfo, rActor, getValue()); return true; end function onDragStart(button, x, y, draginfo) return action(draginfo); end function onDoubleClick(x,y) return action(); end </script> </basicnumber>
When used, it returns. Script Error: [string "scripts/manager_actor.lua"]:443: attempt to compare string with number
Digging into it:
Code:-- GET ABILITY VALUE local nStatScore = getAbilityScore(rActor, sStat); print(rActor) print(sStat) print(sAbility) if nStatScore < 0 then return 0; end
Script Notice:
Script Notice: 4
Script Notice: 4
Script Notice:
Script Notice: level
Script Notice: halflevel
Script Error: [string "scripts/manager_actor.lua"]:443: attempt to compare string with number
And on the same sheet:
Code:function getActor(sActorType, varActor) print(sActorType) print(varActor) -- GET ACTOR NODE local nodeActor = nil; if type(varActor) == "string" then if varActor ~= "" then nodeActor = DB.findNode(varActor); end elseif type(varActor) == "databasenode" then nodeActor = varActor; end if not nodeActor then return nil; end
Script Notice: pc
Script Notice:
Script Error: [string "scripts/manager_actor.lua"]:443: attempt to compare string with number
I can see a string is being read instead of a number somewhere down the line, but Im not sure how. Any ideas?Last edited by ThinkTank; January 19th, 2014 at 19:22.
-
January 20th, 2014, 07:07 #2
Supreme Deity
- Join Date
- Mar 2007
- Posts
- 20,613
Without knowing the code from manager_actor.lua, it's hard to tell what the issue is.
There are 3 newer functions to help in debugging:
Debug.chat(...) - Detailed output to chat window (including tables)
Debug.console(...) - Detailed output to console window (including tables)
printstack() - Outputs current Lua call stack
I suggest that you look at the manager_actor.lua script in your ruleset. And place a Debug.console(<variable list for current function>) call just before that line, and follow that with a printstack() call. This will tell you the current set of variables passed to that function, as well as the call stack that led to that function being called.
Regards,
JPG
-
January 20th, 2014, 15:39 #3
Sorry if you knew this already, but "[string "scripts/manager_actor.lua"]:443: attempt to compare string with number" means that the error is occurring at line 443 in scripts/manager_actor.lua. Open that file in Notepad++ and you will see line numbers down the left side - this allow you to identify exactly which line is reporting the error.
Then, as Moon Wizard mentioned above, put a Debug.console command immediately before this line which prints out the variables that will be compared in the code of line 443. This should help you to identify why there might be an issue with one of the variables being a string or a number when it should be the other to allow a proper comparison. You will then more than likely have to work your way backwards in the code to see where the root cause is.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!
-
January 20th, 2014, 15:40 #4
Here we go, first time I'v actualy been able to get Debug to work properly.
https://pastebin.com/8kzAwWB0
Code:-- GET ABILITY VALUE local nStatScore = getAbilityScore(rActor, sStat); Debug.console(nStatScore) printstack() if nStatScore < 0 then return 0; end ------------------------------- Runtime Notice: #-1 Script Notice: stack traceback: [string "scripts/manager_actor.lua"]:439: in function 'getAbilityBonus' [string "scripts/manager_action_ability.lua"]:17: in function 'performRoll' [string "phy_score"]:1: in function <[string "phy_score"]:1> (tail call): ? Runtime Notice: s'Heroic' Script Notice: stack traceback: [string "scripts/manager_actor.lua"]:439: in function 'getAbilityBonus' [string "scripts/manager_action_ability.lua"]:18: in function 'performRoll' [string "phy_score"]:1: in function <[string "phy_score"]:1> (tail call): ? Script Error: [string "scripts/manager_actor.lua"]:440: attempt to compare string with number -------------------------- rActor returns Runtime Notice: { s'sCreatureNode' = s'charsheet.id-00003', s'nodeCreature' = databasenode = { charsheet.id-00003 }, s'sName' = s'test', s'sCTNode' = s'', s'sType' = s'pc' } sStat returns Runtime Notice: #4 Script Notice: stack traceback: [string "scripts/manager_actor.lua"]:438: in function 'getAbilityBonus' [string "scripts/manager_action_ability.lua"]:17: in function 'performRoll' [string "phy_score"]:1: in function <[string "phy_score"]:1> (tail call): ? Runtime Notice: s'level'
Last edited by ThinkTank; January 20th, 2014 at 15:55.
-
January 20th, 2014, 15:53 #5
nStatScore is being set as "Heroic" by the getAbilityScore function, and is then being compared with 0. This is where the error occurs - as 0 is a number and "Heroic" is a string.
You'll need to see why the getAbilityScore function is returning "Heroic" instead of a number. Does your ruleset use numbers for it's abilities?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!
-
January 20th, 2014, 16:01 #6
Ahh, thats clearer.
Heroic is one of three set level lables which control a number of variables in the charsheet. In this case it should be controling the max stats fields next to the actual stat fields this script is looking at.
Although the actual string for Heroic shouldnt be anywhere near those numberfields, I'll have to do some digging.
-
January 20th, 2014, 16:43 #7
Looks like:
elseif rActor.sType == "pc" then
if sShort == "lev" then
nStatScore = DB.getValue(rActor.nodeCreature, "level", 0);
Was causing trouble, with it commented out, the Partysheet rolls are working, although the orginal stat boxes I was trying to get to do rolls are still looking for a string to compair.
Script Error: [string "scripts/manager_string.lua"]:81: attempt to index local 's' (a number value)
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks