Author Topic: Getting the array count of a specific variable  (Read 901 times)

Is there a way to do this and if so, how?  I can't seem to figure out a way to do so.

Array count? You mean as in, how long it is?
You could try this:
for(%i=0; %blah[%i] !$= ""; %i++){}
//%i is now length


Note if one of the values is empty then it doesn't work.

I guess I didn't specify by count.

What I meant was the amount of arrays there are for a specific variable:

%blah[0]
%blah[1]
%blah[2]

%blahcount = codehere; //or whatever you would use here to get the amount

There is no way to do that. The code I posted above wouls get the length of 3 if all those blahs contain a value. A better way would be to have the code setting the array store the length too.

Just increment %blahcount each time you define a new %blah[].

Alright, I'll go ahead and try your code.
Thanks.
Just increment %blahcount each time you define a new %blah[].
Well I know that, but it's not as efficient as I would want it to be.

What do you use blah[] for? What is the code setting it and what is the code using it?

I'm revising my old announcements mod so it's more efficient and isn't cluttered.
I was thinking of just using files for the announcements but then I didn't want to deal with more files.

Then I thought of just having one big file for all of the announcements and that just seemed the way to go because then I could easily modify the file without having to open it and edit the code.

The arrays used to be in the same file that used them.
« Last Edit: March 16, 2014, 06:28:12 PM by tkepahama »

Then just make it increment the count for every line it reads?

Then just make it increment the count for every line it reads?
That is what I have done before and I know it's the best way for what I did. But that's not what I was looking for because what I was looking for could be done with variables that are stated in the same file that uses them and so forth in which is actually better imo.
« Last Edit: March 16, 2014, 07:02:36 PM by tkepahama »

How does the file look like?

Well I know that, but it's not as efficient as I would want it to be.
Basic addition and variable references are much more efficient than indefinite length loops and string comparisons.