Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Newby |
i know about the button pressed() signal but it when i use it in my code it bugs the game i want to be some thing like this
get_node("Choice1").connect("pressed",get_node("Enemy"),"attack",[get_node("Player")])
i want it something like if a button is pressed call function
How does it bug the game? Are you getting any error message?
hilfazer | 2018-03-01 15:47
i feel like i exaggerated on the bug part its more of the game not working the way i want it to. anyway do you know how to make an if statement with the button without using the signal nodes.
my game is has a multiple choice part and i want it so that when a button is press for an answer the game will go to the next question.
And the “Bug” i mention happens when i have a connect(“pressed”) with a button signal pressed, if you keep getting the right or wrong answer in a row it works fine player gets damage when wrong enemy when right but when the streak ends they both get damaged and i don know why.
im sure is the signal because when i remove it every time works fine
Newby | 2018-03-02 08:18
If you want if statement instead of signal, the closest you can get is use signal to turn some variable to true and then make condition to check that variable. When you press button, your if code will execute on next call of _process.
It could look like this:
get_node("Choice1").connect("pressed",get_node("Enemy"),"attack")
Then inside Enemy script:
var attacked = false
func attack():
attacked = true
func _process(delta):
if attacked:
attacked = false
#some other code...
KoBeWi | 2018-03-03 21:18