0 votes

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

in Engine by (398 points)

How does it bug the game? Are you getting any error message?

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

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...

1 Answer

0 votes

I think we need more code to help. Paste more of what you are doing.

by (143 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.