Global Variables: Booleans?

Discussion and feedback on Construct 2

Post » Tue Jul 31, 2012 7:55 pm

I can't help but feel wrong whenever I use a number or text global variable when I only need a boolean value. It can work in the same way, but it's a little more hassle to work with.

Any chance of having global variables giving a boolean option in the future?
B
19
S
5
G
1
Posts: 104
Reputation: 2,920

Post » Tue Jul 31, 2012 9:05 pm

Yeah, its odd to have booleans available in the local instances of the objects and not in the global.
I personally use string values with "true" and "false" just to make it more readable.
B
38
S
8
G
3
Posts: 438
Reputation: 6,869

Post » Tue Jul 31, 2012 9:11 pm

+1. Can't understand why we don't have global booleans already.
B
54
S
28
G
18
Posts: 1,520
Reputation: 25,020

Post » Tue Jul 31, 2012 11:34 pm

Yeah, this was kind of an oversight when the global variables system was developed. I've been meaning to get round to fixing it...
Scirra Founder
B
359
S
214
G
72
Posts: 22,951
Reputation: 178,578

Post » Wed Aug 01, 2012 2:15 am

I got into the habit of using 1/0 for true/false. It had unexpected advantages so now I use 1/0 for instance variables also.
B
28
S
8
G
1
Posts: 469
Reputation: 4,683

Post » Wed Aug 01, 2012 2:43 am

@keepee: Unexpected advantages, how so? I'm just curious.

One thing I like about booleans is the "Toggle boolean" action, very useful in some cases.
B
27
S
8
G
8
Posts: 903
Reputation: 8,452

Post » Wed Aug 01, 2012 3:38 am

I found myself able to condense multiple events..

Say there's two events for one object:

the first runs when A is 0 and the action makes something = B
the second runs when A is 1 and the action makes something = B + C

you can just have one event which runs instead of both where the action is B+(C*A)

It sounds like a one off occasion but i've ended up using something similar to this atleast three or four times. I've no idea if it's faster or slower during runtime, but it makes the events look a bit simpler.


And occasionally I find myself unexpectedly wanting a third option after intending something to be boolean.
A good example was if you have Player and NPC's both use the same 'body' object as a base, you will need a variable "player" to determine which one the user controls.

So I had Player=0 for npc's and Player=1 for the user.. As I was doing the controls I realised I could just have Player=2 and Player=3 also for some crude multiplayer :p

Also yeah, the toggle option is useful.. keepee2012-08-01 03:40:44
B
28
S
8
G
1
Posts: 469
Reputation: 4,683

Post » Wed Aug 01, 2012 3:51 am

I see @keepee, thanks for taking the time to elaborate!

I often do the second thing you mentioned myself, like use a number for movement events. Instead of using a boolean "moving = false or true", I usually use a number "moving = 0 or 1" just in case I want to add running later. Then I can just use "moving = 2" for that.
B
27
S
8
G
8
Posts: 903
Reputation: 8,452

Post » Wed Aug 01, 2012 4:17 am

[QUOTE=Ashley] Yeah, this was kind of an oversight when the global variables system was developed. I've been meaning to get round to fixing it...[/QUOTE]

That's good to hear! There's definitely lots of work for a two-man team to do, so that's understandable.
B
19
S
5
G
1
Posts: 104
Reputation: 2,920

Post » Wed Aug 01, 2012 4:24 am

I have something pretty similar
I'm using moving = -1,0,1 for moving left, standing still, and moving right.
B
28
S
8
G
1
Posts: 469
Reputation: 4,683

Next

Return to Construct 2 General

Who is online

Users browsing this forum: No registered users and 5 guests