Use one button to change player postion

Why doesnt this work?

1st I would recommend placing 2 sections in an organized way: 1 for Sprites or images, 2 for movement commands
Sprites
Condition - (character) it’s on the ground
it is moving
Action - Change animation number (X)
Command move
Condition - The (X) key is pressed
Action - Simulate left key for (Character)
Flip horizontally (or vertically depending on your game) the (character) Yes/No

You are checking if the timer is above 0.2 seconds before you set the PlayerSide variable to 1.
But you are also checking if the PlayerSide variable is 1 before you start the timer.

To use 1 button for something you could use this example:

Conditions:
left mouse button released
Actions:
set variable mouse_released = 1

Sub event 1 conditions:
if mouse_released = 1
if playerside = 0
Actions:
set mouse_released = 0
set playerside = 1

Sub event 2 conditions:
if mouse_released = 1
if playerside = 1
Actions:
set mouse_released = 0
set playerside = 0

You need to start the timer at the beginning of the scene

3 Likes

If he does that, it still won’t work.
It will detect that the timer is above 0.2, then set the PlayerSide variable to 1.
Then it will also detect that PlayerSide is now 1 and set it back to 0.

Do it like this:

Better still, use a boolean, and do it all in one event :

The bonus is that GDevelop interprets a true as 1, and false as 0, so you can access it like a number variable if the need arises.

1 Like