AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   Global array (https://forums.alliedmods.net/showthread.php?t=198693)

ShufflexDD 10-19-2012 13:04

Global array
 
I have to use this code:
Code:

new String:players[SQL_GetRowCount(query)];
as you can see, I set length of array by count of rows in sql.
This code in OnPluginStart, but I need a global array(I can't set it in global area 'cause I don't know how many rows in sql).
Although I can declare an array in global area with fixed length of array, but it's bad.
So how to figure it out?

11530 10-19-2012 13:10

Re: Global array
 
If you want to make it global, set the String size to some maximum you know you won't exceed.

E.g. If the string holds a player's name, set the maximum length to MAX_NAME_LENGTH.

ShufflexDD 10-19-2012 13:21

Re: Global array
 
it's an array of strings.
I just hoped there is exist another way & better way to do it.
Also I'll be able to use while if it's possible.

11530 10-19-2012 13:28

Re: Global array
 
For a global array of strings use a 2-dimensional array. For example, for an array of players' names use:

new String:g_szPlayersNames[MAXPLAYERS+1][MAX_NAME_LENGTH];

ShufflexDD 10-19-2012 13:36

Re: Global array
 
In array I store steamid's of vip players. I do not need to use 2D arrays.
but thx for helping :)

11530 10-19-2012 13:46

Re: Global array
 
Quote:

Originally Posted by ShufflexDD (Post 1821739)
it's an array of strings.

Quote:

Originally Posted by ShufflexDD (Post 1821749)
I do not need to use 2D arrays.

That's a contradiction. An array of strings is a 2D array (since a string is considered an array itself). Anyway, use a maximum size of 21 for a SteamID.

ShufflexDD 10-19-2012 14:06

Re: Global array
 
may be I'm wrong, I just want to store e.g. 2 steamid's in array
Code:

players[1] = "STEAM_0:0:1";
players[2] = "STEAM_0:0:2";

I know that strings is already array of letters, so I have to make 'em 2D?

ShufflexDD 10-19-2012 14:08

Re: Global array
 
yep, you're right, thx

stupid pawn :)

berni 10-19-2012 16:11

Re: Global array
 
Quote:

Originally Posted by ShufflexDD (Post 1821770)
stupid pawn :)

pawn can't be stupid, only the coder. I'm happy that that Pawn isn't that ressource hungry like some other languages.

ShufflexDD 10-20-2012 05:31

Re: Global array
 
Quote:

Originally Posted by berni (Post 1821832)
pawn can't be stupid, only the coder. I'm happy that that Pawn isn't that ressource hungry like some other languages.

pawn is bad language(in contrast to the others), strings are array, every array I need to define it's size.(it's not all :))
one advantage it is small(probably 'cause of this it is used by sourcemod)


All times are GMT -4. The time now is 11:41.

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