Raised This Month: $ Target: $400
 0% 

String array Q =\


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
GanJa
Member
Join Date: Mar 2004
Location: Salem, OR
Old 07-04-2004 , 11:29   String array Q =\
Reply With Quote #1

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...
GanJa is offline
PM
hello, i am pm
Join Date: Jan 2004
Location: Canalization
Old 07-04-2004 , 12:59  
Reply With Quote #2

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?
__________________
hello, i am pm
PM is offline
Downtown1
Veteran Member
Join Date: Mar 2004
Old 07-04-2004 , 15:26  
Reply With Quote #3

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 .
Downtown1 is offline
PM
hello, i am pm
Join Date: Jan 2004
Location: Canalization
Old 07-04-2004 , 15:46  
Reply With Quote #4

huh
that should give you a runtime error if you leave the array uninitialized
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
__________________
hello, i am pm
PM is offline
GanJa
Member
Join Date: Mar 2004
Location: Salem, OR
Old 07-04-2004 , 17:46  
Reply With Quote #5

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 =\
GanJa is offline
AssKicR
Veteran Member
Join Date: Mar 2004
Location: Norway-Europe(GTM+1)
Old 07-04-2004 , 21:23   Re: String array Q =\
Reply With Quote #6

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) }
__________________
My Plugins

Got ??
AssKicR is offline
GanJa
Member
Join Date: Mar 2004
Location: Salem, OR
Old 07-05-2004 , 20:21  
Reply With Quote #7

Your talking about a single array, I'm talking about a double array.....
GanJa is offline
Johnny got his gun
Veteran Member
Join Date: Jan 2004
Location: Tokyo
Old 07-06-2004 , 18:05  
Reply With Quote #8

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.
Johnny got his gun is offline
GanJa
Member
Join Date: Mar 2004
Location: Salem, OR
Old 07-06-2004 , 18:40  
Reply With Quote #9

well I would settle for 3 seeded array myself =) would kill about 40+ vars in my newest plugin....
GanJa is offline
AssKicR
Veteran Member
Join Date: Mar 2004
Location: Norway-Europe(GTM+1)
Old 07-06-2004 , 21:57  
Reply With Quote #10

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
__________________
My Plugins

Got ??
AssKicR 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 14:47.


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