RPG MAKER MV Shuffle Script Problem

jetsada

Villager
Member
Joined
Sep 16, 2014
Messages
7
Reaction score
3
First Language
English
Primarily Uses
Dear javascript guru,


I write these code in common event but the result is weird;


Script:


$gameVariables.setValue(31,[2,3,4,5,6,7,8,9,10,11,12,13,14,15]);
$gameVariables.setValue(9,$gameVariables.value(31));
var j, temp;
for (i = $gameVariables.value(9).length - 1; i > 0; i--) {
j = Math.floor(Math.random() * (i + 1));
temp = $gameVariables.value(9);
$gameVariables.value(9) = $gameVariables.value(9)[j];
$gameVariables.value(9)[j] = temp;
}


 


Then I check the values of variable 31 and 9 in message


Variable 31 is \V[31]


Variable 9 is \V[9]


 


The result is same. I mean the "Variable 31" was shuffled, too.


Please help how to retain original value of "Variable 31" while "Variable 9" was shuffled.
 
Last edited by a moderator:

Shaz

Global Moderators
Global Mod
Joined
Mar 2, 2012
Messages
40,822
Reaction score
14,021
First Language
English
Primarily Uses
RMMV
When you say


a = [1,2,3,4,5]


b = a


b is not a duplicate of a, but it points to the same object.  If you add another element or two to a, then look at b, it will also have the new elements.


$gameVariables.setValue(9,$gameVariables.value(31).slice(0));


will put a copy of the array into the second variable.
 
Last edited by a moderator:

jetsada

Villager
Member
Joined
Sep 16, 2014
Messages
7
Reaction score
3
First Language
English
Primarily Uses
Thank you very much, Shaz.
 
Last edited by a moderator:

Shaz

Global Moderators
Global Mod
Joined
Mar 2, 2012
Messages
40,822
Reaction score
14,021
First Language
English
Primarily Uses
RMMV
did you read my post?  You seem to have ignored it completely.  Or you just double posted, which is against the forum rules (if you need to make a change/addition, edit your post instead of posting immediately under your last post).
 

jetsada

Villager
Member
Joined
Sep 16, 2014
Messages
7
Reaction score
3
First Language
English
Primarily Uses
Sorry Shaz, the 2nd post is delivered next to 1st continuously (without refresh the browser). I'll delete it after this post.
 

Shaz

Global Moderators
Global Mod
Joined
Mar 2, 2012
Messages
40,822
Reaction score
14,021
First Language
English
Primarily Uses
RMMV
I assumed you just posted without seeing that I'd replied :)   They were pretty close together in time.


Hope it worked for you without any further problems.
 

jetsada

Villager
Member
Joined
Sep 16, 2014
Messages
7
Reaction score
3
First Language
English
Primarily Uses
It works pretty cool. Thanks again.
 

Latest Threads

Latest Profile Posts

Snarkyfork wrote on Trihan's profile.
Hey man, I saw you mention that you do MV javascript work? Just wanted to confirm it before I put you on speed dial. =)
"Man is made by his belief. As he believes, so he is."-Krishna
FastFood in my country is neither fast nor cheap like it's expected to be, but people still buy a lot of it. I don't want to imagine how much of it people would eat if it was.
Started finishing up my bosses and characters...I don't know how long...but its going to take long...

Forum statistics

Threads
107,758
Messages
1,031,946
Members
139,901
Latest member
jekken
Top