programming (general)

Chat about anything not covered in these forums, but keep it civil!

Post » Sun Sep 04, 2011 9:40 pm

Steven from this forum made a cap for me.
In it he made a "switch" with a global variable.
But very efficient.

If pressed 'm'
set variable to 1 - variable

I always did:
if variable = 0 and 'm' is pressed (...)
if variable = 1 and 'm' is pressed (...)

I like how efficient this is and I'm sad I did not come up with this myself.
What is my point? I hope someone can comment on this, in any way.
For example: is this new for you?
B
28
S
6
G
7
Posts: 681
Reputation: 5,682

Post » Sun Sep 04, 2011 10:02 pm

the light bulb just came on when i tested the code in my head.
that...is cool.

well done steven.
B
81
S
32
G
23
Posts: 1,053
Reputation: 35,965

Post » Sun Sep 04, 2011 10:10 pm

There's always: on m pressed add 1 to global
global modulus =0 do stuff
global modulus =1 do stuff
Image ImageImage
B
171
S
50
G
179
Posts: 8,382
Reputation: 113,458

Post » Sun Sep 04, 2011 10:17 pm

There are tonnes of ways to switch a variable from 0 to 1! Here's another, using conditions in expressions, which is one of my favourite "hidden" features:

m = 1 ? 0 : 1

Conditional expressions work like this: condition ? result_if_true : result_if_false
So as you can see when m is 1 it's set to 0, and vice versa.
Scirra Founder
B
399
S
236
G
89
Posts: 24,525
Reputation: 195,382

Post » Sun Sep 04, 2011 10:20 pm

Is that feature implemented in C2?
ImageImageImageImage
B
158
S
66
G
43
Posts: 2,603
Reputation: 35,868

Post » Sun Sep 04, 2011 10:34 pm

Yup, try it!
Scirra Founder
B
399
S
236
G
89
Posts: 24,525
Reputation: 195,382

Post » Sun Sep 04, 2011 10:41 pm

Just did! and it's awesome :D
ImageImageImageImage
B
158
S
66
G
43
Posts: 2,603
Reputation: 35,868

Post » Sun Sep 04, 2011 10:57 pm

Image
B
243
S
30
G
13
Posts: 1,787
Reputation: 18,770

Post » Sun Sep 04, 2011 11:02 pm

Shame it doesn't work with text variables :)
ImageImageImageImage
B
158
S
66
G
43
Posts: 2,603
Reputation: 35,868

Post » Sun Sep 04, 2011 11:28 pm

I always used 1 and minus 1, so when I switched the value I just multiplied it by -1. Still, this method is awesome =D

Hey Ashley, is that in CC as well?
"Construct 4 lets YOU make advanced games! (they wont run anywhere)" Construct Classic - Examples Kit Dropbox is a pile of trash and if you need my old files PM me! :)
B
125
S
42
G
17
Posts: 2,228
Reputation: 19,918

Next

Return to Open Topic

Who is online

Users browsing this forum: No registered users and 3 guests