For structure?

Started by adam100, Sat 26/11/2005 13:04:33

Previous topic - Next topic

adam100

Hmm, is there a for structure in AGS code language? Well it doesn't seem to be. And can I create multi dimensional arrays? Well, seems that I cant too but want to make sure.

Phemar

As far as I know there is no 'for' statements in AGS, but I think it is possible to create 3d arrays.

Check here:

http://www.adventuregamestudio.co.uk/yabb/index.php?topic=13897.0
http://www.adventuregamestudio.co.uk/yabb/index.php?topic=13842.0

monkey0506

You can't actually have multidimensional arrays in AGS, but you can create a single dimension array with a large index, and then use the general formula:

((((a_index * a_max + 1 + b_index) * b_max + 1 + ... (n - 1)_index) * (n - 1)_max + 1 + n_index))

Where a would be the first dimension, b the second, c the third, and n the final dimension (n - 1 being the dimension before the last).

a_index would be the index in the ath dimension, a_max would be the greatest possible index of the ath dimension, etc.

You can emulate a for statement with a while loop.  So:

for (int i = 0; i <= 5; i++) {
  /* do something */
  }

Would become:

int i = 0;
while (i <= 5) {
  /* do something */
  i++;
  }

It's a bit more cumbersome, but it does the same thing.


adam100

Well, I don't need multi-dimensional arrays so much anyway. They are very useful for storing maps though. And yeah, I'm not new to C++ and I know that it can be replace with while but as it is quite inconvienient for an experienced programmer-I practically never use the WHILE function, for is a second-nature you might say so it really is peculiar that it wasn't included in the script language so far. Hope it will change soon enough. ;)

Gilbert


monkey0506

Did there used to be? :o

Why were they removed? :'(

Gilbert

Well, from changes.txt:
QuoteVERSION 2.2, May 2001
- Completely re-written text script compiler and interpreter. Let me know
   if you have any problems with scripts that worked before.

Before that AGS used a third party script interpreter (SeeR), which included the 'for' statement, but since there're several limitations with SeeR CJ wrote his own script interpreter later, which (because of his laziness) did not include 'for' (which is one of the main reasons the old version of my day-night demo won't work anymore), but I have been comfortable with 'while' already now, so I'm not sure if it's still worth making 'for' available (IMO, implementating 'switch' is much more useful than 'for' loops).

SSH

You can have 2D arrays of ints and 3D arrays of chars (kinda) in AGS:

struct 2d_type {
  int y [100];
}

2d_type x[100];

x[23].y[56]=1;

AND:

struct 3d_type {
  String s [100];
}

3d_type a[100];

a[4].s[67]="ABCDEFG";
if (a[4].s[67].Chars[3]==64) //....


12

SMF spam blocked by CleanTalk