[MV] Help with Random Variables not Repeating themselves.

Nerdboy

Veteran
Veteran
Joined
Jan 4, 2017
Messages
78
Reaction score
7
Primarily Uses
I've found tips and tricks to figuring this out in the forums but i want to confirm if what im doing is right because i have a long list of 100 possible random text msgs and id like to know if my code is right before i start to input it. basically trying to use random variables to generate if else statements that dont repeat that output in text msgs.

note - the switch on is for another function that im using, so its needed you can ignore that part.

this is the simplest way ive gotten it down but want someone to look it over to see if this works or not? cuz its gonna be a very tedious process to input 100 random text msgs, as i dont really know how to do it using arrays since im not sure how to remove variables from arrays in javascript. tried looking it up... but... anyhow...

heres the code

if switch is on
control variable X = random 1..25
if x = 1
loop
if x = uniqueID1
control variable X = random 1..25
else
break loop
end
if x = 1
display_message
control variable uniqueID1 = x
end
else
if x = 2
loop
if x = uniqueID2
control variable X = random 1..25
else
break loop
end
if x = 2
display_message
control variable uniqueID2 = x
end
repeat for all 100 display messages

ok so does the code above look right to you? will it work? idk since i havent tried it yet, i may have to but, id like to save me the hassle of going through the whole process and then finding out it still repeats....!!!!

so i tried doing this using a small pool and it doesnt work for some reason, what happens is it doesnt repeat *good but then it also doesnt display the text messages after it displays itself once and only once. what am i doing wrong?
 
Last edited:

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
39,163
Reaction score
12,436
First Language
English
Primarily Uses
RMMV
Nah, there's an easier way.

You create a variable that is an array, and you either put the numbers 1-100 into the elements, or you put the messages themselves into the elements. For ease of use, I'd put the messages into the elements. To do this, create a new common event, and add a command to create the array with no elements:
Code:
Script: $gameVariables.setValue(x, [])
where x is your variable id - no leading zeros.

Then for each of your messages, push that message onto the array. You can do several of these in a single script call, and when you run out of room, just move on to the next script call:
Code:
Script: $gameVariables.value(x).push('This is the first message');
       $gameVariables.value(x).push('This is the second message');
       $gameVariables.value(x).push('This is the third message');

Script: $gameVariables.value(x).push('This is the 99th message');
       $gameVariables.value(x).push('This is the 100th message');

Now each time you want to show one of the messages, you'll first check the array to see that there IS a message to retrieve - if there is, you'll retrieve it, if there isn't, you'll call the common event to recreate the array. To do this:
Code:
Conditional Branch: $gameVariables.value(x).length == 0
    Common Event: reset messages
End

$gameVariables.setValue(y, $gameVariables.value(x).splice(Math.floor(Math.random() * $gameVariables.value(x).length), 1))
This randomly chooses one of the messages in the array, removes it from the array, and places it in variable y. Then you can use the \v[y] escape code (replacing y in the code above and in the escape code) to display it in a message box.


It would actually be better if you used a plugin to store the messages, because using a variable is going to put all the message strings into the save file. You could also use numbers instead of text, but then you'd have to do a whole stack of conditional branches to see which number was chosen and display the correct message. Both of the approaches are messy, but both are easier than what you were trying to go with originally.
 

Nerdboy

Veteran
Veteran
Joined
Jan 4, 2017
Messages
78
Reaction score
7
Primarily Uses
I should've clarified, i was simplifying what I was trying to do, thats why im using the loop and loop break with uniqueID's.

Can you use the above method, with 'show choice' ala multiple choices? and also have extra message box displayed on top of it, so first message, then show choice, then 2nd message. using arrays might get too complicated for this, since it uses mv show choice for what im trying to do.

your method does give me ideas as to how to proceed with splice thats what i was trying to figure out. but, wouldn't it be simpler to use my method in my circumstance? it works somewhat, like it doesn't repeat, but once text message is displayed it only displays once and only once when all options are used up, nothing is displayed. which is good maybe have everything in nested if else statement with last else to output message saying something that tells player all options have been used up. if i did it that way my way works, but kinda not intentional just way code is structured.

using my method unless your method *shaz is easier with what i just said, what would i have to do nest or loop possibly to get it to display more than once but not repeat itself at the same time? tricky i know. if we cant figure out a solution then well, i might just use the nested if else statement and output "all options used up".
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

Here it is in all its leggy glory! I apologize in advance.
Suggestion for the name for the new RM, RPG Maker Re-MV (Re-Mastered Version)
A guide on Furry Potatoes.

I apparently need to send photo ID to Blizzard to change my phone number. I don't even need to do this to change my number with my bank or PayPal

Forum statistics

Threads
98,175
Messages
950,082
Members
129,473
Latest member
Soulbanana
Top