Using boolean as an int?

Started by MurrayL, Tue 06/11/2012 16:00:26

Previous topic - Next topic

MurrayL

Is there any easy/quick way to cast a boolean variable as an integer (0 or 1)?

I've got a series of hotspots that can be switched on/off, and I'd like to be able to use their state to also modify their sprite number (hotspot.Graphic -= hotspotState).

I could just store their state as a 0/1 integer, but it seems more efficient to store it as a boolean if possible.

Crimson Wizard

#1
Store those states as 'chars'. Boolean values won't be smaller than chars anyway.
And you won't need to cast them, since char is just integer... only smaller.


EDIT: Oh my, what am I saying...
AGS allows to simply add boolean to integer, so you don't need to cast anything yourself. Why did this question arise at first place?


Khris

Yeah, true is typecast to 1 and false to 0 anyway.

MurrayL

Aha - excellent. That's what I wanted to know, thanks guys!

Calin Leafshade

Interestingly, AGS doesnt even have a bool type really. It just an Enum with values 0 and 1 and enums are just ints.

The more you know.

SMF spam blocked by CleanTalk