Custom component properties: Adding a string/text and vector data property?

Manual reads :
"[…]hashes allow you to enter the string that will be hashed[…]"

I’ve managed to add boolean and number properties(to script components) but not string/text or vectors.

This means the following fails to show as a property in the UI :

go.property("sometext","String I want displayed")
go.property("avector",{1,2,3})

What am I missing?

Thanks

My solution - pass text as hash and keep a table to match hashes with strings.
Or you can try tostring() lua function.

Have you tried to pass vector as vmath.vector3 ?

1 Like

We don’t support strings, or arbitrary tables yet. We support “(number | hash | url | vector3 | vector4 | quaternion)” (from the doc)

An example:

go.property("text_id", hash("text0"))
go.property("avector", vmath.vector3(1,2,3))
1 Like

I would recommend NOT doing tostring() on the hash.
It does work on the dev build but will not work on the release build as it doesnt keep the string dict for the hashes.
Pass hashes or numbers as keys for a table you got stored somewhere.

1 Like

Thank you kindly all for your responses.

JCash : Your examples were most helpful. As a Lua newbie, it had not occurred to me that the docs were referring to Lua library functions.
Could you suggest any good resources for learning the Lua libraries?

Programming in Lua is the definitive resource for learning all the ins and outs of the language.

2 Likes

Using a lookup table and reading back the original value in the created game object is a good solution. I did an example of this a while back:

Here’s the relevant lines of code in the factory script:

https://github.com/britzl/publicexamples/blob/master/examples/factory_and_properties/factory.script#L22-L31

And in the created game object:

https://github.com/britzl/publicexamples/blob/master/examples/factory_and_properties/thing_with_properties.script#L16

1 Like

Contrary to my assumptions, hash() and mathv.xx are not part of the Lua libraries, but in fact extensions to it.
The reason for using hashes is also made clear here.

Yes, hash, vmath (not mathv!), go, gui, factory and several other Defold specific concepts are part of the Defold APIs.

1 Like