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

Default value of data type (Array)


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
ilham92-cc-sakura
Senior Member
Join Date: Oct 2008
Location: /var/www/index.html
Old 09-11-2014 , 06:48   Default value of data type (Array)
Reply With Quote #1

in C#
Code:
bool[] Nope = new bool[8192];
it will initialized default "null" value, not false or true.

I wonder in SourcePawn if I wrote:
PHP Code:
new bool:Nope[8192];

...

if (
Nope[1] == false)
// valid or not? 
What default value SourceMod will initialized?
Second, what the maximum array can be use? because when player type "!nope" it will not execute some part of code, I plan:
PHP Code:
public Action:Nope(client,args)
{
    if (
Nope[client] == true)
       return 
Plugin_Continue;

__________________
ilham92-cc-sakura is offline
WildCard65
Veteran Member
Join Date: Aug 2013
Location: Canada
Old 09-11-2014 , 07:58   Re: Default value of data type (Array)
Reply With Quote #2

The new keyword initializes bools with false and with arrays, it fills that array with the default value of the type.
__________________
WildCard65 is offline
ilham92-cc-sakura
Senior Member
Join Date: Oct 2008
Location: /var/www/index.html
Old 09-11-2014 , 08:59   Re: Default value of data type (Array)
Reply With Quote #3

what maximum array can be put? if I use 1MiB (1048576)
Code:
new bool:Nope[1048576];
it is safe?
__________________
ilham92-cc-sakura is offline
WildCard65
Veteran Member
Join Date: Aug 2013
Location: Canada
Old 09-11-2014 , 09:29   Re: Default value of data type (Array)
Reply With Quote #4

Quote:
Originally Posted by ilham92-cc-sakura View Post
what maximum array can be put? if I use 1MiB (1048576)
Code:
new bool:Nope[1048576];
it is safe?
TBH I have no idea
__________________
WildCard65 is offline
GsiX
gee, six eggs
Join Date: Aug 2012
Location: Land Below The Wind
Old 09-11-2014 , 09:37   Re: Default value of data type (Array)
Reply With Quote #5

You can check them youself like:

PHP Code:
#include <sourcemod>

public OnPluginStart()
{
    
RegConsoleCmd"sm_test"Test );
}

public 
Action:Testclientargs )
{
    new 
bool:Nope[1048576];
    new 
Size sizeofNope );
    for( new 
i=0i<Sizei++ )
    {
        
PrintToChatAll"Value Pos: %d | %d"iNope[i] );
    }

For the max size, usually the compiler will tell ya..
__________________
If i happen to insulted you unintentionally,
it was me and Google Translate who did it.

Last edited by GsiX; 09-11-2014 at 09:38. Reason: GsiX loose on troll
GsiX is offline
Mitchell
~lick~
Join Date: Mar 2010
Old 09-11-2014 , 14:45   Re: Default value of data type (Array)
Reply With Quote #6

Default value is 0, which is "false" you can set the default value just by doing:
Code:
new bool:Nope[8192] = {true, ...};
Mitchell is offline
Reply



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 09:29.


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