Detecting the existence of an Object

Hi,
Maybe I am approaching this from the C* side of things.

I am trying to check if an object exists or not and then remove it to replace it with a new object.
CASE A:

if not theItem == nill then
theItem:removeSelf
end

CASE B:
if theItem == nill then
theItem:removeSelf
end

In either case the code between the if is not executed, so I take it that you cannot check for nil, so I tried

print(theItem.numChildren)

this prints nil so I take it that it works only for groups

then, I tried to tag them using myName, but I cannot compare a nil value either

What I am really trying to do in objective-C is

[theItem setImage:[UIImage imageNamed:@“somepic.png”]];

so as not to find an equivalent, I am approaching it as

theItem:removeSelf()
theItem = display.addNewImage(“somepic.png”)

coz, if I do not remove theItem, I get another element, so are the variable not a pointer or a reference to the object? How can I ensure that the variable points to only 1 object and after I remove it, I can check with nil that it has been removed?

cheers,

Jayant C Varma [import]uid: 3826 topic_id: 3440 reply_id: 303440[/import]

Don’t use NOT. And it’s nil, not nill. Check like this:

[lua]if theItem ~= nil then[/lua] [import]uid: 5712 topic_id: 3440 reply_id: 10344[/import]

Hi Mike,
Danke schoen. The “nill” was actually a remainder from typing null, but the actual problem was resolved by the ~= operator. I cannot recollect where but I forgot about this one, I had tried <>, then != but when both of them failed, I tried the NOT condition.

Thank you for that

cheers,

Jayant C Varma [import]uid: 3826 topic_id: 3440 reply_id: 10350[/import]