Change label text of each instance of prototype

I want to create a speech bubble game object with scriptable behavior as a re-usable prototype which I can embed within other instances. However the text cannot be set for each instance, as setting it for one will change it for all.

Here’s my file structure:
person.go - file with script controller and other components
speech_bubble.go - file with label component and script controller

And in the main collection outline:

  • person1 - instance of person.go
    – controller - instance property is set here
    – speech_bubble1 - embedded instance of speech_bubble.go
    ---- controller - an instance property is set here
    ---- label component
  • person2 - instance of person.go
    – controller - instance property is set here to a different value
    – speech_bubble1 - embedded instance of speech_bubble.go
    ---- controller - an instance property is set here to a different value
    ---- label component

With this structure, I cannot have a unique label for each person. Is this possible? Maybe I misunderstand how defold works. But I would like to use this configuration so that my other non-coding teammembers can create instances of a person with or without a speech bubble.

Yeah, as you’ve discovered it’s not possible to achieve this the way you’ve tried to do it. Some ideas:

  • Use a gui with a gui template for the speech bubble and render that in a separate pass so that they follow the person instead of being anchored to screen coordinates (like in this example)
  • Set the label programmatically, based on a script property. The script property would be a hash that is the key to a string value in a lookup table with speech bubble texts.
2 Likes

Thanks @britzl. Do you know if this is a limitation of the label component or if this will ever be implemented?

Well, it’s not so much a limitation of the label component as it is with the collection system. In this case we’d need something similar to the gui templates, which lets you override properties of an instance. It’s not something we have in our current roadmap, but some day in the future we might add that.

2 Likes

5 posts were split to a new topic: How to change mass of collision object?