tge-was-taken / Atlus-Script-Tools

A set of tools for working with scripts used in various game developed by Atlus.
GNU General Public License v3.0
65 stars 40 forks source link

Potential Fix for variable array indexing #54

Closed vim449 closed 1 year ago

vim449 commented 1 year ago

First off, thank you for all the work that you've provided for the modding scene around these games.

From what I understand, the flow file specification does not support arrays, so the way that arrays work in flowscript is that they get compiled to individual variables that represent an individual element. As a result of this, being able to simply access any index of an array with a variable does not work. However, by doing something like the following, it should be possible to support this anyways:

int array[] = {4, 5 , 6};

int index = 1;
int access = array[index]; //currently this is unsupported as outlined above

// however, by turning the array access into code like this
// each array element is it's own variable and we're still able to access the correct index of the array
array_element1 = 4;
array_element2 = 5;
array_element3 = 6;

int access;
if (index == 0) { access = array_element1; }
else if (index == 0) { access = array_element2;}
else if (index == 1) {  access = array_element3;}

Array lengths are fixed and known at compile time, so it should always be possible to convert any array access with variables into something that the compiled BF files actually allow for. I do not know C# nor have enough understanding of the codebase here to actually implement this feature, but I'm hoping that by outlining a potential fix, someone may implement this at some point such that arrays are actually usable for mod development.

ShrineFox commented 1 year ago

I think arrays are supposed to be supported if you initialize it with a size like so:

const int Personas[14] = { 363, 366, 368, 371, 190, 191, 192, 193, 194, 195, 196, 197, 198, 188 };

It is fixed length and values are required to be known at compile time, so it's still pretty much like a fancy shorthand for variables, but it's nice for code readability I suppose

vim449 commented 1 year ago

Sorry, I guess I didn't make it clear enough in my original post, arrays are supported, and you can use them for specific things, however, in nearly any case where you try to access an element of an array with a variable index, the compiler will return the error: return address corruption, and then the array access will behave very inconsistently. Here's a post I made in the Persona Modding discord that outlines exactly what cases cause this error: https://discord.com/channels/746211612981198989/1052660832330334308 In this post I did not initialize it with a size, but I tested all of the cases again with that, and am still getting the error, so even then they still do not function correctly.

tge-was-taken commented 1 year ago

Covered by fb798269fc96892aeaf9cab2b32d4b25ad1e2f63