using 'event.other.myName' with numbers... ?

Greetings,

Ok so I know how to reference objects by using the:

event.other.myName == "name"

But I’m naming a ‘list’ of objects by numbers… 

for i = 1, 10 do objects[i].myName = i end

now I WANT to something like this:

if event.other.myName \> 0 then

however I’m getting errors because it’s trying to compare number with string (duh)… 

What’s the simplest way to achieve this?

Thanks in advance! 

I got it, I just used an 'objects[i].myName = “name” 'as well as 'objects[i].myNumb = i ’ to keep track of individual things vs group of objects.

Answered!

You can also use 

if tonumber(event.other.myName) \> 0 then

Thanks @JonPM , a much better method… I tried converting to number when I assigned it to ‘myName’ – didn’t think about it that way. :slight_smile:

What you could also have done is check whether the property was a string or number before making the comparison:

if type(event.other.myName) == "number" and event.other.myName \> 0 then

I got it, I just used an 'objects[i].myName = “name” 'as well as 'objects[i].myNumb = i ’ to keep track of individual things vs group of objects.

Answered!

You can also use 

if tonumber(event.other.myName) \> 0 then

Thanks @JonPM , a much better method… I tried converting to number when I assigned it to ‘myName’ – didn’t think about it that way. :slight_smile:

What you could also have done is check whether the property was a string or number before making the comparison:

if type(event.other.myName) == "number" and event.other.myName \> 0 then