Been wondering why its not possible to define a string property
like the one below
go.property(“name”, noname))
I always get this error “Only these types are available: number, hash, msg.url, vmath.vector3, vmath.vector4, vmath.quat…” are allowed
Instead i have to write it as go.property(“name”, hash(“noname”))
Id like to be able to pass string properties without have to figure out how to cast a hash back to a string.
@Pkeod
I’m trying to pass a table of values to a factory to initialize the objects
My understanding is that the object getting initialized captures the values through properties.
Factory code below:
local id = factory.create("#commodityfactory", pos, null, { position = vmath.vector3(), name = “corn” }
)
CommodityFactory creates a commodity object.
There i figured that the values i passed get mapped to the properties
go.property(“position”, vmath.vector3())
go.property(“name”, “noname”)
Note: this code doesnt work, because it needs to be a hash. Is there any other clean way to do this besides passing in a message? I’d like to cleanly initialize the objects and have the values automatically accessible through “self”.
Yeah, you have to pass that as a message or perhaps keep the value you received from the external service in a look-up table and pass the index/id/key into that lookup table in factory.create() and look it up in the created object using the provided key.
We steer away from strings in the runtime at all times since they are so problematic. A single string has no real impact on anything, but since they are so convenient for us humans they tend to rapidly populate the memory. In the worst case, you can end up with the most problematic of perf issues; when a lot of things take a little time each, summing up to a problem. It takes a really long time to fix issues like that. This is why we deliberately don’t support strings, to guide users towards working with hashes which are free from these issues.
The exception is obviously as you stated, when you want to display information to the player. The information comes from two sources, static (which often becomes localised and fits well in a string library) or dynamic from web services or other players. In the dynamic situation it still makes sense to keep these things in a separate data store and the thing to display stuff has a key into that store (like @britzl’s example). You might want to be able to supply place holder info in the absense of responses, etc.
I understand what you mean. I’m unsure if these will always cover the scenarios though. Unfortunately this indirection doesn’t provide a smooth flow for a developer to transition to using defold. It seems developer would normally gravitate and expect to be able to do certain things and restricting this by design seems odd and should frankly be handled some fluid way (maybe define a custom string implementation that gives you the benefits of both worlds). But i appreciate the help.
Suppose I’m making a tutorial for my game, placing dozens of “info” signs near various tutorial levels and objects. They all look the same, but display different text when clicked. In Unity/UE4 you would just place the same prefab dozens of times, and then edit the property of each individual info sign, which is a string! Same for other game objects that look alike but display/say different texts, like NPCs with one-liners and unique names. How can I achieve this in Defold without creating a mess, like setting an int instead of a string, and then looking the actual string up from the int?
I’d use a hash as property and use that to lookup a string from a dictionary (table). This is really the way to go, especially if you plan to translate the text in your game.
I’m creating a lot of texts, infos, names, etc in the way guys are describing here it is very convenient, when you want to change some text or in translating. You can create a Lua module that would store every usage combination like:
Sorry to dredge up an old discussion, but this has me a little puzzled. The string implementation is not applied because of performance? But all strings in Lua are hashed. Even when you concat a string, it is hashed - there are no direct string manipulation ops on just maintaining strings. If people want to run gsubs, or matches, then thats a functional issue, not a resource one.
This leaves me wondering why this feature would be skipped - seems to be a nice-to-have. In my case, being able to have simple get/set props on certain go’s would be very useful without a msg merry-go-round (which is actually far less performant btw - having to wait for update for completion).
Could someone explain this better. I feel like maybe Im missing something obvious. Do strings get sent up the SDK API? Because that would then make a little more sense, but kinda not … since ‘why’ comes to mind
To explain my thinking a little. There is care about performance of strings, but much of the SDK uses Lua api calls (vmath a classic example) where if you call alot of vmath functions you will create the same “string” styled issue. If you use a Lua based one, the perf probs go away (I have a lua verlet physics test that does exactly this). And so, I think (personally) it might be a valuable feature to have string properties (I think it makes it also a little more consistent).
End Dave Rant.
[ additional q ] What would be the appropriate method for “getting” text associated with a game object that has been generated in the game object (not for display btw - for data reasons). How would you attempt this via a message? ( req → resp? )