I see the string type is not included on script properties. Why is that?
I knew there was a reason, but I couldnât find any explanation, thanks.
The issue I was running into is I store IDs of object in my game as UUIDâs, and wanted to set the id as a property. But I use messages to set them after theyâre created, so I have a workaround.
would I be able to use a UUID in this, or does it have to be a url object?
I have a working solution for me. But being able to store the UUID in a property would simplify things for me.
The UUID is a string right? Strings wonât work, so no, the URL solution is a no go. And I assume it canât be a number since itâs too large?
UUID is a string correct, and they contain alpha characters. No worries, I have a working solution.
Sorry to ressurect such an old post but that âreasonâ to not being possible to pass strings as properties is complete nonsense. I guess the user should be free to choose if he/her wanna âpopulate the memoryâ or not. Programming mistakes are parte of learning. Isnât it worse (both for use of memory AND time) to have 30 labels created as GameObjects instead of dynamically as a Factory? Well, right now I have that very problem. I have to spawn a label informing something, and I cant pass the text to the label. Sorry guys, that sucks.
Hey @lightenlynx, i donât disagree that it would be nice to be able to have strings as properties (or ANY lua type, really, including functions and tables), there is definitely a better way to do what youâre trying to do than manually creating each label as a GO.
I donât know the particular use-case, so i canât say what the âbestâ way would be. I prefer to avoid attaching scripts to everything if i can avoid it, but if you have a script on your dynamically created labels, you should be able to create them, store the url, and then pass a message with the text to set. It would be 2 lines of code (factory create, send message) instead of 1 (factory create with this property).
If you DONT have/want/need a script on your factory created label GO, you should still be able to factory create the object, get the url of the object#label from the instance returned by the factory, and then label.set_text the text of the label.
Hope that makes sense, and apologies if Iâve misunderstood your issue.
Can you please explain a bit more about your specific scenario? You spawn some game object which has a label and you need to set the text on the label as well?
1st of all, Ryan you are right, I totally forgot about sending a message. But the reason for this is that I got the other variables/parameters to work, so I guess I was a little cranky because strings didnât. Iâm a programmer who is used to procedural languages and Lua is delicious, I love those scripts.
Britzl I am working in a small adventure game, top-down view, as I always wanted to .And I want to make it multiplayer, even if it is just for fun, and my first try after tutorial was try to connect a TCP socket, what I did, and thats one of the features that made me love Defold.
So in this game, we have a character that receives and inflicts damage in enemies right⌠so I wanted the damages to appear in the screen, and fade away after some seconds.
So I made a factory for the damage with only one label. I kinda did it already, luckily the damages are numbers⌠but in the future I would use the same approach to display strings. Anyway, thats a screenshot for what I got so far:
Thank you guys, forgive my bad mood.
EDIT: I found Britzlâs example on how to make GUI elements follow the Game Object, and will study it later. Looks like it is the best approach.
No worries!
You could use labels. This is one suggestion (untested code!):
local function create_floating_combat_text(position, text, color)
local id = factory.create("#labelfactory", position)
local label_url = msg.url(nil, id, "#labelid")
go.set(label_url, "color", color)
label.set_text(label_url, text)
go.animate(id, "position.y", go.PLAYBACK_ONCE_FORWARD, position.y + 40, go.EASING_OUTQUAD, 0.6)
go.animate(label_url, "color.w", go.PLAYBACK_ONCE_FORWARD, 0, go.EASING_OUTQUAD, 0.6, 0, function()
go.delete(id)
end)
end
local function take_damage(self, amount)
self.hp = self.hp - amount
create_floating_combat_text(go.get_position(), tostring(amount), vmath.vector4(1,0,0,0))
end
Whoa that looks great. I will test this as soon as I get my coffee. Thanks really!
Dude, that works like a charm! I see now I have a lot to learn about the engine and itâs possibilities. The only thing I had to change in the code is remove the â#â where it address the label ID.
"#labelid")
should be
"labelid")
Again, really thank you.
Ah, that is correct. Happy to hear you figured it out.