How to do with one variable
Hey there.
So in my ZP there are many different classes and I don't like using different variable names like g_nem, g_assa, g_sni, g_surv, etc. I wonder how can I achieve the same thing by using one varible and bitwise operator like -- g_iPlayerType[ iPlayer ] & P_SNIPER g_iPlayerType[ iPlayer ] & P_NEMESIS Like that I have seen one plugin use it but I can't understand. Can anyone tell me how to do as above ? |
Re: How to do with one variable
Code:
Code:
|
Re: How to do with one variable
Quote:
I want to use like Code:
How to do it ? |
Re: How to do with one variable
Take a look at a programmer/scripter's very good friend.
|
Re: How to do with one variable
Quote:
Can you give me any other example please ? |
Re: How to do with one variable
Why do you want to use bitwise operators when the variables are not mutually connected? Can a player be a nemesis and survivor at the same time? Probably not.
|
Re: How to do with one variable
Quote:
I want when nemesis set it like g_iPlayerType[ id ] |= P_NEMESIS When survivor g_iPlayerType[ id ] |= P_SURVIVOR and so on. Do you get it now ? If yes, can you show me how to do it ? Because I have an sma which uses same kind of var as I mentioned above but I can't understand and also Bugsy showed the same in his bit-field tutorial. I just want someone who can explain me how to set and check back. |
Re: How to do with one variable
The thing you showed isn't really a good example because you only need 1 variable and with enums you're accomplishing the thing you're asking for. Bitwise is not a good choice here, but the method is still the same - you won't have any more or less variables than with what I've shown.
|
Re: How to do with one variable
PHP Code:
|
Re: How to do with one variable
Just because you prefer something doesn't make it good code. We try to give you the best advice to help you learn which won't always be what you "prefer". If the states are mutually exclusive (meaning that you can't be more than one thing at a time) then you should use the method provided in post #2.
The example provided in post #9 shows a case where the states are not mutually exclusive which is a valid use case of bitwise operations. |
| All times are GMT -4. The time now is 14:08. |
Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.