Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 05-26-2006, 06:44 AM
jake13jake jake13jake is offline
Former Classic Staff
jake13jake's Avatar
Join Date: Dec 2002
Location: Northwest Vermont
Posts: 1,452
jake13jake will become famous soon enough
Detecting multiple values in a bitflag

Is there any other way to test for multiple values in a bitflag other than iterating through it?
Reply With Quote
  #2  
Old 05-26-2006, 08:23 AM
Rick Rick is offline
PipBoy Extraordinaire!
Rick's Avatar
Join Date: Jul 2004
Location: Long Beach, California.
Posts: 831
Rick is on a distinguished road
if (flags & (flag1 | flag2))
Reply With Quote
  #3  
Old 05-26-2006, 03:12 PM
jake13jake jake13jake is offline
Former Classic Staff
jake13jake's Avatar
Join Date: Dec 2002
Location: Northwest Vermont
Posts: 1,452
jake13jake will become famous soon enough
Quote:
Originally Posted by Rick
if (flags & (flag1 | flag2))
uhhhhhhh... not really what I meant.
you could have
100000000000000000000000000000001
or
000000000000000010000000000000000

I mean, of course I would know the range of this flag. it certainly wouldn't take all 32 places.

What would be the best way to detect if there is more than one value stored in it though?

for (i=0; i<flagsize; i++) {
if (flag & 2^i)
this.flagcounter++;
if (this.flagcounter == 2)
return true;
}
return false;
Reply With Quote
  #4  
Old 05-27-2006, 12:22 AM
Rick Rick is offline
PipBoy Extraordinaire!
Rick's Avatar
Join Date: Jul 2004
Location: Long Beach, California.
Posts: 831
Rick is on a distinguished road
First of all, Graal doesn't support above 32bits for numbers (I think).
Second, what I said was correct

if (flags & (0x100000001 | 0x10000))

[edit]

We had a discussion about this on IRC and we came to that I misunderstood your original question, mostly because your original question was not written very well.

Anyway, my point of view: you're using bitflags for the wrong reason.

But uhh, here's how I would do it:

PHP Code:
function getFlagCount(flags)
{
  
temp.count 0;
  while (
temp.flags 0)
  {
    
temp.count += temp.flags 1;
    
temp.flags >>= 1;
  }
  return 
temp.count;


Last edited by Rick; 05-27-2006 at 12:48 AM..
Reply With Quote
  #5  
Old 05-27-2006, 03:16 AM
jake13jake jake13jake is offline
Former Classic Staff
jake13jake's Avatar
Join Date: Dec 2002
Location: Northwest Vermont
Posts: 1,452
jake13jake will become famous soon enough
I'm using bit flags to conserve variable space actually.
Reply With Quote
  #6  
Old 05-27-2006, 08:00 PM
Admins Admins is offline
Graal Administration
Join Date: Jan 2000
Location: Admins
Posts: 11,693
Admins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud of
You need to loop through all bits you want to check, there is no countbits() function or so yet
Reply With Quote
  #7  
Old 05-28-2006, 04:49 AM
jake13jake jake13jake is offline
Former Classic Staff
jake13jake's Avatar
Join Date: Dec 2002
Location: Northwest Vermont
Posts: 1,452
jake13jake will become famous soon enough
ok
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 05:25 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.