Code:
Problem description:Question how would i make a choice random using the rand proc like a rand then with a if statement like rand(1,2,3) then a if statement after
In response to YoungJR1232
|
|
YoungJR1232 wrote:
and is it possible to put more than 1 rand like rand(1,2,3,4) You can only have two in rand(var1, var2) |
In response to YoungJR1232
|
|
If you're looking to get a random choice from a list, take a look at the pick() proc.
|
In response to Mightymo
|
|
Mightymo wrote:
If you're looking to get a random choice from a list, take a look at the pick() proc.yes so how would use do that in a if statement so would it work like the rand proc if(pick(jack,dog,cat) == dog) |
proc Give switch a try if you want to pick stuff from a list. It's not right for every situation, but it is incredibly useful. Also incredibly useful is remembering that the input window here will automatically post stuff if you press tab and enter. |
You'd probably want the pick to choose from a list of strings.
So: if(pick("jack", "dog", "cat") == "dog") But, that's probably not what you actually want to do. Are you trying to do something unique for each possible choice, or just one choice? |
Yes, that would work. However, I cannot really see a use in using it like that. In an instance like that, using rand from 1 to 3 looking for a value of 2 would be equivalent. Generally, you use pick() if you need the result later, e.g. doing an action specific to the choice, and then incrementing the variable chosen. In such an instance, you would be better off placing the result of pick() into a variable, and then checking against that variable.
Edit: I'm slow. |
btw im trying to make it so when a player logs in it runs a proc to pick a class and i was thinking i could use rand (but now i guess pick) to randomly pick a class so if dog then your class is blah blah if cat your class is blah blah what Mada said is most suited
|
mob |
In response to YoungJR1232
|
|
YoungJR1232 wrote:
btw im trying to make it so when a player logs in it runs a proc to pick a class and i was thinking i could use rand (but now i guess pick) to randomly pick a class so if dog then your class is blah blah if cat your class is blah blah what Mada said is most suited It would have been ideal to mention this at the beginning so we could have pointed this out to you much earlier. As we tell people, more information given is better (in most cases). |
In response to YoungJR1232
|
|
Everything appears correctly; do you have an interface file made? If so, make sure you enabled 'default' on your main output element so these messages can go to that output without specifying via output().
Personally, I would do var/b = pick(list(...)) |
In response to GhostAnime
|
|
GhostAnime wrote:
YoungJR1232 wrote:Yeah sorry my fault but thank you guys alot for your help now ik what i can do and i have a new proc to use |
Here's how:
- rand() RETURNS a value (like how an input() returns a value the user entered)
- if() is used to check a condition.
Here are some variations
If you are trying to do a probability, you are better off using prob(), ex: