Raised This Month: $32 Target: $400
 8% 

Booleans outputs integers?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
fatal_nl
Member
Join Date: Apr 2017
Old 08-08-2018 , 21:20   Booleans outputs integers?
Reply With Quote #1

PHP Code:
new bool:g_bAdmin[33]

public 
client_authorized(id)
{
    
g_bAdmin[id] = bool:(get_user_flags(id) & ADMIN_LEVEL_G)
}

public 
some_function(id)
{
    
client_print(0print_chat"%i"g_bAdmin[id])

This wil give 262144 in chat. I thought booleans are supposed to give either true (1) or false (0).


Last edited by fatal_nl; 08-08-2018 at 21:21.
fatal_nl is offline
ddhoward
Veteran Member
Join Date: May 2012
Location: California
Old 08-09-2018 , 00:14   Re: Booleans outputs integers?
Reply With Quote #2

You're just retagging; you're not actually changing the value.

PHP Code:
new bool:g_bAdmin[33

public 
client_authorized(id

    
g_bAdmin[id] = !!(get_user_flags(id) & ADMIN_LEVEL_G


public 
some_function(id

    
client_print(0print_chat"%i"g_bAdmin[id]) 

Try this. This is how we'd do it in Sourcemod, so it should be the same here.
__________________
ddhoward is offline
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 08-09-2018 , 02:26   Re: Booleans outputs integers?
Reply With Quote #3

Operator & doesn't return a boolean value.
__________________
klippy is offline
ddhoward
Veteran Member
Join Date: May 2012
Location: California
Old 08-09-2018 , 02:46   Re: Booleans outputs integers?
Reply With Quote #4

Quote:
Originally Posted by KliPPy View Post
Operator & doesn't return a boolean value.
He tagged it as bool. He seems to have been under the impression that retagging actually changed the value within the cell.
__________________
ddhoward is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 08-09-2018 , 03:29   Re: Booleans outputs integers?
Reply With Quote #5

g_bAdmin[id] = boolget_user_flags(id) & ADMIN_LEVEL_G) ? true:false;

As klippy said operator & is not a comparison operator.
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !

Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
ddhoward
Veteran Member
Join Date: May 2012
Location: California
Old 08-09-2018 , 03:33   Re: Booleans outputs integers?
Reply With Quote #6

Quote:
Originally Posted by Natsheh View Post
g_bAdmin[id] = bool:(get_user_flags(id) & ADMIN_LEVEL_G) ? true:false;

As klippy said operator & is not a comparison operator.
Does !! not work in AMX Mod X? Also, why are you tagging as bool something that is already bool? If your ternary operator is already returning true or false... the tag isn't necessary?

PHP Code:
g_bAdmin[id] = !!(get_user_flags(id) & ADMIN_LEVEL_G); 
Is this not valid in Amx?
__________________

Last edited by ddhoward; 08-09-2018 at 03:37.
ddhoward is offline
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Stockholm, Sweden
Old 08-09-2018 , 03:44   Re: Booleans outputs integers?
Reply With Quote #7

Quote:
Originally Posted by ddhoward View Post
Does !! not work in AMX Mod X? Also, why are you tagging as bool something that is already bool? If your ternary operator is already returning true or false... the tag isn't necessary?

PHP Code:
g_bAdmin[id] = !!(get_user_flags(id) & ADMIN_LEVEL_G); 
Is this not valid in Amx?
It works.

Quote:
Originally Posted by fatal_nl View Post
PHP Code:
// ... 
This wil give 262144 in chat. I thought booleans are supposed to give either true (1) or false (0).

EVERYTHING in this language is a 32-bit cell or an array of it. Integers, booleans, floats, strings and pointers, it's just all the same. Tags are there so the compiler can point out possible mistakes.
__________________

Last edited by Black Rose; 08-09-2018 at 03:57.
Black Rose is offline
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 08-09-2018 , 05:03   Re: Booleans outputs integers?
Reply With Quote #8

Quote:
Originally Posted by ddhoward View Post
He tagged it as bool. He seems to have been under the impression that retagging actually changed the value within the cell.
Yeah, I just pointed out why OP's code didn't work as they expected it to. Your solution works.
__________________
klippy is offline
Reply


Thread Tools
Display Modes

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 -4. The time now is 22:11.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode