Toggle Frames with ONE button

Get help using Construct 2

Post » Sat Dec 15, 2012 10:01 pm

Hello,

I have a character that I want to have PUNCH with his fists
when the SPACE key is pressed...

However, I would like to have this character TOGGLE back
and forth between LEFT and RIGHT PUNCHES with each SPACE key
press...

Example:
SPACE key Pressed = Select Frame0 (LEFT PUNCH)
SPACE key Pressed = Select Frame1 (RIGHT PUNCH)

I am having trouble testing a boolean state.
I can create a Global variable or Instance Variable (BOOLEAN)
but I can't find a method to TEST the current state.
If PunchLR = True then...
or
If PunchLR = False then...

Any ideas to get my DUDE to TOGGLE PUNCHES with just ONE SPACE key press???
B
5
Posts: 58
Reputation: 916

Post » Sun Dec 16, 2012 1:07 am

How about this?

Create a global variable called "spacekey" or something like that. Then create an event: "on Space Key pressed" -> Set variable "spacekey" to "1-spacekey" (without quotes; and where "spacekey" is the name of your global variable; on the event sheet it should look like this: 1-spacekey.

Now create 2 new events for "Compare variable spacekey"...
on the first one: "spacekey" = 0 -> Set animation to Frame0
on the second one: "spacekey" = 1 -> Set animation to Frame1


Please let me know if this works out for you.
B
14
S
5
G
4
Posts: 121
Reputation: 3,938

Post » Sun Dec 16, 2012 9:45 pm

Thank you for the advice...
It did work, randomly though..

Normally, I would just create a global boolean variable
and add..

if boolean = true then setframe to 1
if boolean - false then setframe to 0
and then toggle the boolean variable...

No???

Not possible???
B
5
Posts: 58
Reputation: 916

Post » Sun Dec 16, 2012 9:47 pm

Bascially,

ON KEY DOWN

Test the boolean variable..
If true, then set frame to 1
if false, then set the frame to 0
then toggle the boolean variable state for the next keypress
B
5
Posts: 58
Reputation: 916

Post » Sun Dec 16, 2012 10:06 pm

Create your sprite with your boolean, let's say "leftPunch", then setup your events like so...

On key pressed |
    Is boolean instance variable set ('leftPunch') | - set frame 0
                                                                         - toggle boolean ('leftPunch')
    Else | - set frame 1
             - toggle boolean ('leftPunch')

That should get you started. "Is boolean instance variable set" only tests for true however, if there are moments when you specifically need to test for false, simply right click the condition and select "invert" this makes it a NOT condition. So basically, "Is boolean instance variable set (inverted)" = "If boolean is NOT true". Hope this helps :) Merry Christmas!
B
64
S
8
G
9
Posts: 290
Reputation: 8,590

Post » Wed Dec 19, 2012 3:03 am

Hey Brent,

Thanks for the advice..

I created a BOOLEAN Instance variable for this sprite which has 2 frames
LEFT=0 and RIGHT=1 for LEFT RIGHT punches.

I have a ON KEY DOWN event..
In that event, I am not seeing an option for testing the BOOLEAN instance variable as you suggested.
The menu choices are as follows..
ADD TO, SET VALUE, TOGGLE BOOLEAN, SET BOOLEAN, SUBTRACT FROM
The SET VALUE never seems to SEE my instance variable on the list.
My guess is because it is not meant for Boolean values.

I have been puzzled by the menu options available at times.
Under what situation does the options for
"If then else" appear???
B
5
Posts: 58
Reputation: 916

Post » Wed Dec 19, 2012 3:03 pm

Sounds like you're looking at actions. The option for comparing booleans is a condition.

For else, right-click the event and go to the 'Add' sub-menu and the last option is 'Add else'. Or the shortcut is select the event and press 'X'.

B
54
S
28
G
18
Posts: 1,520
Reputation: 24,990

Post » Wed Dec 19, 2012 7:32 pm

Hey Ramones,

THANK YOU sooo MUCH...

I'm new to C2, less than 2 weeks, and I've been trying to find the conditional logic menu system.

I "right-click" and your right, there they are..
Sheesh...

Thanks again... :)
B
5
Posts: 58
Reputation: 916

Post » Thu Dec 20, 2012 10:22 pm

You could use an integer too to keep track of which animation is playing.
On key pressed
   Set animation to instanceInt
   Set instanceInt to (instanceInt + 1) % 2

A bit tidier and permits you to add a third or even more animations to your attack sequence !Magistross2012-12-20 22:23:57
B
45
S
16
G
18
Posts: 845
Reputation: 13,673


Return to How do I....?

Who is online

Users browsing this forum: Maced0, Magistross and 1 guest