Change instance variable on key pressed

From the Asset Store
Random Maze Generator with Door & Key System - tutorial capx
  • I´m working on a JRPG game. My character has an instance variable called ShipActive, which determines if it must load the character animations or the ships animations. My code is written like this : there is a condition that checks that if the Z key is pressed and the player is overlapping a dock (where you can take a ship). Inside this condition there are two subconditions: if ShipActive is 0, it changes to 1, and if it´s 1, it changes to 0. But the problem is that this isn´t working, and I can see in the debugger that the variable doesn´t change.

    I have tried removing the overlapping condition and it doesn´t work, and if I remove the subconditions and put one of the actions in the main condition, it works. For example, the initial value of ShipActive is 0, and if I put the action that changes the variable to 1 inside the condition, it works perfectly. So I suppose there must be a problem with the subconditions somewhere. So I´m asking if you can see if I am doing something wrong.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • To SEE what are you are doing wrong we would have to see the events but I think I can guess this one anyway, you probably have the variables toggling on/off in the sub events so if 0 go to 1, if 1 go to 0. With C2's top down structure it will change the variable to 1 then back to 0, if that's how you've set the sub events up. So the variable is changing, just to 1 and back to 0 in the same tick. To fix it add an Else to the conditions.

  • Thank you, you were right, I fixed the problem by replacing the second subcondition by an Else.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)