• Welcome to Valhalla Legends Archive.
 

Why isn't this working?

Started by OuTLawZGoSu, January 28, 2004, 04:09 PM

Previous topic - Next topic

OuTLawZGoSu

 

Case ID_JOIN

If FLAGS = 0 Then
Form1.ChannelList.ListItems.add 1, , username, , GetIcon
ElseIf FLAGS = 2 Then
Form1.ChannelList.ListItems.add 1, , username, , ICON_GAVEL
ElseIf FLAGS = 20 Then
Form1.ChannelList.ListItems.add 1, , username, , ICON_SQUELCH
End If


Can you tell me why this isnt working?

FLAGS = 0 works fine. It gets all the user's icons. Only game icons, not squelch or gravel.

The rest dont do anything. Am I doing something wrong?

ObsidianWolf

Have you checked your ImageList to see that the Appropriate Keys Have been set for those Icons?

warz

#2
I'd suggest Switch (FLAGS) { } also

Kp

Quote from: OuTLawZGoSu on January 28, 2004, 04:09 PMCan you tell me why this isnt working?

Yes.

Quote from: OuTLawZGoSu on January 28, 2004, 04:09 PMThe rest dont do anything. Am I doing something wrong?

Yes.

Thus spake the Oracle.
[19:20:23] (BotNet) <[vL]Kp> Any idiot can make a bot with CSB, and many do!

Zakath

I'm going to do something I don't normally do and just drop some code on you, because you've completely missed a critical aspect of the flags bitmask. Hopefully you'll learn something from this.


void CheckFlags( DWORD dwFlags, int *lpnStatImg, int *lpnLagImg ) {
   if ( dwFlags & 0x10 )
      *lpnLagImg = ICON_PLUG;
   if ( dwFlags & 0x20 )
      *lpnStatImg = ICON_SQUELCH;
   if ( dwFlags & 0x04 )
      *lpnStatImg = ICON_MEGAPHONE;
   if ( dwFlags & 0x02 )
      *lpnStatImg = ICON_GAVEL;
   if ( dwFlags & 0x08 )
      *lpnStatImg = ICON_BNET;
   if ( dwFlags & 0x01 )
      *lpnStatImg = ICON_BLIZZARD;
}


There are three key concepts in that function that you've missed. See if you can figure out what they are.
Quote from: iago on February 02, 2005, 03:07 PM
Yes, you can't have everybody...contributing to the main source repository.  That would be stupid and create chaos.

Opensource projects...would be dumb.

OuTLawZGoSu

I got no idea what that does. I dont know C++ :/

hismajesty

QuoteFLAGS = 0 works fine. It gets all the user's icons. Only game icons, not squelch or gravel.

gravel eh? Is that a new flag? :P

QuoteI got no idea what that does. I dont know C++ :/
My C++ knowledge is limited but it's not too hard to figure out what that means.

R.a.B.B.i.T

Switch(Value){} is the same as Select Case Value:Case Value:EndSelect.

MyndFyre

You'd better raise my karma for this one.

The following code:

Case ID_JOIN

If FLAGS = 0 Then
Form1.ChannelList.ListItems.add 1, , username, , GetIcon
ElseIf FLAGS = 2 Then
Form1.ChannelList.ListItems.add 1, , username, , ICON_GAVEL
ElseIf FLAGS = 20 Then
Form1.ChannelList.ListItems.add 1, , username, , ICON_SQUELCH
End If

determines if the flags value equals EXACTLY the value that you're looking for.  

I can see two things that you are doing wrong.

First, part of the entire point of using flags is to allow for several boolean values within a single numeric value.  Because data is stored ultimately in bits, a 1 can represent a true value, and a 0 a false value.

So, if you wanted a user to have the regular icon, no special icon flags are set.  Hence, the flags value is 0.

An example 8-bit number like the ones that are used in this case might be 01001010b = 0x4A (hex), or in Visual Basic, &H4A, the decimal equivalent being 74.

On Battle.net, it is possible (for example) for a squelched user to have the gavel.  Thus, you need to be able to check each individual BIT for its truth value.

Zakath posted some C-style code that lets you do this.  In your case, perhaps try modifying your code to utilize the bitwise operators AND and OR.


Case ID_JOIN

If FLAGS = 0 Then
 Form1.ChannelList.ListItems.add 1, , username, , GetIcon
Else
 If FLAGS And &H2 = &H2 Then
Form1.ChannelList.ListItems.add 1, , username, , ICON_GAVEL
 ElseIf FLAGS And &H20 = &H20 Then
Form1.ChannelList.ListItems.add 1, , username, , ICON_SQUELCH
 End If
End If


These code modifications do two things....

First, it completely removes conditional checking of the second case (special icons) if the first (standard game icon) turns out being the case.

Second, it changes your flags tests to ensure that 1.) you are using HEX values and not DECIMAL values (checking for decimal 20 would never work, because it's the bitwise combination of 16 and 4 -- you'd get megaphone if that was in there), and 2.) that you are actually doing BITWISE FLAGS tests and not direct numeric comparisons.

Make sure to have them in the correct order; I believe a squelched gavel holder has the squelched icon.

Cheers
--Rob
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

o.OV

#9
Quote from: Myndfyre on January 28, 2004, 06:09 PM
You'd better raise my karma for this one.

The following code:

Case ID_JOIN

If FLAGS = 0 Then
Form1.ChannelList.ListItems.add 1, , username, , GetIcon
ElseIf FLAGS = 2 Then
Form1.ChannelList.ListItems.add 1, , username, , ICON_GAVEL
ElseIf FLAGS = 20 Then
Form1.ChannelList.ListItems.add 1, , username, , ICON_SQUELCH
End If

determines if the flags value equals EXACTLY the value that you're looking for.  

I can see two things that you are doing wrong.

First, part of the entire point of using flags is to allow for several boolean values within a single numeric value.  Because data is stored ultimately in bits, a 1 can represent a true value, and a 0 a false value.

So, if you wanted a user to have the regular icon, no special icon flags are set.  Hence, the flags value is 0.

An example 8-bit number like the ones that are used in this case might be 01001010b = 0x4A (hex), or in Visual Basic, &H4A, the decimal equivalent being 74.

On Battle.net, it is possible (for example) for a squelched user to have the gavel.  Thus, you need to be able to check each individual BIT for its truth value.

Zakath posted some C-style code that lets you do this.  In your case, perhaps try modifying your code to utilize the bitwise operators AND and OR.


Case ID_JOIN

If FLAGS = 0 Then
 Form1.ChannelList.ListItems.add 1, , username, , GetIcon
Else
 If FLAGS And &H2 = &H2 Then
Form1.ChannelList.ListItems.add 1, , username, , ICON_GAVEL
 ElseIf FLAGS And &H20 = &H20 Then
Form1.ChannelList.ListItems.add 1, , username, , ICON_SQUELCH
 End If
End If


These code modifications do two things....

First, it completely removes conditional checking of the second case (special icons) if the first (standard game icon) turns out being the case.

Second, it changes your flags tests to ensure that 1.) you are using HEX values and not DECIMAL values (checking for decimal 20 would never work, because it's the bitwise combination of 16 and 4 -- you'd get megaphone if that was in there), and 2.) that you are actually doing BITWISE FLAGS tests and not direct numeric comparisons.

Make sure to have them in the correct order; I believe a squelched gavel holder has the squelched icon.

Cheers
--Rob

Here is another modification..


Case ID_JOIN

If FLAGS = 0 Then
 Form1.ChannelList.ListItems.add 1, , username, , GetIcon
Else
 If (FLAGS And &H2) = &H2 Then
Form1.ChannelList.ListItems.add 1, , username, , ICON_GAVEL
 ElseIf (FLAGS And &H20) = &H20 Then
Form1.ChannelList.ListItems.add 1, , username, , ICON_SQUELCH
 End If
End If


If you plan on a moderation bot with a feature to unignore safelisted users you will have to setup another check to detect for a squelched ops..
Assuming you will use this example in other cases.
If the facts don't fit the theory, change the facts. - Albert Einstein

DarkMinion

Never ever ever check a bitmask with =

o.OV

#11
Quote from: DarkMinion on January 29, 2004, 08:08 AM
Never ever ever check a bitmask with =

Well I only did a minor fix on it.. and I'm not even sure exactly what you mean by that.. lol

I could do the fix like this..


If (flags And &H2) = &H2 Then
   Form1.ChannelList.ListItems.Add 1, , Username, , ICON_GAVEL
ElseIf (flags And &H20) = &H20 Then
   Form1.ChannelList.ListItems.Add 1, , Username, , ICON_SQUELCH
Else
   Form1.ChannelList.ListItems.Add 1, , Username, , GetIcon
End If
If the facts don't fit the theory, change the facts. - Albert Einstein

Networks

did u make columns in the list box? so that the icons go where they're supposed to.

UserLoser.

#13
Quote from: Networks on January 29, 2004, 01:27 PM
did u make columns in the list box? so that the icons go where they're supposed to.

Subclassing, or you can just use a ListView if you want columns and icons (which is a lot easier)

MyndFyre

#14
Quote from: DarkMinion on January 29, 2004, 08:08 AM
Never ever ever check a bitmask with =

Well thanks, I'm not a VB programmer, I do C/Java/C#, so I wouldn't know.  It was intended more to point him in the right direction.  :)  When I check bitmasks in C#, I go:


if ( (flags & (int)UserFlags.Squelched) == UserFlags.Squelched)
 // assign squelched icon
else if ( (flags & (int)UserFlags.Moderator) == UserFlags.Moderator)
 // give it the gavel.

etc.
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.