Maximum Array Size? (SOLVED)

Started by Valentine, Mon 21/05/2007 14:29:52

Previous topic - Next topic

Valentine

I need to include Array information going up into the thousands (I know this sounds unlikely, but it really does have its use). At the moment, the game crashes past 994. Is there any way around this limit?

Khris

What exactly are you trying to achieve?
There might be ways, but it's a bit hard to tell if we haven't any idea what you're after.

Valentine

Sorry, I should have given more information, yeah.

Basically I need 3000 modifiable variables. They only need to be room based, not global. Each needs to be independent of anything other than itself.

Not sure what other information I need to give  :-\.

Arrays would really help with this. Can 994 be increased?

Ashen

#3
Where are you declaring the array(s), what exactly causes the error (e.g. is it on compile, or when you try to use the array), and what is the error message (if any)? I can compile a game fine with an array of 3000, and it seems like I can access the members OK, so I don't think there's actually a 994 limit.

I think there is/was a limit to how many variables you can declare - I think it's 4Kb worth  in a function, not sure about Global/Room scripts. Could you be bumping into that? If you delete some other variables, can the array get bigger?
EDIT: A 3000-strong (int) array declared in a function will cause a crash, elsewhere it seems OK.
I know what you're thinking ... Don't think that.

Gilbert

I think the problem was not related to that 994 you mentioned.
It's probably becauseof memory limitation.

Can you tell us how large is each entry?

For example, in my game, I have multiple arries of 1200 elements in both the Global and Room scripts and didn't have any problem. I used short for these entries though, that made them 2*1200 ~ 2+ kb for each array. Even if they're int, the size of each would be ~5kb, which should be of much problem either.
But if say the entries are complicated Struct of large size, it can eat up memory drastically (ESPECIALLY when you make it room-based, since these variables' states would also be saved in the savegames thus boosting their sizes).

Edit:Ashen beated me, but I'll still post.

Valentine

I'm declaring the arrays in the room, will I be able to access them normally in the Global Script? If so where do I declare them and how do I access them?

The problem occurs when I try to test the game. The error message is:

Error: run_text_script1: error-6 running function 'room_a':
Error: stack overflow, attempted grow to 10012 bytes in Room 1 script (line 9)

Line nine is where I have typed: int Health[3000];



Khris

#6
So you are declaring the array inside a function.

Try moving the "int Health[3000];" line outside any function to the top of the room script.

Since you kind of contradicted yourself, do you want to access the array from the global and the room script?
Do you need a 3000 array for each room?

@RickJ:
missing: export Health;

RickJ

Variables declared withing a function like that are only accesable from within the function.  Ass the error message implies, such variables aren created on the stack area when the function is called and lost when the function returns.  It sounds like wehat you really want are global variables. To do this you need to add a couple lines in the global script and script header files as follows:

Script Header
#define SIZE 3000
import int Health[SIZE];    // Check manual for exact syntax of the import statement

Global Script
int Health[SIZE];              // Placed outside the bounds of any function, usually at top of script

Room Script
function room_a() {
   int i;

   // Example initializes members of Health array to 100
   i = 0;
   while (i<SIZE) {
      Health = 100;
      i++;
   }
}

KhrisMUC replied while I was typing ;).  so there is  some redundancy.

Valentine

Aah.. I've moved it up before the function and it works fine now.  ::) Whoops

*slaps wrist* Bad newbie! *slaps*

Thanks for the help, I'd been racking my brain for ages trying to figure it out.

SMF spam blocked by CleanTalk