How to read user propeteries?

In Level Director X i can add user properties. For example, for “Update_start_stop_2” I’ve added “type” with value “floor”. The problem is, i have no idea how to read this value in corona.

I am doing it this way:

local f = myLevel:getObject("Update\_start\_stop\_2").view print(f.property['type'])

but i always get same error:

attempt to index field ‘property’ (a nil value)

What i am doing wrong?

The properties are stored at the object level not at the view level (display object)

local f = myLevel:getObject("Update\_start\_stop\_2") print(f.property['type'])

Notice the .view has been removed, so it should now find your property.

If you need to access the display object you would use f.view…

It does make more sense to have the properties at the view level but it is possible to export a polygon or bezier with no display object (view) i.e. data points only, hence why the properties are at the LDX object level.

Thanks a lot! Know i feel stupid, because I didn’t thought about it.

Is there a way to use it in collision? I have global postCollision listener and in proper function i am checking what objects collided. After checking that event.object2 is my car, i need to check if event.object1 is one of the floors. To do so I’ve added user property “type” with value “floor” for every floor i have.

print(event.object1.name)

return

Update_start_stop_2

Same as f.name, made like you said, so i am sure that this is collision with that floor. Sadly, there is again error:

attempt to index field ‘property’ (a nil value)

after using

print(event.object1.property['type'])

even while

print(f.property['type'])

returns exactly what i want, so i am sure i made user properties right. Also, i am sure that my postCollision function is correct, because

myLevel:removeLayerObject("ToDestroy",event.object1.name)

works just great.

That’s why it would be better to have the properties linked to the view so you could use it within collisions, but there is a simple workaround, try this;

local f = myLevel:getObject("Update\_start\_stop\_2") f.view.property = f.property print(f.view.property['type'])

I might even think about duplicating the properties on the view if there is one in a future release.

If you only need a single property per object, I also suggest you take a look at the built-in ‘class’ property which you can set per object, this is accessible on the view.

Yes, your removeLayerObject command looks spot on, removing an object from a specific layer with that object name.

This code works, thanks. Sadly, i would have to use

f.view.property = f.property

For every floor on every level, so i have to find another way of checking type of object.

I didn’t know that i can check class simply just by using .class. It completely solve my problem and it is exactly what i need. Thanks a lot, now i am step closer to close finish making this game. I have already around 1200 lines of code so far (not counting levels generated in LDX), so i guess in two months it will be fully playable.

Excellent, glad you found a solution.

FYI, when using classes, you can add the class names to the project, by clicking the project name in the project window, and in the properties use the standard ‘add property’ button.

This builds up a set of classes for your project and when you specify the class on an object, as you type it will list the classes from the project so you can simply select one.

Might not be useful to you, but thought I would mention it.

The properties are stored at the object level not at the view level (display object)

local f = myLevel:getObject("Update\_start\_stop\_2") print(f.property['type'])

Notice the .view has been removed, so it should now find your property.

If you need to access the display object you would use f.view…

It does make more sense to have the properties at the view level but it is possible to export a polygon or bezier with no display object (view) i.e. data points only, hence why the properties are at the LDX object level.

Thanks a lot! Know i feel stupid, because I didn’t thought about it.

Is there a way to use it in collision? I have global postCollision listener and in proper function i am checking what objects collided. After checking that event.object2 is my car, i need to check if event.object1 is one of the floors. To do so I’ve added user property “type” with value “floor” for every floor i have.

print(event.object1.name)

return

Update_start_stop_2

Same as f.name, made like you said, so i am sure that this is collision with that floor. Sadly, there is again error:

attempt to index field ‘property’ (a nil value)

after using

print(event.object1.property['type'])

even while

print(f.property['type'])

returns exactly what i want, so i am sure i made user properties right. Also, i am sure that my postCollision function is correct, because

myLevel:removeLayerObject("ToDestroy",event.object1.name)

works just great.

That’s why it would be better to have the properties linked to the view so you could use it within collisions, but there is a simple workaround, try this;

local f = myLevel:getObject("Update\_start\_stop\_2") f.view.property = f.property print(f.view.property['type'])

I might even think about duplicating the properties on the view if there is one in a future release.

If you only need a single property per object, I also suggest you take a look at the built-in ‘class’ property which you can set per object, this is accessible on the view.

Yes, your removeLayerObject command looks spot on, removing an object from a specific layer with that object name.

This code works, thanks. Sadly, i would have to use

f.view.property = f.property

For every floor on every level, so i have to find another way of checking type of object.

I didn’t know that i can check class simply just by using .class. It completely solve my problem and it is exactly what i need. Thanks a lot, now i am step closer to close finish making this game. I have already around 1200 lines of code so far (not counting levels generated in LDX), so i guess in two months it will be fully playable.

Excellent, glad you found a solution.

FYI, when using classes, you can add the class names to the project, by clicking the project name in the project window, and in the properties use the standard ‘add property’ button.

This builds up a set of classes for your project and when you specify the class on an object, as you type it will list the classes from the project so you can simply select one.

Might not be useful to you, but thought I would mention it.