Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
Compare two values problem!? — Gideros Forum

Compare two values problem!?

GiderosFanGiderosFan Member
edited June 2015 in General questions
I tried to compare two values.
The first value i have saved in my settings the other is just an number.

my code looks like this:
	counted_tested = sets:get("counted")
				counted_tested = counted_tested + 1
				sets:set("counted", counted_tested, true)
				print(sets:get("counted"))	--> gives me the correct number back
 
 
				if sets:get("counted")  <= 30  then --> gives me the error like this (attempt to compare number with nil)
so the error message is: attempt to compare number with nil

why this is nil i have set an number or?

Comments

  • What is sets?
    How get and set function written like?
    It depends on the returned value.

    Likes: GiderosFan

    +1 -1 (+1 / -0 )Share on Facebook
  • piepie Member
    edited June 2015
    Do you have a default/starting num value on "counted" for the first iteration?

    I think that you can also use or
    counted_tested = sets:get("counted") or 1
  • @tkhnoman sets is my settings.lua file that contains the counted value sorry i forgotten to explain this.

    my settings file look like this:
    local settings = {
    	counted = 0,
    }

  • GiderosFanGiderosFan Member
    edited June 2015
    @ pie
    sets:get("counted") or 1
    gives me the same error.
  • piepie Member
    @GiderosFan try
    local settings = {
    	"counted" = 0,
    }

    Likes: GiderosFan

    +1 -1 (+1 / -0 )Share on Facebook
  • piepie Member
    edited June 2015 Accepted Answer
    Two more things you can try:

    1) check the type of your value
    print("value type", type(counted_tested) )
    If the value is saved as a number, but returned as string maybe it's not recognized as a "number in a string" which lua is supposed to do.
    What is strange is that you have nil in the error and not "trying to compare number with string".

    If that's the case, you can use tonumber(counted_tested) to "convert" it back.

    2) instead of using the function as the parameter to your condition, try writing it "exploded"
    local countTested = sets:get("counted")
    print("countTested: ", countTested ) --just to be sure 
    if countTested  <= 30  then..

    Likes: GiderosFan

    +1 -1 (+1 / -0 )Share on Facebook
  • ahhh yes that was what i have searched to convert it with tonumber(....) thank you pie for the fast solution :).

    the code works yet thank you :)
Sign In or Register to comment.