Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: MurrayL on Tue 06/11/2012 16:00:26

Title: Using boolean as an int?
Post by: MurrayL on Tue 06/11/2012 16:00:26
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.
Title: Re: Using boolean as an int?
Post by: Crimson Wizard on Tue 06/11/2012 16:43:02
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?

Title: Re: Using boolean as an int?
Post by: Khris on Tue 06/11/2012 16:51:56
Yeah, true is typecast to 1 and false to 0 anyway.
Title: Re: Using boolean as an int?
Post by: MurrayL on Wed 07/11/2012 00:05:37
Aha - excellent. That's what I wanted to know, thanks guys!
Title: Re: Using boolean as an int?
Post by: Calin Leafshade on Wed 07/11/2012 08:37:14
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.