What is nan in terms of Lua? Does it equate to nil? If so why doesn’t this code work:
[lua]g.alive = function( event )
print(“Am I Alive”, g.status)
if not g.status then
print(“error”)
g.status = true
end
end
Runtime:addEventListener(“enterFrame”, g.alive)[/lua]
When there is an erroneous call to g.alive in which g.alive is nil it should be set to true, right? But all I get is Am I Alive nan [import]uid: 54716 topic_id: 17034 reply_id: 317034[/import]
nan or NaN is usually ‘Not a Number’. You can get these from illegal math operations like dividing by 0. It’s not clear to me how you got nan from the code you pasted. [import]uid: 7563 topic_id: 17034 reply_id: 63910[/import]
Oh duh, not a number, epic face palm. It’s not clear to me either lol. Thanks for the response. I know now what to look for. [import]uid: 54716 topic_id: 17034 reply_id: 63913[/import]
Is there a way to test for non numbers? I still have no clue where I am passing it in. I should only be having nil or a number. [import]uid: 54716 topic_id: 17034 reply_id: 63931[/import]
Not really. Testing for NaN is actually really hard and would require platform/architecture specific tricks if it could be done at all. The best thing is to avoid creating them in the first place. [import]uid: 7563 topic_id: 17034 reply_id: 64044[/import]
You could maybe try to use the tonumber() function.
If it can’t convert the parameter to a number it’ll return nil, and if it’s already a number it will just return the number. [import]uid: 70847 topic_id: 17034 reply_id: 64050[/import]
Just a guess here, but if g.status is a Boolean type and not a number it could be throwing off the print command where you use a comma to separate the string and g.status. You could try
print(type(g.status))
above line 2 to find out what type g.status is.
Also you could try this for line 2:
print(“Am I Alive” … g.status)
or
(“Am I Alive” … tostring(g.status))
And you could do a check for the correct type (not quite a check for nan but might be just as good). Something like (untested):
If tostring(type(g.status)) ~= “number” then
–do something to handle the wrong type
end
[import]uid: 9422 topic_id: 17034 reply_id: 64055[/import]
Thanks ingemar and XenonBl I will try those options. Thing is those variables are only set in two places and are numbers or nil so I am still confused as to what it could be. And what else is in Lua that’s not a table, boolean, numbers, or string??? [import]uid: 54716 topic_id: 17034 reply_id: 64067[/import]
I know at least half of those would print out something or throw an error for trying use in a string. I will have to look into the rest thanks. [import]uid: 54716 topic_id: 17034 reply_id: 64074[/import]
I expect NaN to be a number type in Lua. You won’t be able to distinguish it from any other number.
[import]uid: 7563 topic_id: 17034 reply_id: 64076[/import]
0/0 is indeterminate. And the first rule of indeterminate club, is you don’t talk about indeterminate club.
According to IEEE 754-2008, the sign of a NaN has no meaning. Then again, I have heard that if a particle of NaN meets a particle of -NaN, there is an explosion.
I’ll go back to enjoying garlic naan and try to forget everything I didn’t learn in this thread. [import]uid: 9422 topic_id: 17034 reply_id: 66549[/import]