Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: PERXEO on Mon 22/05/2023 15:06:00

Title: Parsing a code of N lines (SOLVED)
Post by: PERXEO on Mon 22/05/2023 15:06:00
Hi everyone! I've a snippet of code similar to this
PuzzleD.rows[0]=getRow(0);
    PuzzleD.columns[0]=getColumn(0);
    piece0.X=posxInitial+(PuzzleD.columns[0]*witdh);
    piece0.Y=posyInitial+(PuzzleD.rows[0]*height);

 PuzzleD.rows[1]=getRow(1);
    PuzzleD.columns[1]=getColumn(1);
    piece1.X=posxInitial+(PuzzleD.columns[1]*witdh);
    piece1.Y=posyInitial+(PuzzleD.rows[1]*height);

 PuzzleD.rows[2]=getRow(2);
    PuzzleD.columns[2]=getColumn(2);
    piece2.X=posxInitial+(PuzzleD.columns[2]*witdh);
    piece2.Y=posyInitial+(PuzzleD.rows[2]*height);
.........................................
 PuzzleD.rows[n]=getRow(n);
    PuzzleD.columns[n]=getColumn(n);
    piecen.X=posxInitial+(PuzzleD.columns[n]*witdh);
    piecen.Y=posyInitial+(PuzzleD.rows[n]*height)


I want to resume this in an unique loop like this

for(int i=0;i<=N;i++)
    {
        PuzzleD.rows[i]=getRow(i);
        PuzzleD.columns[i]=getColumn(i);
        "piece"+i.X=posxInitial+(PuzzleD.columns[i]*witdh);
       "piece"+i.Y=posyInitial+(PuzzleD.rows[i]*height);
}

but I don't know exactly how to do it. Piece1, piece2, piece3, .... pìeceN, are objects on a room, but I don`t have any idea how to parse it... thanks for your help!!!
Title: Re: Parsing a code of N lines
Post by: Crimson Wizard on Mon 22/05/2023 15:10:57
All Room Objects are stored in an array "object[]". If your "piece" objects have sequential order, then you could do "object[i + FIRST]", where FIRST is the index of a first "puzzle" object.

If they are not sequential, and it's too difficult to make them such for any reason, then you could create your own array and assign objects to it:

Code (ags) Select
Object* pieces[HOW_MANY];
pieces[0] = piece0;
pieces[1] = piece1;
etc
and then work with "pieces" array.
Title: Re: Parsing a code of N lines
Post by: PERXEO on Mon 22/05/2023 15:30:01
Thanks!!! I'm going to try it....