How do I toggle a layer (flashlight) on/off?

Get help using Construct 2

Post » Thu Jan 09, 2014 6:06 pm

The logic for this sounded very easy in my head. But I can't get it to work like I want (or at all for that matter).

I want to create a flashlight that I can toggle on and off with the F key.

I have the flashlight object set to invisible from the start.

Here's the logic.

--> Global number FlashlightOn = 0 (this represents 'off')

Event 1 - If Flashlight is Off:

Condition 1 - If FlashlightOn = 0
Condition 2 - If 'F' key is pressed
Action 1 - Set "flashlight" object to visible
Action 2 - Set FlashlightOn value to 1 (this represents 'on')

Event 2 - If Flashlight is On:

Condition 1 - If FlashlightOn = 1 ("On")
Condition 2 - If 'F' key is pressed
Action 1 - Set "flashlight" object to invisible
Action 2 - Set FlashlightOn value to 0 ("Off")

Without the second event (which I have a feeling is unnecessary), I'm able to get the flashlight to turn on. But I'm not able to toggle it off afterwards.

Here's the event sheet:


Thanks for any help! I'm sure this is an easy thing to do. But I'm still new to C2!DrSilva2014-01-09 18:07:21
B
6
S
2
Posts: 11
Reputation: 539

Post » Thu Jan 09, 2014 6:12 pm

instead of the second event
put the flashlighton = 0 as a subevent and
use the system else condition.LittleStain2014-01-09 18:13:51
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Thu Jan 09, 2014 6:19 pm

[QUOTE=LittleStain] instead of the second event use the system else condition.[/QUOTE] That was my first thought, but 'Else' is grayed out in the right-click context menu, and if I add it as a new event (or sub-event) it says "Else (not valid here)".
B
6
S
2
Posts: 11
Reputation: 539

Post » Thu Jan 09, 2014 6:30 pm

If you put it in the right place it will work, but well..

create two events:

system compare variable flashlighton = 0
- flashlight set visible

system compare variable flashlighton = 1
- flashlight set invisible

keyboard on f pressed
- system set flaslighton : 1-flashlighton


LittleStain2014-01-09 18:31:23
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Thu Jan 09, 2014 6:52 pm

Aha! That did it. Thanks a lot!
B
6
S
2
Posts: 11
Reputation: 539


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 5 guests

cron