Global Variables: Booleans?

0 favourites
From the Asset Store
Globals 2.0
$3.99 USD
Globals 2.0 stores and group variables. You can also load and save data (variables) from/to JSON files.
  • 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?

  • Yeah, it�s 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.

  • +1. Can't understand why we don't have global booleans already.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Yeah, this was kind of an oversight when the global variables system was developed. I've been meaning to get round to fixing it...

  • 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.

  • 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.

  • 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..

  • 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.

  • Yeah, this was kind of an oversight when the global variables system was developed. I've been meaning to get round to fixing it...

    That's good to hear! There's definitely lots of work for a two-man team to do, so that's understandable.

  • I have something pretty similar

    I'm using moving = -1,0,1 for moving left, standing still, and moving right.

  • Me too. I use "true/false" strings or 0 or 1 as a substitute, but it's still not the most convenient method, especially when employers actually look at my code...

  • if you do get around to adding global bools please also add an option to set the value of the bool not just toggle it. The toggle is useful no doubt but Id like the ability to set the value directly as well. Same for instance bools. I dont use those at all simply because I cant set the value

  • aridale, you can set the value of instance booleans. They would be pretty usless for most situations if you could only toggle.

  • is that new? I just checked in r99 and theres is a set boolean but I swear Ive never seen it before... only toggle

  • if you do get around to adding global bools please also add an option to set the value of the bool not just toggle it. The toggle is useful no doubt but Id like the ability to set the value directly as well. Same for instance bools. I dont use those at all simply because I cant set the value

    But there is a Set Boolean event already.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)