AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   [Ask] String[] ? (https://forums.alliedmods.net/showthread.php?t=236658)

dias 03-09-2014 00:46

[Ask] String[] ?
 
A:
PHP Code:

new StringA[64// 64 

and

B:
PHP Code:

new StringB[] // 255 

So if i use B, it'll take more memory right ?
Correct me if i am wrong :)

fysiks 03-09-2014 00:51

Re: [Ask] String[] ?
 
I honestly don't know what the default dimension is for arrays when not properly indexed when created but I highly recommend that you ALWAYS define the size of the array explicitly.

dias 03-09-2014 01:04

Re: [Ask] String[] ?
 
So A is better

fysiks 03-09-2014 01:16

Re: [Ask] String[] ?
 
Quote:

Originally Posted by dias (Post 2109499)
So A is better

I wouldn't say it that way. I would say that A is the ONLY option.

Shooting King 03-09-2014 03:37

Re: [Ask] String[] ?
 
X-Y Problem.

Black Rose 03-09-2014 10:35

Re: [Ask] String[] ?
 
Quote:

Originally Posted by dias (Post 2109494)
A:
PHP Code:

new StringA[64// 64 

and

B:
PHP Code:

new StringB[] // 255 

So if i use B, it'll take more memory right ?
Correct me if i am wrong :)

B won't even compile. Problem solved.
Code:

error 009: invalid array size (negative or zero)
error 036: empty statement


fysiks 03-09-2014 16:53

Re: [Ask] String[] ?
 
Quote:

Originally Posted by Black Rose (Post 2109619)
B won't even compile. Problem solved.
Code:

error 009: invalid array size (negative or zero)
error 036: empty statement


It seems to compile fine if you don't use the variable (which is what I tested originally) but when you actually use it, you'll get that error.

Black Rose 03-09-2014 16:59

Re: [Ask] String[] ?
 
Quote:

Originally Posted by fysiks (Post 2109807)
It seems to compile fine if you don't use the variable (which is what I tested originally) but when you actually use it, you'll get that error.

If used globally, yes. If declared inside a function it will throw an error immediately.

^SmileY 03-10-2014 13:57

Re: [Ask] String[] ?
 
decl String:szName[] = "SmileY";

>> Create a String with char size
For sourcemod, for amxmodx do not have decl ??

EDIT:

new szName[] = "SmileY";

worked, but i do not know if it is a correct way, i think was created with a maximum lenght of 7 chars

Black Rose 03-10-2014 14:15

Re: [Ask] String[] ?
 
Quote:

Originally Posted by ^SmileY (Post 2110098)
decl String:szName[] = "SmileY";

>> Create a String with char size
For sourcemod, for amxmodx do not have decl ??

EDIT:

new szName[] = "SmileY";

worked, but i do not know if it is a correct way, i think was created with a maximum lenght of 7 chars

Easy way to find out:
server_print("Size of szName: %d", sizeof szName);
But yes, 6 chars + 1 null.


All times are GMT -4. The time now is 05:58.

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