minor modification in var.lua

Posted by Unia_nt on Tue 29 Dec 2015 03:48 AM — 3 posts, 13,707 views.

#0
var.xx return a string, when do comparing with a number in lua will lead error, so I changed the return as :

return tonumber(GetVariable (name) ) or GetVariable (name)

in var.lua and fixed the issue.
USA Global Moderator #1
This would unfortunately break compatibility with anything already using the file. If you know the stored value is a number (which you must in order to do your comparison that way), it would be safer to tonumber the value on the outside of the access instead of inside of it.

So like "yournumber == tonumber(var.foo)" instead of "yournumber == var.foo"
Amended on Tue 29 Dec 2015 11:38 AM by Fiendish
Australia Forum Administrator #2
I agree with Fiendish. For example:


print (tonumber (" 42 "))


That prints 42, and discards the spaces. Your change would corrupt existing variables, quite possibly.