Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: spook1 on Fri 25/01/2008 10:25:09

Title: define an array dependent on a fixed value?
Post by: spook1 on Fri 25/01/2008 10:25:09
I am not sure if I am asking for dynamic array..

In my game I calculate currents between conenction points, using a matrix approach. Now I want to:

#define NUMCONNECTIONS 8

function MAX_WIRES(){
int i;
int maxwires_loc=1;
while (i<NUMCONNECTIONS ){
maxwires_loc = maxwires_loc + i;
return  maxwires_loc;
}
}


//NumCurrent = MAX_WIRES() - NUMCONNECTIONS + 1;

// Declare an array variable of type Connection

Connection Connections[MAX_WIRES()];
int                            current[NumCurrent];



This obviously does not work.

Is there a way to decalre arrays, depending on a defined value?
This way I can create a general roomscript, where I only need to change the number of connections to have all currents calculated. This is not really dynamic is it?

I am curious to read about any suggestions,

martijn
Title: Re: define an array dependent on a fixed value?
Post by: Khris on Fri 25/01/2008 10:47:36
In the current state, MAX_WIRES() returns 1 every time.

But to answer your question:
Either use a dynamic array or simply a very high initial dimension like 10000.
Storing an int eats a few bytes, so storing 10000 eats a few 10k. Most current PCs have at least 50.000 times more RAM than that.