AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Booleans outputs integers? (https://forums.alliedmods.net/showthread.php?t=309837)

fatal_nl 08-08-2018 21:20

Booleans outputs integers?
 
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).

http://i66.tinypic.com/63ygjl.png

ddhoward 08-09-2018 00:14

Re: Booleans outputs integers?
 
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.

klippy 08-09-2018 02:26

Re: Booleans outputs integers?
 
Operator & doesn't return a boolean value.

ddhoward 08-09-2018 02:46

Re: Booleans outputs integers?
 
Quote:

Originally Posted by KliPPy (Post 2609208)
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.

Natsheh 08-09-2018 03:29

Re: Booleans outputs integers?
 
g_bAdmin[id] = bool:(get_user_flags(id) & ADMIN_LEVEL_G) ? true:false;

As klippy said operator & is not a comparison operator.

ddhoward 08-09-2018 03:33

Re: Booleans outputs integers?
 
Quote:

Originally Posted by Natsheh (Post 2609218)
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?

Black Rose 08-09-2018 03:44

Re: Booleans outputs integers?
 
Quote:

Originally Posted by ddhoward (Post 2609219)
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 (Post 2609191)
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.

klippy 08-09-2018 05:03

Re: Booleans outputs integers?
 
Quote:

Originally Posted by ddhoward (Post 2609212)
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.


All times are GMT -4. The time now is 12:37.

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