Sorry for the confusing title, not sure what to have it as. I am hoping to have the following looked at to see if there is a better way to do this.
My main concern at the moment is the more data (in the example below, weapons) I add to the .JSON file the longer it will take to loop/repeat through which may add a delay to the game or worse cause issues if the player is swapping weapons prior loop/repeat finishing. If you have any thoughts/ideas I am all ears.
I am grabbing the .json with the send a request to a web page action as this is being hosted localy and previewed within the IDE. Stores the .json as string.
I convert the string to global variable, this way the data is stored between scenes rather then doing the above for every new scene. (Felt this would be smarter/faster)
Then I added the relevant variables to the object when they change weapons. (Repeat # is how many weapons there are)
I did some testing to see what the load times were. First lot was with x30 entries, the second was 200, third 500 (13k lines). I did x5 load test each time, first test was for loading the data and storing in the scene/global variables the second was looping thought and adding variables to object (vaild object was always last)
x30 Load .Json
5 MS
5 MS
4 MS
5 MS
5 MS
x30 Store on Object
1 MS
2 MS
1 MS
2 MS
2 MS
x100 Load .Json
11 MS
8 MS
9 MS
9 MS
9 MS
x100 Store on Object
3 MS
2 MS
2 MS
3 MS
2 MS
x500 Load .Json
24 MS
25 MS
23 MS
24 MS
23 MS
x500 Store on Object
7 MS
7 MS
7 MS
7 MS
7 MS
At 500 entries, load times are very fast. More then fast enough to do it on the main menu before the player starts.
I can’t imagine the player swapping weapons faster then 7MS, however I can always ad a isLoaded variable to check prior to swapping.
I do only trigger the check when weapons are swapped, but it still needs to loop through the variables to get the data. Maybe on that initial load I run a single loop and store the weapon name with it’s corresponding array number(Like a hashmap), that way instead of a loop each weapon swap I just call the variable of data.weapon.[key.weapon_name.value].name etc. I guess I’ll give it a try after work tomorrow
So I played around with the logic tonight to remove any Conditionless loops and have a nice setup now.
Game Loads
Within 20 MS, loads all the data from my .json file into a scene variable as a string.
Convert the string into global variables as I will be using them in any scene from here on out.
Once loaded into the global variables, I call GlobalVariableChildCount() to see how many weapons I have. (They’re stored as data.weapon.value.#.name, data.weapon.value.#.variable2, etc)
Run a single however many GlobalVariableChildCount()'s there are, each time adding +1 to a current loop variable.
Each loop stores a data.weapon.key. with corresponding current loop variable (eg: data.weapon.key.weapon_1 0, data.weapon.key.weapon_2 1, etc).
When I want to switch weapons, I check the objects variable to see if has the right stats and if not I simply add them on using data.weapon.value[data.weapon.key[object_name].variable1, data.weapon.value[data.weapon.key[object_name].variable2, etc.