1
Advanced Technical Forum / List of Struct Arrays - How to select array in code? [SOLVED]
« on: 22 Apr 2013, 11:32 »
I currently have a bunch of arrays declared as follows:
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:
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?
Code: Adventure Game Studio
- // 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: Adventure Game Studio
- // 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: Adventure Game Studio
- 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?









