AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   String array Q =\ (https://forums.alliedmods.net/showthread.php?t=3354)

GanJa 07-04-2004 11:29

String array Q =\
 
I wanna pass something like this....
Code:
new var[32], var2[SOME_AMMOUNT][32] some_function(var,var2)
Where the stock for "some_function" looks like this:
Code:
stock some_function(&thevar[],&thevar2[][]){ }
now the prob I have is I wanna know how much "SOME_AMMOUNT" is once I get into the function...

PM 07-04-2004 12:59

It should be possible, but you would need a native for it..
Can't you just pass the size to the function as an extra parameter? :)

Downtown1 07-04-2004 15:26

Adhering to the law that Small makes all the elements a 0 by default, here is how it will probably be done (although I'd recommend passing the parameter):

Code:
for (new i = 0; true; i++) {      if (var2[i][0] == 0)           break } //i will be the # of elements in the arrray

The problem with doing it this way is that the first dimension must be filled sequentially, i.e. var2[0][] must have a string (i.e. initialized to SOMETHING), var2[1][] must have a string .. etc , if var2[1][] does not have a string, but var2[2][] does, then this code will only go until it reaches an element without a string :).

PM 07-04-2004 15:46

huh
that should give you a runtime error if you leave the array uninitialized :D
also, if you write
Code:
new arr xD[8][] = { "aa", "bb", "cc", "", "ff", "ee", ... }
your code would return 3 elements if I haven't drunk too much :D

GanJa 07-04-2004 17:46

meh amx needs some easy functions like this one I hate passing like 6 diff things to a function just to get what I want =(
Although Thx I was way to tired to think of pasing the length =\

AssKicR 07-04-2004 21:23

Re: String array Q =\
 
Quote:

Originally Posted by GanJa
I wanna pass something like this....
Code:
new var[32], var2[SOME_AMMOUNT][32] some_function(var,var2)
Where the stock for "some_function" looks like this:
Code:
stock some_function(&thevar[],&thevar2[][]){ }
now the prob I have is I wanna know how much "SOME_AMMOUNT" is once I get into the function...

Do this

Code:
new var[32], var2[SOME_AMMOUNT] some_function(var,var2) stock some_function(thevar[],thevar2[]){ new thevarsize=strlen(thevar) new thevar2size=strlen(thevar2) }

GanJa 07-05-2004 20:21

Your talking about a single array, I'm talking about a double array.....

Johnny got his gun 07-06-2004 18:05

If the array/string is empty, the "size" would be 0. Size is not necessarily the same as length.

In my CS Metamap plugin ( http://forums.alliedmods.net/showthread.php?t=339 ) I have a function that looks like this:

Code:
createlevel(id, walls, matrix[], const COLUMNS, const LINES, Float:realMapWidth, Float:realMapDepth) {     new const Float:mapWidth = realMapWidth     new const Float:mapDepth = realMapDepth /***/ }

Matrix is a 2 dimensional array fitted inside a 1 dimensional array, and the size could vary but must of course anyway be known at compiletime, and this is done in the constants COLUMNS and LINES, so these have to be passed just as was discussed here.
To access the matrix I use another set of functions for ease of use...
Code:
readmatrix(matrix[], col, lin, const COLUMNS) {     return matrix[lin * COLUMNS + col] } writematrix(matrix[], col, lin, const COLUMNS, newvalue) {     matrix[lin * COLUMNS + col] = newvalue }

If I remember right I think multidimensionals are supported in newer Small versions... Which would make working with matrixes a lot more easy.

GanJa 07-06-2004 18:40

well I would settle for 3 seeded array myself =) would kill about 40+ vars in my newest plugin....

AssKicR 07-06-2004 21:57

Quote:

Originally Posted by GanJa
well I would settle for 3 seeded array myself =) would kill about 40+ vars in my newest plugin....

about 130 in mine


All times are GMT -4. The time now is 14:47.

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