Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Boolean operations? (I think)

Author
Message
Mobiius
Valued Member
21
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 29th Dec 2012 15:36
Hello, is there a way to check a decimal number to see if another power of two number has it's bit set in AppGameKit?

In more detail, I want to have a system where I can set a flag and check it's corresponding bit to see if it's enabled.

E.G.
Option1 = 1
Option2 = 2
Option3 = 4
Option4 = 8

OptionList = OptionList && Option1 && Option3

So now OptionList should be 5. (Or 00000101 in binary)

I've tried this but it doesn't work as I expected. Is anyone able to direct me to what I'm doing wrong??

Thanks.

I live for video games! (And beers, and football, and cars!)
See what I live for here: [url]http:\\www.TeamDefiant.co.uk[/url]
JimHawkins
15
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 29th Dec 2012 15:57
Try using & instead of &&

If you want to add bits in you should logical OR - |

Life is much better in Pascal. This what sets do in a highly optimised way:

type tOptions = (none,one,two,three,quitter);
tOptionSet = set of tOptions;

var Options : tOptionSet;
Options := []; // empty set

Options := Options +[one];
Options := Options + [two];
Options := Options + [Quitter];

You could also do this with Options := Options + [one,two,quitter];

You can do set compliment, exclusion, intersection, difference and comparison. But quite simply:

if quitter in Optionset then ByeBye;

I won't drone on. Happy New Year!

-- Jim DO IT FASTER, EASIER AND BETTER WITH AppGameKit FOR PASCAL
Marl
13
Years of Service
User Offline
Joined: 19th Nov 2011
Location: Bradford, UK
Posted: 29th Dec 2012 18:35
Quote: "I want to have a system where I can set a flag and check it's corresponding bit to see if it's enabled."

I have used a similar thing for directions;

The constants can also be expressed as binary if it makes things easier;
Mobiius
Valued Member
21
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 29th Dec 2012 18:38
Cheers, sorted it after being pointed in the right direction by Jim.

To add the flag, it's ||
To check the flag it's &&

Everything's working as it should now.

(I even added a ternary IF function too. I'm to spoilt by php!)

I live for video games! (And beers, and football, and cars!)
See what I live for here: [url]http:\\www.TeamDefiant.co.uk[/url]
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 2nd Jan 2013 17:20
Marl, I think you want to change the '&&' to '&'. The way you have it, you will get a true result for both tests as long as myObject.flags is not zero.

Cheers,
Ancient Lady
AGK Community Tester and AppGameKit Master
Mobiius
Valued Member
21
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 3rd Jan 2013 15:05
Using & doesn't work as expected, but && does.

I live for video games! (And beers, and football, and cars!)
See what I live for here: [url]http:\\www.TeamDefiant.co.uk[/url]
JimHawkins
15
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 3rd Jan 2013 15:59
As I said before, you should be using | (LOR) to add bits. If you want to use AND, you need a mask with all bits set.

-- Jim DO IT FASTER, EASIER AND BETTER WITH AppGameKit FOR PASCAL
Mobiius
Valued Member
21
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 3rd Jan 2013 18:11
I am using || to set bits, and && to check if a bit is set.

I live for video games! (And beers, and football, and cars!)
See what I live for here: [url]http:\\www.TeamDefiant.co.uk[/url]

Login to post a reply

Server time is: 2024-11-24 06:58:41
Your offset time is: 2024-11-24 06:58:41