Toggle visibility?

For questions about using Classic.

Post » Wed Sep 29, 2010 2:46 pm

I am making a DX game, and I want to know is thare some way to toggle something, like a flashlight i put in the game. Press F to turn it on, and press f again to turn it off. Please. :cry:

Help very much apreciated...
B
2
G
2
Posts: 30
Reputation: 710

Post » Wed Sep 29, 2010 3:34 pm

This is a fairly common question, usually you will want to use a private variable.
Here's how I would do it.

[url:1od5bemi]http://dl.dropbox.com/u/666516/simpleio.cap[/url:1od5bemi]
Image Image
B
161
S
48
G
90
Posts: 7,356
Reputation: 66,767

Post » Wed Sep 29, 2010 3:36 pm

Toggling is done with events through branching.

Please have a look at this thread: [url:2vjloa7g]http://www.scirra.com/forum/viewtopic.php?f=8&t=6880[/url:2vjloa7g]
Image
B
23
S
8
G
10
Posts: 1,820
Reputation: 8,242

Post » Wed Sep 29, 2010 3:45 pm

[quote="newt":35zntp90]This is a fairly common question, usually you will want to use a private variable.
Here's how I would do it.

[url:35zntp90]http://dl.dropbox.com/u/666516/simpleio.cap[/url:35zntp90][/quote:35zntp90]

I'd even do it without a private variable. Although Newt has a point since in many situations having a PV will be to your advantage.

B
21
S
6
G
10
Posts: 1,024
Reputation: 7,445

Post » Wed Sep 29, 2010 5:26 pm

[quote="newt":2p5pmpyw]This is a fairly common question, usually you will want to use a private variable.
Here's how I would do it.

[url:2p5pmpyw]http://dl.dropbox.com/u/666516/simpleio.cap[/url:2p5pmpyw][/quote:2p5pmpyw]

Thank you, but would you mind just explaining the code for me so that I can remember it for future use. Thanx :mrgreen:
B
2
G
2
Posts: 30
Reputation: 710

Post » Wed Sep 29, 2010 7:32 pm

The way I make values that toggle goes like this.

Sprite-- set value to-- 1 - Sprite.value('value')

With this the value will always be 1 or 0, so you can set the visibility to 1=on 0=off. Or doors 1=open 0=closed, etc. Very handy to keep this one in mind.
B
9
S
2
G
4
Posts: 346
Reputation: 2,726

Post » Wed Sep 29, 2010 10:20 pm

Thank you Steven
B
2
G
2
Posts: 30
Reputation: 710

Post » Wed Sep 29, 2010 10:37 pm

For simplicity's sake Steven's, or PRb's way is probably better.
I wonder if a plug for this would be a good idea.
Boolean behavior anybody?
Image Image
B
161
S
48
G
90
Posts: 7,356
Reputation: 66,767


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 3 guests