Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

How to read user propeteries?
Started by xenonisbad Dec 21 2016 07:09 AM

5 replies to this topic

Best Answer retrofitProductions , 22 December 2016 - 03:42 AM

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.

[TOPIC CONTROLS]
This topic has been archived. This means that you cannot reply to this topic.
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

xenonisbad

[GLOBAL: userInfoPane.html]
xenonisbad
  • Observer

  • 3 posts
  • Corona SDK

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?



[TOPIC: post.html]
#2

retrofitProductions

[GLOBAL: userInfoPane.html]
retrofitProductions
  • Contributor

  • 321 posts
  • Corona SDK

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.



[TOPIC: post.html]
#3

xenonisbad

[GLOBAL: userInfoPane.html]
xenonisbad
  • Observer

  • 3 posts
  • Corona SDK

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.



[TOPIC: post.html]
#4

retrofitProductions

[GLOBAL: userInfoPane.html]
retrofitProductions
  • Contributor

  • 321 posts
  • Corona SDK

  Best Answer

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.



[TOPIC: post.html]
#5

xenonisbad

[GLOBAL: userInfoPane.html]
xenonisbad
  • Observer

  • 3 posts
  • Corona SDK

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.



[TOPIC: post.html]
#6

retrofitProductions

[GLOBAL: userInfoPane.html]
retrofitProductions
  • Contributor

  • 321 posts
  • Corona SDK

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.




[topic_controls]
[/topic_controls]