Checking For Nil

I feel really stupid asking this but I havent managed to figure it out

I want to check if a value is empty, ie nil or doesnt exist

for example I load an image image_foo

I want to assign a lifetime tracker to the image, so I setup image_foo.lifetime = “time based calculation”

but before that I need todefine initial values etc… so I need to check for image_foo.lifetime == undifined / image_foo.lifetime == nil

ive not found one that works yet and the debugger gives me " attempt to perform arithmetic on field ‘lifetime’ (a nil value)" [import]uid: 5354 topic_id: 581 reply_id: 300581[/import]

I think you’re going to need to post some of your code to get good feedback. Checking var == nil or even table_var.field == nil is perfectly fine, so from your description above, it’s not clear what the problem is.

Matt
[import]uid: 78 topic_id: 581 reply_id: 1128[/import]

I wrote my way around it, thought it could be a coding issue so I redid the code in a different way (old code now overwritten)

I was trying to implement a local lifetime to different objects so I could do time based rather than frame based animations

So I was assigning image_foo.lifetime == system.getTimer() - image_foo.lifetime;

the error was when I was checking for image_foo.lifetime == nil for the first loop but I cant be sure that it was that or the following rules that caused the error

–anyway I am now setting 1 global timePrevious value to check all animations against where
timePrevious = event.time; – 1 line of main loop

–in each animation function thats called in the main loop
local timeDelta = system.getTimer() - timePrevious;

–and then to do the time based adjustment to account for a drop in framerate
local scaleVelocity = 2.5
local newScale = scaleVelocity+((0.03*scaleVelocity)*timeDelta);
image_foo.yScale = image_foo.yScale; + (newScale);
image_foo.xScale = image_foo.xScale; + (newScale);
im hoping this makes sense, it allows you to adjust for delays in the main loop and if applied to each function call, it will sync animation (I hope) [import]uid: 5354 topic_id: 581 reply_id: 1129[/import]