Raised This Month: $12 Target: $400
 3% 

Booleans and Enums [SOLVED]


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
11530
Veteran Member
Join Date: Sep 2011
Location: Underworld
Old 04-06-2012 , 22:17   Booleans and Enums [SOLVED]
Reply With Quote #1

Note: Turns out this problem is an enum bug in the language. This newer post of mine explains it better:
http://forums.alliedmods.net/showthread.php?t=182348

--------------------------------------------------------------------------------------------------------

I'm currently experiencing errors with the following pieces of code in my plugin:
Code:
enum _:PlayerData
{
    bool:bForced = true
}

new g_Players[MAXPLAYERS + 1][PlayerData];

...

PrintToChat(client, "%d", g_Players[client][bForced]);
And the output of this is 8. Is this just another enum bug (of which there are plenty) or is it just that I can't use %d for a bool (to get something akin to 1 or 0)?

Last edited by 11530; 04-09-2012 at 00:35.
11530 is offline
minimoney1
SourceMod Donor
Join Date: Dec 2010
Old 04-06-2012 , 22:31   Re: Booleans and Enums
Reply With Quote #2

Quote:
Originally Posted by 11530 View Post
I'm currently experiencing errors with the following pieces of code in my plugin:

Code:
enum _:PlayerData
{
    bool:bForced = true
}

new g_Players[MAXPLAYERS + 1][PlayerData];

...

PrintToChat(client, "%d", g_Players[client][bForced]);
And the output of this is 8. Is this just another enum bug (of which there are plenty) or is it just that I can't use %d for a bool (to get something akin to 1 or 0)?
I think you got it wrong.
Here's my version and it tests to be working.
PHP Code:
enum PlayerData
{
    
bool:bForced true
}

new 
g_Players[MAXPLAYERS 1][PlayerData];

public 
OnPluginStart()
{
    
RegConsoleCmd("sm_testing"Command_Testing);
    
g_Players[0][true] = 1337;
}

public 
Action:Command_Testing(clientargs)
{
    
PrintToServer("%d"g_Players[client][PlayerData:bForced]);

minimoney1 is offline
11530
Veteran Member
Join Date: Sep 2011
Location: Underworld
Old 04-06-2012 , 22:40   Re: Booleans and Enums
Reply With Quote #3

Quote:
g_Players[0][true] = 1337;
Are you sure you put [true]?
What was the output?
11530 is offline
minimoney1
SourceMod Donor
Join Date: Dec 2010
Old 04-06-2012 , 22:42   Re: Booleans and Enums
Reply With Quote #4

I copied and pasted my source.
It works, notice these changes:
enum PlayerData
instead of
enum _:PlayerData
and
g_Players[client][PlayerData:bForced]
instead of
g_Players[client][bForced]

Second one is the source of your issue I believe.

EDIT: Forgot to mention, but by "it tests to be working" I meant that the outcome is, indeed, 1337.

Last edited by minimoney1; 04-06-2012 at 22:45.
minimoney1 is offline
11530
Veteran Member
Join Date: Sep 2011
Location: Underworld
Old 04-06-2012 , 22:51   Re: Booleans and Enums
Reply With Quote #5

I have to use _:PlayerData due to another enum bug here: http://forums.alliedmods.net/showthread.php?t=180813

I guess I just must have assigned the boolean to 8 somewhere. Gonna have to sort through 400 lines! :3 Thank you for your help!

Last edited by 11530; 04-09-2012 at 00:36.
11530 is offline
minimoney1
SourceMod Donor
Join Date: Dec 2010
Old 04-06-2012 , 22:53   Re: Booleans and Enums
Reply With Quote #6

Code:
g_Players[client][PlayerData:bForced]
instead of 
g_Players[client][bForced]
try that.
Don't know if it will or will not work because of the above issue, but worth a try.

Last edited by minimoney1; 04-06-2012 at 22:54.
minimoney1 is offline
11530
Veteran Member
Join Date: Sep 2011
Location: Underworld
Old 04-06-2012 , 23:09   Re: Booleans and Enums
Reply With Quote #7

If yours returned 1337, then my returning 8 shouldn't be a problem (even though I'm pretty sure I'm only using =true and =false). I just must be assigning a number somewhere mistakenly.

Thanks for your help anyway.


Edit: It turns out this is in fact a bug with enums. See this newer post of mine for more info:
http://forums.alliedmods.net/showthread.php?t=182348

Last edited by 11530; 04-09-2012 at 00:38.
11530 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 10:39.


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