List of Struct Arrays - How to select array in code? [SOLVED]

Started by WHAM, Mon 22/04/2013 11:32:17

Previous topic - Next topic

WHAM

I currently have a bunch of arrays declared as follows:

Code: AGS

// Header
struct StoryBlocks {
  String Speaker1;
  String Speaker2;
  String Speaker3;
  int Speaker1mood;
  int Speaker2mood;
  int Speaker3mood;
  String Line;
};

import function InitStoryBlocks();
import StoryBlocks SB_01[1000];
import StoryBlocks SB_02[1000];
import StoryBlocks SB_03[1000];
import StoryBlocks SB_04[1000];
import StoryBlocks SB_05[1000];


Code: AGS

// Script
StoryBlocks SB_01[1000];StoryBlocks SB_02[1000];StoryBlocks SB_03[1000];StoryBlocks SB_04[1000];StoryBlocks SB_05[1000];
export SB_01;export SB_02;export SB_03;export SB_04;export SB_05;


Now I want a piece of code to use a pair of global variables to first select the array we are using, then select the row from that array.
That's where I hit a wall just now. Being a bit simple I first thought I'd do something, well, simple:

Code: AGS

String GetCurrentBlock() {
  // Returns the name of the target array as String
  if (gCurrentBlock == 1) {return "SB_01";}
  if (gCurrentBlock == 2) {return "SB_02";}
  if (gCurrentBlock == 3) {return "SB_03";}
  if (gCurrentBlock == 4) {return "SB_04";}
  if (gCurrentBlock == 5) {return "SB_05";}
}

String GetTextLine() {
  // Uses the array name and global variable "gCurrentLine" to return a line of text from array
  // The nextrow is stupid and should be regarded as pseudocode
  return GetCurrentBlock()[gCurrentLine].Line; // <- What to replace this with
}

function DisplayNextLine() {
  // Displays returned text in a GUI label "labTXT"
  labTXT.Text = String.Format("%s", GetTextLine());
  gCurrentLine++;
} export DisplayNextLine;


So, as far as I know, I cannot currently create an array of arrays within which to nest these existing arrays of structs, so that leaves me a bit confused.
Suggestions, ladies and gentlemen?
Wrongthinker and anticitizen one. Utterly untrustworthy. Pending removal to memory hole.

RickJ

You can make a 2D array by doing something like the following:

Code: AGS

struct StoryBlocks {
  String Speaker1[1000];
  String Speaker2[1000];
  String Speaker3[1000];
  int Speaker1mood[1000];
  int Speaker2mood[1000];
  int Speaker3mood[1000];
  String Line[1000];
};

StoryBlocks SB[6];

Display(SB[2].Line[23]);


WHAM

Oh, well that seems much more simple than what I had in mind...
Thanks! :D
Wrongthinker and anticitizen one. Utterly untrustworthy. Pending removal to memory hole.

SMF spam blocked by CleanTalk