Properybag class error, "attempt to compare number with string" (SOLVED!)

When I use this code:

  
 local prop = require("property")  
 propertyBag = prop:init()  
  
 propertyBag:setProperty("myValue", tonumber(1))  
 propertyBag:SaveToFile()  
 propertyBag:GetFromFile()  
  
  
 if propertyBag:getProperty("myValue") \> 0 then  
 print("This is working!")  
 end  
  
  

I get an error.
Any good solution? [import]uid: 24111 topic_id: 12757 reply_id: 312757[/import]

I solved it by using this code:

 local prop = require("property")  
 propertyBag = prop:init()  
   
 propertyBag:setProperty("myValue", 1)  
 propertyBag:SaveToFile()  
 propertyBag:GetFromFile()  
  
  
 if propertyBag:getProperty("myValue") \> string.format(0) then  
 print("This is working!")  
 end  
  

[import]uid: 24111 topic_id: 12757 reply_id: 46791[/import]

@oskwish,
you can set it to whatever you want, but you need to convert it while reading to a number if you want to compare,

so

[lua]local result = tonumber(propertyBag:getProperty(“myValue”))

if result > 0 then
print (“Hey, this is working”)
end[/lua]

but if you are happy converting the number to a string to compare, fine but be warned that strings compare differently than numbers.

cheers,

?:slight_smile: [import]uid: 3826 topic_id: 12757 reply_id: 46818[/import]

Okay, thanks for the advice :smiley: [import]uid: 24111 topic_id: 12757 reply_id: 46828[/import]