How do I make a player move by an event

Get help using Construct 2

Post » Tue Feb 07, 2017 4:15 pm

Hi!
I'm struggling with this: I'm creating a game where we use drag and drop to put commands in order, then, we read the commands and execute them, making the player move forward, backward and jump , for example.
I tried using a while loop and a 'simulate control' to the right, simulating that I was pressing the button, when I read the 'command' "move right" but it doesn't work! The game just stop working and the player don't even move.
Do you know any way to solve this?
Thanks.
B
4
Posts: 6
Reputation: 212

Post » Tue Feb 07, 2017 4:41 pm

eduardoprimeiro wrote:Hi!
I'm struggling with this: I'm creating a game where we use drag and drop to put commands in order, then, we read the commands and execute them, making the player move forward, backward and jump , for example.
I tried using a while loop and a 'simulate control' to the right, simulating that I was pressing the button, when I read the 'command' "move right" but it doesn't work! The game just stop working and the player don't even move.
Do you know any way to solve this?
Thanks.

The moment you mention "While loop" and game stops working, its most likely because it goes into an endless loop :D. So my advice is to double check that the while is actually working correctly.
B
44
S
11
G
2
Posts: 1,182
Reputation: 6,848

Post » Tue Feb 07, 2017 4:49 pm

Don't use while loop for that case. 'While' loop execute the command consecutively so fast as the condition remains true. If it can't find an exit condition, the game will crash.
ImageImage
B
111
S
51
G
24
Posts: 787
Reputation: 23,394

Post » Tue Feb 07, 2017 7:21 pm

Yes.
But do you know another way to do this?
B
4
Posts: 6
Reputation: 212

Post » Tue Feb 07, 2017 7:44 pm

For how long you want to move the player ?

This might be a solution :
Add these boolean instance variables to your player: movingRight, movingLeft, ...etc
then do, for example: when command = right then Player.movingRight = right.
then to move the player you test the boolean variables:
if(Player.movingRight) then :
- simulate right
- wait 1s
- simulate stop
B
21
S
10
G
3
Posts: 49
Reputation: 3,267

Post » Wed Feb 08, 2017 12:07 am

I tried this and it worked!
But I still have no animation and when I call use the command more than one time it only work one time.
B
4
Posts: 6
Reputation: 212


Return to How do I....?

Who is online

Users browsing this forum: Lancifer and 20 guests