On top of my local script I have the following struct:
Spoiler
struct PaletteCycle
{
String system;
String game;
String Year;
int palette0r;
int palette0g;
int palette0b;
int palette1r;
int palette1g;
int palette1b;
int palette2r;
int palette2g;
int palette2b;
int palette3r;
int palette3g;
int palette3b;
bool UsedForCycle;
};
PaletteCycle palettecycles[60];
The room_AfterFadeIn first calls a function declaring the arrays (from 0 to 59), followed by calling the select_random_palette function (which randomly selects one of the 60 not yet selected palette, updates this palette, waits x time, and rerun the function until all 60 palettes has been chosen.
if a palette has been selected, the bool UsedForCycle is set to true and the function is called again.
Here's the looping select_random_palette function:
Spoiler
function select_random_palette()
{
if (ranPaletteTotal < 60)
{
ranPalette=Random(59);
if (palettecycles[ranPalette].UsedForCycle == true)
{
select_random_palette();
}
else if (palettecycles[ranPalette].UsedForCycle == false)
{
ranPaletteTotal++;
palettecycles[ranPalette].UsedForCycle = true;
Lamountpalettes.Text = String.Format("palettes shown: %d", ranPaletteTotal);
palette[0].r = palettecycles[ranPalette].palette0r;
palette[0].g = palettecycles[ranPalette].palette0g;
palette[0].b = palettecycles[ranPalette].palette0b;
palette[1].r = palettecycles[ranPalette].palette1r;
palette[1].g = palettecycles[ranPalette].palette1g;
palette[1].b = palettecycles[ranPalette].palette1b;
palette[2].r = palettecycles[ranPalette].palette2r;
palette[2].g = palettecycles[ranPalette].palette2g;
palette[2].b = palettecycles[ranPalette].palette2b;
palette[3].r = palettecycles[ranPalette].palette3r;
palette[3].g = palettecycles[ranPalette].palette3g;
palette[3].b = palettecycles[ranPalette].palette3b;
UpdatePalette();
Wait (10);//waittimecycle
select_random_palette();
}
}
else if (ranPaletteTotal == 60)
{
SetTimer (1, 300);
SetTimer (2, 60);
return;
}
}
The select_random_palette function works fine until for some reason it gets a '
call stack overflow' error, usually somewhere between the 30th and 40th palette update (out of the 60 palettes)...
When it happens, the line highlighted in the editor is one of the two "select_random_palette();" lines in the select_random_palette function
The full error msg:
Error running function 'room_AfterFadeIn':
Error: call stack overflow, recursive call problem?I can't seem to figure out why this is happening, any idea anyone?