0 votes

Sorry everyone I tried uploading pics but basically I just have a button called runbutton> toggle signal> connected to control> and I have that scene emitting signals to my player scene in the main and when I click the button in game the players move speed is updated to run speed. This works, however when I click the button after, my player doesn't return to regular move speed, which is what I want. I've tried:

Emit_signal("walk") in control node script and all sorts of variations

Func onrunbutton_run();
Speed = run speed
Ok this works, but i want my player to go back to just Speed when I click the button again.

Here is my code and signals I've connected
Control node>button

Extends control
Signal run
Signal walk
Func onbutton_toggled():
Emit signal("run") <-stops working here.
Emit signal("walk")<-this is just a guess I don't know what I'm doing
Main scene


Player script:
Func onrunbuttonrun():
Speed=run speed
Func _on
Speed = speed
And I have very basic movement functin, if key pressed move, physics process delta, vector2 etc.
Any thought into this matter is very much appreciated.

asked Aug 13 in Projects by Et24 (12 points)

1 Answer

0 votes

Of course it doesn't go back to Speed. You changed Speed into run_speed, remember?

Speed=run speed

Speed is now equal to run_speed and when you press the other button you essentially say:

Speed = Speed

Create another variable named initial_speed or something and change your value using that. What you want is 3 variables:
1) Speed is the value that controls the characters speed at all times
2) Initial_speed is the starting value.
3) Run_speed is the highest value

When button is pressed, if Speed==Initial_speed then turn it into Run_speed.
If Speed==Run_speed then turn it into Initial_speed.

If you found this answer useful, please mark it as best.

answered Aug 14 by johnygames (614 points)
edited Aug 14 by johnygames
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 How to use this Q&A? before posting your first questions.