Hi!
I’m trying to implement some complex button behavior like change color on press.
I did a button gui with script attached to it, that listens to input and change button bg color.
Now it doesn’t work and i know why
Also, if you add a script to the template GUI scene, the script will be ignored, only one script is tied to each GUI scene and is set on the scene root node in the Outline view as usual.
So now i can’t really pre create some really useful gui templates, like same way animating buttons and so on?
Will it be possible ever, or may be i’m going wrong way?
GUI templates are node templates and nodes and behavior are separated in Defold.
You can absolutely create useful templates. The instances you create will all follow a known naming pattern so you can easily create behavior that works on any instance you create. Either put the code directly in the script for the scene that instances the template or (if you need the code elsewhere) in a module.
My idea is to make a separate gui file (animated_button.gui) and put there Box (as background) and Text (as text ).
Then i would like to create menu dialog. This dialog will have 3 animated buttons. How should i add these animated buttons to it? As from docs i can’t do it from editor, because script from buttons will be ignored.
Now i animate them from menu dialog script, but if i have another dialog with animated buttons, i will have to copy/paste animation code there?
By module @sicher means a Lua module. A Lua module is a file with .lua extension that can be required by your scripts and provide shared functionality. Modules are described in detail in the Modules manual. They are not a Defold specific thing but rather a Lua language concept so this or this resource applies as well.