DadGuyDrawing

Veteran
Veteran
Joined
Apr 15, 2020
Messages
91
Reaction score
36
First Language
English
Primarily Uses
RMMV
I have some code in a custom plugin where I place a bunch of arrays in $gameVariables but my code seems to replace all of the variables with the last array instead of placing them in sequentially.

Pseudo code:
-make a temp array with a bunch of 0's in it
-make a variable (intVariableID) with the first $gameVariable ID
-change a few items in the temp array
-place the temp array int the first $gameVariable with ID (intVariableID)
-change (intVariableID) to be the 2nd $gameVariable ID
-change a few items in the temp array
-place the temp array in the second $gameVariable with new ID (intVariableID)

I initially did this with a for ... loop, but all the variables were populated with the last array only. So I modified the code as per below, but still only the last array populates in all of the variables.

Any help would be appreciated! Actual code below.

Thanks.

JavaScript:
funInitializeBookshelf = function(){

        var arrTempStorageArray = [];
        var intBookShelfStorageVariableID; 
        
        /*:
        * Array Index
        0 = intTargetSkillID
        1 = intTargetIntroComplete
        2 = intTargetIntermediateComplete
        3 = intTargetAdvancedComplete
        4 = intTargetIntroSessions
        5 = intTargetIntermediateSessions
        6 = intTargetAdvancedSessions
        7 = intTargetIntroShow
        8 = intTargetIntermediateShow
        9 = intTargetAdvancedShow
        10 = intTargetTopicShow
        11 = Reward Screen
        *
        */



        arrTempStorageArray[0] = 0;
        arrTempStorageArray[1] = 0;
        arrTempStorageArray[2] = 0;
        arrTempStorageArray[3] = 0;
        arrTempStorageArray[4] = 0;
        arrTempStorageArray[5] = 0;
        arrTempStorageArray[6] = 0;
        arrTempStorageArray[7] = 0;
        arrTempStorageArray[8] = 0;
        arrTempStorageArray[9] = 0;
        arrTempStorageArray[10] = 0;
        arrTempStorageArray[11] = 0;
// "enchantment":
            
                intBookShelfStorageVariableID = 591;               
                arrTempStorageArray[0] = 28; //intTargetSkillID
                arrTempStorageArray[7] = 1;//intro Show
                arrTempStorageArray[8] = 1;//intermediate Show
                arrTempStorageArray[9] = 1;//advanced Show
                $gameVariables.setValue(intBookShelfStorageVariableID,arrTempStorageArray);
            
// "magic":
                intBookShelfStorageVariableID = 592;
                arrTempStorageArray[0] = 28; //intTargetSkillID
                arrTempStorageArray[7] = 1;//intro Show
                arrTempStorageArray[8] = 1;//intermediate Show
                arrTempStorageArray[9] = 1;//advanced Show
                $gameVariables.setValue(intBookShelfStorageVariableID,arrTempStorageArray);
// "social":
                intBookShelfStorageVariableID = 593;
                arrTempStorageArray[0] = 20; //intTargetSkillID
                arrTempStorageArray[7] = 1;//intro Show
                arrTempStorageArray[8] = 1;//intermediate Show
                arrTempStorageArray[9] = 1;//advanced Show
                $gameVariables.setValue(intBookShelfStorageVariableID,arrTempStorageArray);

// "divination":
                intBookShelfStorageVariableID = 594;
                arrTempStorageArray[0] = 23; //intTargetSkillID
                arrTempStorageArray[7] = 1;//intro Show
                arrTempStorageArray[8] = 1;//intermediate Show
                arrTempStorageArray[9] = 1;//advanced Show
                $gameVariables.setValue(intBookShelfStorageVariableID,arrTempStorageArray);
// "alchemy":
                intBookShelfStorageVariableID = 595;
                arrTempStorageArray[0] = 21; //intTargetSkillID
                arrTempStorageArray[7] = 1;//intro Show
                arrTempStorageArray[8] = 1;//intermediate Show
                arrTempStorageArray[9] = 1;//advanced Show
                $gameVariables.setValue(intBookShelfStorageVariableID,arrTempStorageArray);
 
        

       };
 

Aerosys

Veteran
Veteran
Joined
Apr 23, 2019
Messages
730
Reaction score
701
First Language
german
Primarily Uses
RMMZ
I think I got it. What does work with reassigning the intBookShelfStorageVariableID, does not work with arrays, as these are objects.

So this:

Code:
const a = [1, 2, 3]
a[4] = 4;
const b = a;

will result in BOTH a and b being [1, 2, 3, 4].

I recommend you to always use a new Array to mitigate unwanted side effects. So

Code:
$gameVariables.setValue(xy, array1);
$gameVariables.setValue(xz, array2);
$gameVariables.setValue(xv, array3);
...

And also I recommend to use shorthand assignment of arrays, ie.

Code:
const arrTempStorageArray = [0, 0, 0, 0, 0, 0, 0, 0, ....]
 

Latest Threads

Latest Profile Posts

I know I'll put one of my game's sprites here to give the illusion that I am a productive member of game society.
handelspriteanim.gif
Preparing untested English localization for DOWNFALLEN.

unknown-43.png
Sometimes I wonder if I feature creep... 225 magic spells is a lot lol.

Forum statistics

Threads
124,500
Messages
1,164,063
Members
163,329
Latest member
milkpowder
Top