PDA

View Full Version : Strings in the wrong place



ThinkTank
January 19th, 2014, 19:15
Bit of a strange one this time.

I have a common diceroll script attached to a basicnumber.



<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:



-- GET ABILITY VALUE
local nStatScore = getAbilityScore(rActor, sStat);
print(rActor)
print(sStat)
print(sAbility)
if nStatScore < 0 then
return 0;
end


Returned

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:



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


Returned

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?

Moon Wizard
January 20th, 2014, 07:07
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

Trenloe
January 20th, 2014, 15:39
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.

ThinkTank
January 20th, 2014, 15:40
Here we go, first time I'v actualy been able to get Debug to work properly.

https://pastebin.com/8kzAwWB0




-- 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'

Trenloe
January 20th, 2014, 15:53
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?

ThinkTank
January 20th, 2014, 16:01
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.

ThinkTank
January 20th, 2014, 16:43
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)