PDA

View Full Version : Unity broke my stuff :P



Stv
March 6th, 2020, 18:21
I just tried my 5e reliable talent extension in FGU and it throws an error :

[3/6/2020 6:17:17 PM] [<color="red">ERROR</color>] Script execution error: [string "scripts/reliabletalent.lua"]:50: attempt to compare nil with number.

In FGC, this code works fine.


local sPCNodeName = ActorManager.getCreatureNodeName(rSource);
local nodeFeatureList = DB.getChild(sPCNodeName, "featurelist");
local critfail=false
if nodeFeatureList and
string.match(rMessage.text,"PROF")and not string.match(rMessage.text,"PROF x1/2") then
for k, nodeFeature in pairs (nodeFeatureList.getChildren()) do
if DB.getValue(nodeFeature, "name", ""):lower() == "reliable talent" then
---Check the value of the 1st die in the message(D20 roll, and if it's <10 change it to 10, add a notification to the output message then exit the loop)
for _,v in pairs(rMessage.dice) do
--new stuff in here so possibly breaking things
--
--
--check if the critical fail/success settings option is on and check for crit
if OptionsManager.isOption("AFAIL","yes") then
--if result is a one, then flag as a critical fail
if v.result==1
then rMessage.text="[CRITICAL FAIL]\r"..rMessage.text
critfail=true
--if result is a 20 then flag as a critical success
else if v.result==20 then
v.result=20
rMessage.text="[CRITICAL SUCCESS]\r"..rMessage.text
end
end
end
if v.result<10 and critfail==false then
local temp=v.result
v.result=10
rMessage.text="Reliable Talent\r[Dropped "..temp.."]\r"..rMessage.text
end


end
break;
end
end
end

The offending part of the code is this line :


if v.result<10 and critfail==false then

If I Debug the value of v.result at that point it 1st reports the correct value, but then it's like it runs the debug line again but this time returns a value of nil.

Anyone got any ideas or can shove me in the right direction ?

Cheers, Stv.

Moon Wizard
March 6th, 2020, 18:25
Try putting printstack() function just before offending line to get the call stack for how your function is being called.

Regards,
JPG

Stv
March 6th, 2020, 18:33
OK, that gve me this :


stack traceback:
[string "scripts/reliabletalent.lua"]:50: in function 'fResult'
[string "scripts/manager_actions.lua"]:613: in function 'resolveAction'
[string "scripts/manager_actions.lua"]:587: in function 'handleResolution'
[string "scripts/manager_actions.lua"]:563: in function <[string "scripts/manager_actions.lua"]:556>
(tail call): ?
[3/6/2020 6:31:28 PM]
stack traceback:
[string "scripts/reliabletalent.lua"]:50: in function 'fResult'
[string "scripts/manager_actions.lua"]:613: in function 'resolveAction'
[string "scripts/manager_actions.lua"]:587: in function 'handleResolution'
[string "scripts/manager_actions.lua"]:563: in function <[string "scripts/manager_actions.lua"]:556>
(tail call): ?
[3/6/2020 6:31:28 PM] [<color="red">ERROR</color>] Script execution error: [string "scripts/reliabletalent.lua"]:51: attempt to compare nil with number


And I have no idea what to make of it :)

Cheers, Steve.

Moon Wizard
March 6th, 2020, 18:56
No idea; but it looks like it's coming from same place each time. It looks like something is calling the ActionsManager twice. It's usually an error triggers the script twice (as a fallback mechanism in Lua), but that doesn't look like the case here.

What do the parameters to your action handler function look like (rSource, rTarget, rRoll)?

JPG

Stv
March 6th, 2020, 19:17
I've had to go out, so not at my pc right now, as soon as I'm back I'll have a look and post it.... although I'm currenty thinking I have my break from the loop at the wrong point which is throwing the error.

Cheers, Steve.

damned
March 6th, 2020, 21:39
try ipairs instead of pairs

Moon Wizard
March 6th, 2020, 21:59
Good call, damned. There is actually an extra "expr" key/value in the dice list in FGU that is a string. You only want to iterate over specific dice which are all integer-based keys (i.e. ipairs).

Regards,
JPG

Stv
March 7th, 2020, 11:47
FFS Damned, once again you've saved my life :D
Changing to ipairs fixes it.

Thanks alot, Steve.