Why no local or global boolean variables?

Discussion and feedback on Construct 2

Post » Sun Nov 08, 2015 6:35 am

But Why?
Image
B
33
S
11
G
2
Posts: 564
Reputation: 5,163

Post » Sun Nov 08, 2015 8:30 am

ruskul wrote:But Why?


If you try Search you'll find that Ashley admitted it was just an oversight and has been on the todo list for a while.
If your vision so exceeds your ability, then look to something closer.
Moderator
B
136
S
31
G
87
Posts: 5,490
Reputation: 60,266

Post » Sun Nov 08, 2015 8:30 am

because setting an integer variable to 0 or 1 is the same thing,

though i think it should reduce a bit of code, instead of checking if something == 1 or 0 , you could do if (var) -> do something,
because booleans by default have false or true only. wouldn't affect performance, only would be easier to write a line.
Sea Monsters template - Isometric
Also includes 40 pages PDF of optimizations and "how-to" for your games, and how the "sea monsters" template was built. Follow link for details :)

sea-monsters-templates-and-assets_t162705
B
43
S
14
G
12
Posts: 626
Reputation: 9,450

Post » Mon Nov 09, 2015 12:39 am

I agree, and setting a variable to 1 or 0 is simple enough, of course, whether it's a boolean or not. A simple work around for of you need to toggle a boolean/ivariable without having to check it first:

Variable1 = (Varable1 + 1) % 2
A big fan of JavaScript.
B
76
S
20
G
74
Posts: 2,254
Reputation: 46,482

Post » Mon Nov 09, 2015 12:45 am

Or just make global object with boo's. I am actually finding this much more comfortable then if I'd have to scan trough globals and locals.
My professional Royalty Free Music at Scirra Assets Store
--------------------------------
Specs: i5 2500, 16gb of ram, gtx 770, win 7, Focusrite Scarlett 8i6, Mackie mr8mk2, Alesis 320, browsing the net on chrome.
B
91
S
30
G
22
Posts: 1,985
Reputation: 20,149

Post » Wed Nov 11, 2015 3:55 am

megatronx wrote:Or just make global object with boo's. I am actually finding this much more comfortable then if I'd have to scan trough globals and locals.


Well, I must admit I do that as well. lol. In large projects its no good to use global variables. There are too many of them and no way to organize them. But I would like to use local variables. They are a bit more meaningful than saying set TempObject.TempBoolean to false
Image
B
33
S
11
G
2
Posts: 564
Reputation: 5,163

Post » Wed Nov 11, 2015 6:21 am

saiyadjin wrote:because setting an integer variable to 0 or 1 is the same thing,

though i think it should reduce a bit of code, instead of checking if something == 1 or 0 , you could do if (var) -> do something,
because booleans by default have false or true only. wouldn't affect performance, only would be easier to write a line.


I didn't know that. Thank you! (Not a sarcastic response).
Risk Rocket now available on Google Play
Image
B
36
S
15
G
6
Posts: 337
Reputation: 6,300

Post » Wed Nov 11, 2015 1:08 pm

ruskul wrote:
megatronx wrote:Or just make global object with boo's. I am actually finding this much more comfortable then if I'd have to scan trough globals and locals.


Well, I must admit I do that as well. lol. In large projects its no good to use global variables. There are too many of them and no way to organize them. But I would like to use local variables. They are a bit more meaningful than saying set TempObject.TempBoolean to false


I'm calling that object just SYS . I use local vars too. Depends what is needed.
My professional Royalty Free Music at Scirra Assets Store
--------------------------------
Specs: i5 2500, 16gb of ram, gtx 770, win 7, Focusrite Scarlett 8i6, Mackie mr8mk2, Alesis 320, browsing the net on chrome.
B
91
S
30
G
22
Posts: 1,985
Reputation: 20,149

Post » Fri Nov 13, 2015 11:00 am

ruskul wrote:
megatronx wrote:Or just make global object with boo's. I am actually finding this much more comfortable then if I'd have to scan trough globals and locals.


Well, I must admit I do that as well. lol. In large projects its no good to use global variables. There are too many of them and no way to organize them. But I would like to use local variables. They are a bit more meaningful than saying set TempObject.TempBoolean to false


I must have around 600 global variables. With a good naming system, they are manageable. ;)
B
70
S
24
G
19
Posts: 1,757
Reputation: 17,616

Post » Fri Nov 13, 2015 8:10 pm

@Silverforce - With a good naming system, it is true... But I would postulate that the better the names the longer it takes to type. In a programing language, these variables would be better split among objects or static singletons that are a snap to access.

In Construct -

LevelSpawnPlayerType = something.

in c#

level.Spawn.Player.Type = something.

Autocomplete doesn't work in construct until you get far enough. LevelSpawnPLayerT... if another variable LevelSpawnPlayerLocationX or LevelSpawnEnenmy... or som on exists. In other IDE, splitting the variables up allows you to access them using auto complete which would function at each level of organization. That's the primary reason I stick them in objects as opposed to using globals. Also, the variables clutter up your expressions list every time you start typing in expressions. But if it works for you the way you do things, great, keep it that way!

I should also point out I suck at typing and the more help I get the better. Too slow! :cry: iama diamond/masters starcraft player but my apm is only like 90 :( I fail at typing in the same way. lol
Image
B
33
S
11
G
2
Posts: 564
Reputation: 5,163

Next

Return to Construct 2 General

Who is online

Users browsing this forum: No registered users and 10 guests