Input number to choose how many?

But I'm still wondering if this can be done with the Event Command window? I don't mind using script. I was having more fun using the Event Editor though. I'm afraid to say I'm not good with script...Event Editor is easier for me.

I'm kinda lost at this point but amazed at what you wrote at the same time. So thank you. 🙂
But I'm still wondering if this can be done with the Event Command window? I don't mind using script. I was having more fun using the Event Editor though. I'm afraid to say I'm not good with script...Event Editor is easier for me.

I'm kinda lost at this point but amazed at what you wrote at the same time. So thank you. 🙂
I'm sorry, but at this point I don't understand your question. I literally just wrote it out using the buttons you would click in the Event Editor...which part are you lost by? 😳
The script parts are entered through a Call Script command, which is at the bottom of page 3 of event commands.
The script parts are entered through a Call Script command, which is at the bottom of page 3 of event commands.

Thank you! 🙏
Thanks, Shaz, I accidentally typed just Script instead of Call Script.
I keep getting error
Syntax Error

missing ) after argument list



If I am understanding correctly, Variable 1 is the number the player inputted. Variable 2 is a variable created to randomly subtract the items.

And for script $gameVariables.setValue(2, Math.randomInt($gameVariables.value(1)) + 1;
is the number 2 I bolded the number of the variable being used? In this case in example we are calling it variable 2 but my variable is number 158 or whatever I should set it to that number instead?


I have been playing around with this but so far I have been unsuccessful. I think it would be very cool if I got this to work. That and it helps me learn.
I keep getting error
Syntax Error

missing ) after argument list


And for script $gameVariables.setValue(2, Math.randomInt($gameVariables.value(1)) + 1;
The error means exactly what it says - there are three ( but only two ). Put a third closing parentheses right in a row.
is the number 2 I bolded the number of the variable being used? In this case in example we are calling it variable 2 but my variable is number 158 or whatever I should set it to that number instead?
Yes, that number 2 is the number of a free variable that's only used inside this event. The number 1 inside the parentheses is whatever variable you used for Input Number, also only used inside this event.
The error means exactly what it says - there are three ( but only two ). Put a third closing parentheses right in a row.

Yes, that number 2 is the number of a free variable that's only used inside this event. The number 1 inside the parentheses is whatever variable you used for Input Number, also only used inside this event.
With the second variable being the one that generates a random number, in this case 1-99?

By weight I assume you mean the rarity of the items? If so, do I use 3 different variables that generate random or used the same random variable and change the random amount?


Edit5: I went ahead and set the player input variable to 0 so the next input will start at 0. (At the very end with the last item) So that fixed that I guess? I also removed ◆Control Variables:#0253 Player Input# -= Ultra Rare
So it would display the correct number last. I think that also fixed it.



Edit 6: If I wanted a bunch of items, like more than 5 how would I loop that? You mentioned this.

Also the items are alway 1 off?
By weight I assume you mean the rarity of the items? If so, do I use 3 different variables that generate random or used the same random variable and change the random amount?
Yes, in math, "weighing" randomness means your outcome will be random but certain outcomes are more or less likely. So I could say I always want at least 30% of the stuff given to me to be glass. You can generate a random number between two values with:
Math.floor(Math.random() * (max - min + 1) + min);
where "min" would be what percentage of your gains has to be this material, e.g. $gameVariables.value(253)*.3 for 30%, and max is just the value of 253. So you'd replace the random numbers in your script calls with that.
Edit 6: If I wanted a bunch of items, like more than 5 how would I loop that? You mentioned this.
You just keep copying the code the same way it has been 3 times. You only need a loop if the number of items you get can vary.
Also the items are alway 1 off?
Your screenshot window isn't wide enough, so we can't see all of the text in your script calls. However, a few things I see:
- You have lines at the top setting 263, 262 and 261 to random numbers. Why?
- You've taken out the conditional statements I had before each material. The way it's written (as far as I can see your script), you can run into bugs if the random materials reach the number the player input before you get to diamonds. This could be causing the items to be off, or it could be something in the scripts that I can't see to the right.
- You're setting 259, 260, and 255 to the glass/diamond/crystal. Why? They're not used for anything here, are they being used someplace else?
- Similarly, you're using three different variables for the random amounts of materials (261, 262,263). Why? Just use the same variable each time as I showed you. Or, if you're using those numbers someplace else in the game, use those variables instead of 259, 260, and 255. I don't understand why you're using 6 variables instead of 1.
Your screenshot window isn't wide enough, so we can't see all of the text in your script calls.
I did not realize that, I apologize. I will try that script too, thanks.

You just keep copying the code the same way it has been 3 times. You only need a loop if the number of items you get can vary.
If I understand correctly, vary meaning the player may sometimes just get glass only or all three. (In example) I'd like to see how that works actually. I'd like to give more than three items, a way to choose how many would be nice for future use. (Unless by vary you mean player gets glass, diamond, glass, glass, crystal etc. Then no. Just one message for each appraised item)

- You have lines at the top setting 263, 262 and 261 to random numbers. Why?
So that Glass would be very common, Crystal rare and Diamond ultra rarer. I thought each needed it's own random variable. And because I'm a derp. 😛

- You're setting 259, 260, and 255 to the glass/diamond/crystal. Why? They're not used for anything here, are they being used someplace else?
Because I was playing around with the event and I don't know what I am doing. I think at the time I did this, I was hoping the message displayed would show how many items were received? Either way, I can see that it's pointless now.

- Similarly, you're using three different variables for the random amounts of materials (261, 262,263). Why? Just use the same variable each time as I showed you.

Because I thought a new variable was needed for each random to be different. I worry that if I don't keep certain variables constant it will mess up other parts of the games or something.

Like, if I use a variable that generates a random message from 1-3 and then in a completely other event change that same variable to 1-5 random messages. Then because I did that the events that use 1-3 random will not always work since I changed the variable in another event to a random of 1-5.
If I understand correctly, vary meaning the player may sometimes just get glass only or all three. (In example) I'd like to see how that works actually. I'd like to give more than three items, a way to choose how many would be nice for future use. (Unless by vary you mean player gets glass, diamond, glass, glass, crystal etc. Then no. Just one message for each appraised item)
"Vary" means something can change, be different. So if the number of materials can vary, that means sometimes the player will get back all glass, or glass and crystal, or glass and crystal and butterfly poop.
I think at the time I did this, I was hoping the message displayed would show how many items were received?
It will, but you used the wrong code - it's \V, not \v.
Because I thought a new variable was needed for each random to be different. I worry that if I don't keep certain variables constant it will mess up other parts of the games or something.
Nope, the code follows the instructions you give it. If you tell this variable to become a random number, use that value for some things, then tell it to become a different random number, it will. It can't possibly do anything to your game if you're not reusing that variable in other events. I even did this when I typed it out for you when I used the example number of 2 every time. I have several variables in my game just named Storage 1 and so forth that I use in all events where I need to temporarily keep track of numbers.
Like, if I use a variable that generates a random message from 1-3 and then in a completely other event change that same variable to 1-5 random messages. Then because I did that the events that use 1-3 random will not always work since I changed the variable in another event to a random of 1-5.
That can't possibly happen - things on a computer don't happen at the same time. Even though it all happens faster than a human can keep track of, they happen in order. Unless you actually call a different common event from inside this event, nothing you do in a different event can affect this, so long as you're always setting the values of the variables in here (which you are).

I'm happy to answer questions for you, but it really sounds like you should check out some tutorials for MV, because a lot of the things you're confused about are pretty basic parts of the program. There are more on the forums and YouTube if you Google it, but a quick search turns up stuff about...
Events: https://moegamer.net/2016/08/17/rpg-maker-mv-getting-started-with-events/
Switches, variables, conditionals: https://forums.rpgmakerweb.com/inde...r-mv-switches-branches-variables-basic.49665/
Loops:

I'd suggest you go through at least the first two of those, see if that helps this make more sense, then ask me what you're still confused about. And if your event still doesn't work right, post another screenshot but make the window wide enough to see everything.
Switches and Conditions I'm fine with. It's variables I'm not always sure on. ^^;

I just watched the Loop video. I would like to try to make an event that has items that are "weighed" and "vary". (I've never made one of those before! o-o)

So I replace the current script with ?

Math.floor(Math.random() * (max - min + 1) + min); $gameVariables.value(253)*.3


You can generate a random number between two values with:
Math.floor(Math.random() * (max - min + 1) + min);
where "min" would be what percentage of your gains has to be this material, e.g. $gameVariables.value(253)*.3 for 30%, and max is just the value of 253. So you'd replace the random numbers in your script calls with that.

Random numbers being which part? I'm a little unclear on this. Like, where in the script do I replace the random numbers? The max and min of Math.floor(Math.random() * (max - min + 1) + min);??

I'm not sure where to put my numbers or variable in the script.

I'm going to work on the event now and will get back to this topic.

Edit: I'd just like to know how to vary and weigh items, and include more items if wanted.

The attachment First Event White Wonderful is the event I was working on first.
The second attachment is an event with weight and vary script.

Side notes: If Diamond is 0, I don't want the message even displaying. And yes, player can sometimes get all glass or most glass and a few diamonds.

PS: Thanks for the help. 🙂 I'm really appreciating it.
Switches and Conditions I'm fine with. It's variables I'm not always sure on. ^^;
Variables are just a way to store a number. It's one of your measuring spoons when you're cooking - you don't need to use a different tablespoon for every ingredient, just so long as you're not trying to scoop two ingredients at the same time.
So I replace the current script with ?

Math.floor(Math.random() * (max - min + 1) + min); $gameVariables.value(253)*.3
No, I didn't describe two statements, just the one. Typing "$gameVariables.value(253)*.3" is like standing in the middle of the kitchen and shouting "one tablespoon of vinegar!" You're not doing anything with it, just saying how much you have.
Random numbers being which part? I'm a little unclear on this.
There's only one thing in your event that creates a random number. It's the same line of script every time, and it's the only Call Script lines that you have.
Edit: I'd just like to know how to vary and weigh items, and include more items if wanted.
The instructions I gave you to replace your random number script is how to weigh items. I already told you that to include more items you just copy the code more times, and you've done that (I appreciate the butterfly poop XD ).
The second attachment is an event with weight and vary script.
So I gave you Math.floor(Math.random() * (max - min + 1) + min); with instructions on what to replace "max" and "min" with. You have replaced them with the numbers 253, 261, and .1.

1 - that's three different numbers, when "max" and "min" are only two different things - whatever you put for "min" needs to be the same both places.

2 - you putting in 253 and 261, for a computer, are just numbers. If you type "253-261+1" that will always be the same thing, -7. If you want to use the values of those variables, you know how to do that from the script you were already using: $gameVariables.value(253) or $gameVariables.value(261)

3 - I do not think using those numbers is what you want to do. Even if you type it with the correct script, you're saying you want a random number between 1-99 (which is what you still have 261 set to at the top of your event for some reason) and the number of White Wonderfuls the player gave. Surely you can see that doesn't make sense...it is possible for your minimum number to be higher than your maximum, which will obviously make something weird happen. So, see my next point:

I'm going to go back to the first post I wrote in this thread - the most important part of this kind of work is planning out your instructions. I told you about the concept of pseudo-code, and that's just making instructions for every step, like a recipe. Then you figure out the programming to make it work.

In this case, you need to describe exactly how these combinations are possible, because I don't know what you want in your brain. I already told you how to do it by example, and some part of that isn't making sense to you - that's fine, and I'll help you, but you need to know what you want to happen, and you need to be able to explain it clearly and precisely, or you can't make it happen on a computer (and no one else will be able to make it for you because they won't understand, either).

Here is my example:
When someone gives me a net of butterflies, they're guaranteed to get at least 45% of that number, but not more than 70%, as butterfly wings.
Then they'll get 50%-100% of the rest as butterfly legs.
Then, if there's anything left, they'll get a random amount of butterfly poop.
Then, if there's anything left, they'll get a random amount of cocoons.
I just accidently posted, I'm not finished with this current post. I will update this post as soon as I am finished with it.

Edit: Just finished my post.



I'm bad at explaining at some things, such at this topic, but I am trying. I think one of the things confusing me is where to put my variables into the scripts you're giving me.

Like

$gameVariables.setValue(261, Math.randomInt($gameVariables.value(253))) + 1;

I figured out above that the first variable 261 is the random variable and the second variable is 253, what the player inputted. (The variable numbers I am using. I'm not entirely sure now if I understood that correctly)

============================================


So I gave you Math.floor(Math.random() * (max - min + 1) + min); with instructions on what to replace "max" and "min" with. You have replaced them with the numbers 253, 261, and .1.

1 - that's three different numbers, when "max" and "min" are only two different things - whatever you put for "min" needs to be the same both places
Math.floor(Math.random() * (max - min + 1) + min);
where "min" would be what percentage of your gains has to be this material, e.g. $gameVariables.value(253)*.3 for 30%, and max is just the value of 253. So you'd replace the random numbers in your script calls with that.

So max being what the player inputted, in my case variable 253. And min being what percentage I want? So if I chose 30% like your example. Then the script would look like this

Math.floor(Math.random() * (253 - 30% + 1) + 30%);

or do I use .3 instead for the percentage? I'm not sure which at the moment. The .3 is sounding more plausible right now...^^;




===========================================



As for the random 1-99, is the variable not needed because of script

Math.floor(Math.random() * (max - min + 1) + min); ?

I thought it had to use an actual variable in order for the script to work? Like when I set a variable to recognize how much of an item I have, the event won't work until the variable is called in the event to see how much of an item the player actually has.

If you want to use the values of those variables, you know how to do that from the script you were already using: $gameVariables.value(253) or $gameVariables.value(261)
Does this mean I am editing one script or making two separate script calls?

============================






Here is my example of something I'm trying to make work as a test:
  1. I give an npc a number of White Wonderfuls.
  2. Maybe 10% to 25% they will get a Crystal (Uncommon)
  3. Maybe 1% to 10% they will get a Diamond (Super Rare item)
  4. The rest they'll get is glass ranging from 75% to 100%. I want glass to be the last item but the majority of what is received. (Glass being common)
  5. This is something I might want to use, but is it possible to have Glass be 100% sometimes? Sometimes they'll get 3 Crystals, 1 Diamond and rest Glass. Or they just get all Glass.


In the mean time I'm going to look over this topic and work on the event. I'm slowly understanding some of this now.

Edit: I should mention I am a visual person so it might help if I see an example of what I am trying to do.

I also want to say thank you, I really appreciate your patience with me.
Math.floor(Math.random() * (max - min + 1) + min);

So max being what the player inputted, in my case variable 253. And min being what percentage I want?
"Max" is short for the word "maximum," the highest value you want to be possible. "Min" is short for the word "minimum," the lowest value you want to be possible. If you want your random number to possibly be 100% of what the player input, then sure.
So if I chose 30% like your example. Then the script would look like this

Math.floor(Math.random() * (253 - 30% + 1) + 30%);
Perhaps you get over-excited and try to dive into things, but try to slow down and go methodically, because this is ignoring several examples and corrections I already gave you.

You typing the number 253 doesn't mean anything to your computer other than the number 253. If you want to use the value of variable 253, then you need to type that in the way you've been shown - $gameVariables.value(253)
or do I use .3 instead for the percentage? I'm not sure which at the moment. The .3 is sounding more plausible right now...^^;
Correct - again, I already showed you that in a prior example. This is just regular math, the way you would say "30% of something" is "that number * .3." So if you want to use 30% of variable 253, then $gameVariables.value(253)*.3

As for the random 1-99, is the variable not needed because of script

Math.floor(Math.random() * (max - min + 1) + min); ?

I thought it had to use an actual variable in order for the script to work?
Yes, you use a variable. But you're doing extra things with them that I don't understand. Look at the very first two lines of your event. The first line sets variable 261 to a random number between 1-99. Why? There's no place that you ever use that value. It wasn't in the first example I wrote for you. Same question for the next line that does something with variable 252.
Here is my example of something I'm trying to make work as a test:
  1. I give an npc a number of White Wonderfuls.
  2. Maybe 10% to 25% they will get a Crystal (Uncommon)
  3. Maybe 1% to 10% they will get a Diamond (Super Rare item)
  4. The rest they'll get is glass ranging from 75% to 100%. I want glass to be the last item but the majority of what is received. (Glass being common)
  5. This is something I might want to use, but is it possible to have Glass be 100% sometimes? Sometimes they'll get 3 Crystals, 1 Diamond and rest Glass. Or they just get all Glass.
Okay! This is a good start. However, it's not great yet, because some of it is out of order. You say in step 4-5 that it's possible for them to get 100% glass, but that's impossible because you already listed them getting other materials. If it's possible that everything will turn into glass, it must be first so that we know that nothing is left when we look at the next material.

You just told me "put two cookies into your lunchbox. Now, put all the cookies into the cookie jar." Well, I can't put all the cookies into the jar because I just put two into my lunchbox!

So keep that idea, look again at exactly how I wrote my example for you, and do it once more. Don't worry about getting distracted with trading card Uncommon/Super Rare words, that doesn't mean anything for what you're trying to do.
"Max" is short for the word "maximum," the highest value you want to be possible. "Min" is short for the word "minimum," the lowest value you want to be possible. If you want your random number to possibly be 100% of what the player input, then sure.

I already knew that Max is short for Maximum and Min for Minimum. But I'm still a little confused. I think I now know you meant for me to choose two numbers for random. I thought I was placing/stating? variables in them. o-o

I think I understand that the script Math.floor(Math.random() * (max - min + 1) + min); is the same as when I was using my variable at the top for random numbers 1-99 but Math.floor(Math.random() * (max - min + 1) + min); is the script form.

Perhaps you get over-excited and try to dive into things, but try to slow down and go methodically, because this is ignoring several examples and corrections I already gave you.
Yes I'm excited, no I'm not trying to ignore your several examples. It's just that I am having trouble understanding. I'm still not clear on where to place the random numbers, where to state my variables in the script and where to place $gameVariables.value(253)


You just told me "put two cookies into your lunchbox. Now, put all the cookies into the cookie jar." Well, I can't put all the cookies into the jar because I just put two into my lunchbox!

I like cookies. But okay, the glass doesn't have to be 100%. o-o

Correct - again, I already showed you that in a prior example. This is just regular math, the way you would say "30% of something" is "that number * .3." So if you want to use 30% of variable 253, then $gameVariables.value(253)*.3

I knew that .3 was 30% but at the time I wasn't sure which one to use. I'm not familiar with scripts themselves, just the buttons I see in Rpg Maker.

Also the script, I just replaced the number in this example with X. I need clarification. Are the Max and min in place of the two random numbers I'd like? What is the X in your example? Is X the items, the variables or the random numbers?

◆Script:$gameVariables.setValue(253, Math.floor(Math.random() * (x - .x + 1) + .x));

The min is already the percentage so I think Max has to be the player input, in this case variable 253
So I think the script should look something like this
$gameVariables.setValue(253, Math.floor(Math.random() * (253 - .3 + 1) + .3));

I think the script means player input(variable 253 is player input) minus glass percentage and the +.3 is glass being added into the inventory.


but have no idea if that script line is accurate, placed by each other properly or if the computer recognizes that 253 is the variable, not a number. I don't know how to combine the two scripts into one script.

and if glass is script $gameVariables.setValue(253, Math.floor(Math.random() * (253 - .3 + 1) + .3));

and if I wanted just two items, Diamonds and Glass, then is this Diamonds script
$gameVariables.setValue(253, Math.floor(Math.random() * (253 - .7 + 1) + .7));
to equal 100%?

Math.floor(Math.random() * (max - min + 1) + min)
The way I interpret this script call is that it is generating something random. (Because of the words Math.Random) It's also I think multiplying. (because of the *) The .3 is how much glass I want the player to get back. And that min is the same for both min now. But what is Max? The player input or something else entirely?

I've tried setting $gameVariables.setValue(253, Math.floor(Math.random() * (x - .x + 1) + .x));

to state that 253 IS the player input.

And is Math.floor(Math.random() * (max - min + 1) + min); is my random variable? You said
Yes, you use a variable. But you're doing extra things with them that I don't understand. Look at the very first two lines of your event. The first line sets variable 261 to a random number between 1-99. Why?

I keep using 261 variable 1-99 because in past events, in order for a random to work it has to be stated in the event. Or else nothing happens. Is the script Math.floor(Math.random() * (max - min + 1) + min); in place of the random variable?

And if Math.floor(Math.random() * (max - min + 1) is my random variable, how do do I do this part?
◆Change Items:Diamond + {RNG}

Because now I don't see or seem to have a variable to use for this item change that's depending on a variable.

And is $gameVariables.setValue(253, Math.floor(Math.random() * (253 - .3 + 1) + .3));

The script I'm even suppose to be using?


If you want to use the values of those variables, you know how to do that from the script you were already using: $gameVariables.value(253) or $gameVariables.value(261)

I see two scripts $gameVariables.value(253) and Math.floor(Math.random() * (max - min + 1) + min);

and have no idea how to arrange them in a script call properly. Does $gameVariables.value(253) go first? Is there a space between $gameVariables.value(253) and Math.floor(Math.random() * (max - min + 1) + min);?

If I could just see a visual of the event I'm trying to create, I will most likely have a better understanding. That usually works for me.


I just attached a screenshot that took me several minutes to compose together but right now I am assuming the Math.floor(Math.random() * (max - min + 1) + min); but have not fixed it.
You are still trying to write the event without knowing what you want to achieve. This will always fail. If you can write out the instructions, in English, for what you want to happen (exactly the way I gave you an example of), I will help you make it into an event. The rest of your questions are just very all over the place and I have given you the answers to all of them in one post or another.

I do not understand what you mean (twice, now) of seeing a visual. If you mean a clip from a game, you would see a character walking up to another character and little windows pop up that you received these items. I don't know how that would be helpful. If you mean you want me to write the event for you without knowing how you want it to work...in the first place, I can't, because I don't know what you want. In the second place, that's just words on the screen, which is the exact same thing I'm typing to you now. I don't see what the difference is between reading words in a forum post or words in a screenshot 😛
I think I need to start over. I keep looking over your past posts and I still don't understand them. How is this achieved below? This is what I want.

  1. I give an npc a number of White Wonderfuls.
  2. 25% they will get a Crystal
  3. 10% they will get a Diamond (Super Rare item)
  4. The rest they'll get is glass, 65%. I want glass to be the last item but the majority of what is received. (Glass being common)
I think I need to start over. I keep looking over your past posts and I still don't understand them. How is this achieved below? This is what I want.

  1. I give an npc a number of White Wonderfuls.
  2. 25% they will get a Crystal
  3. 10% they will get a Diamond (Super Rare item)
  4. The rest they'll get is glass, 65%. I want glass to be the last item but the majority of what is received. (Glass being common)
If this is what you want, you can just do it with regular event buttons. This is less complicated than the first event you asked me for, there are no random numbers involved.

You have been asking for help making a process where you get a random number of these items back. If you want an exact percentage, you don't need any special script calls, that's just all in the event buttons.
I would like random numbers involved. But I don't know how to ask this.
All I know is I want items to be rare or common or whatever.

Glass to be the majority give back like 75%
and the rest is random, but small amounts of it

Original thread: https://forums.rpgmakerweb.com/threads/input-number-to-choose-how-many.133024/