Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | bobokox | |
Old Version | Published before Godot 3 was released. |
Hey!
I have a script for textured buttons and i want to use it for more than one node.
If i connect a signal with a script its fixed on the node. indipendet from where the script is.
i already found an alternative for pressed()
in script, but i totally need the mouse_exit()
function. I found is_hovered()
but it doesn’t help, because i need the trigger in the moment the mouse exits the button.
is there a way to do it per script, Independent from the node which carries the script or is there a possibility to get the connection automatically from the current node?
thank you
I’m a bit confused about what you mean. When you say “for more than one node”, do you actually mean “for more than one type of node”? (for example Button, Control, TextureButton…).
All controls inherit Control
, there is enough stuff in there to do any kind of button.
Can you provide one example where you have a problem?
Zylann | 2017-04-04 12:43
Hey Zylann.
thank you for the comment.
sry for the bad explanation. Let’s try it again
I have several texturebutton-nodes in my scenes. They are all collectable and all of them should carry the same script.
The script should change a global variable, when the mouse is hovering, and set the variable to 0 when the mouse exits the button. and here is the problem. when i make the script with
if is_hovered() == false: global.MyVar = 0
it doesn’t work if i have more than one texturebutton-node with the script in my scene, because the last script which runs will set the global var to 0 if its not hovered, meaningless if an other texturebutton is hovered.
so, what i need is something like the mouse_exit()
signal, but individually for every texturebutton-node which carries the script.
Don’t get me wrong, im pretty sure i would be able to solve this with is_hovered()
and some if querys, but there is such a simple way to do it with signals, so their must be a way to do it simple in script too.
the whole script:
extends TextureButton
export var type = "coco"
export var time_need = 5
export var visible = true
var generate = false
func _ready():
set_fixed_process(true)
func _fixed_process(delta):
if visible:
set_hidden(false)
else:
set_hidden(true)
if is_hovered():
global.time_needed = time_need
if is_hovered() == false: ################### heres the problem
global.time_needed = 0
if is_pressed() == true:
visible = false
if type in global:
var a = global.get(type)
a += 1
global.set(type, a)
print(global.get(type))
i hope its better understandable now. im very bad in explaining things
bobokox | 2017-04-04 14:25