Page 1 of 1

doing arithmetic on tables

Posted: Mon May 05, 2014 9:38 pm
by lifanov
v can be a table here. This silences the error (tonumber of nil is nil and tonumber of not a number is nil):

Code: Select all

diff --git a/game/modules/tome/class/Actor.lua b/game/modules/tome/class/Actor.lua
index a47492e..0d6d26a 100644
--- a/game/modules/tome/class/Actor.lua
+++ b/game/modules/tome/class/Actor.lua
@@ -1715,7 +1715,7 @@ function _M:tooltip(x, y, seen_by)
 
        local retal = 0
        for k, v in pairs(self.on_melee_hit) do
-               if v then retal = retal + v end
+               if tonumber(v) then retal = retal + v end
        end
 
        if retal > 0 then ts:add("Melee Retaliation: ", {"color", "RED"}, tostring(math.floor(retal)), {"color", "WHITE"}, true ) end

Re: doing arithmetic on tables

Posted: Mon May 05, 2014 10:00 pm
by darkgod
thanks :)

Re: doing arithmetic on tables

Posted: Tue May 06, 2014 9:35 pm
by lifanov
I can confirm that this is fixed for me.