GUI Template and gui_script

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 :slight_smile:

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.

From docs here

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?

2 Likes

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.

Don’t think i understood you :frowning:

My idea is to make a separate gui file (animated_button.gui) and put there Box (as background) and Text (as text :slight_smile: ).

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 you mean to put animating code to it and use code whenever i want just buy including it?

Check a frame size (parent node size) of your button.

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.

@sven’s Dirty Larry library is a perfect example of how to provide reusable GUI components with behaviour in a Lua module.

2 Likes