ID:1662159
 
(See the best response by Pirion.)
Code:

obj
Sorting_Hat
icon = 'randoms.dmi'
icon_state = "SortingHat"
density = 1
verb
Get_Sorted()
set src in oview(1)
switch(alert("Are you sure you want to get sorted?","","Yes","No"))
if("Yes")
switch(input("Do you have any specific house you don`t want to be in?","") in list ("","Not Gryffindor!","Not Ravenclaw!","Not Hufflepuff!","Not Slytherin!","I dont mind"))
if("Not Gryffindor!")
if(prob(33))
view() << "<b><font size = 3><font color = yellow> Hufflepuff!"
else if(prob(33))
view() << "<b><font size = 3><font color = blue> Ravenclaw!"
else if(prob(34))
view() << "<b><font size = 3><font color = green> Slytherin!"

else if("Not Ravenclaw!")
if(prob(34))
view() << "<b><font size = 3><font color = yellow> Hufflepuff!"
else if(prob(33))
view() << "<b><font size = 3><font color = red> Gryffindor!"
else if(prob(33))
view() << "<b><font size = 3><font color = green> Slytherin!"
else if("Not Hufflepuff!")
if(prob(34))
view() << "<b><font size = 3><font color = red> Gryffindor!"
else if(prob(32))
view() << "<b><font size = 3><font color = blue> Ravenclaw!"
else if(prob(33))
view() << "<b><font size = 3><font color = green> Slytherin!"
else if("Not Slytherin!")
if(prob(33))
view() << "<b><font size = 3><font color = yellow> Hufflepuff!"
else if(prob(34))
view() << "<b><font size = 3><font color = blue> Ravenclaw!"
else if(prob(33))
view() << "<b><font size = 3><font color = red> Gryffindor!"
else
if(prob(26))
view() << "<b><font size = 3><font color = red> Gryffindor!"
else if(prob(26))
view() << "<b><font size = 3><font color = yellow> Hufflepuff!"
else if(prob(24))
view() << "<b><font size = 3><font color = blue> Ravenclaw!"
else if(prob(24))
view() << "<b><font size = 3><font color = green> Slytherin!"
else if("No")
usr << "<b><font size = 2><font color = black>If you are not ready, come back another time then!"


Problem description:
I am creating a Harry Potter game, and I am using the prob function for the Sorting Hat(It gives you a random house). For this verb I am using the prob proc, and sometimes it does not give me a result,sometimes it gives me more than 1 result, and sometimes it gives me the house that isn`t even listed inside it.
Tests: If I select "Not Hufflepuff" it could give me Hufflepuff as a result, or it can give me both Slytherin and Ravenclaw at the same time.

Could anyone help me out with this problem?

Thank you.

Well I didn't like the setup of how you had it so I tweaked a good portion of it, simplifying it down.

Make sure you read the comments where I placed them:
obj
Sorting_Hat
icon = 'randoms.dmi'
icon_state = "SortingHat"
density = 1

var/tmp/list
Houses = list("Gryffindor"="red", "Slytherin"="green", "Hufflepuff"="yellow", "Ravenclaw"="blue") // A list with the entries being the House names and their values being the House colours
PlayersUsing = list() // You want to make sure that a person does not call this twice. /tmp makes this variable unsavable.
verb
Get_Sorted()
set src in oview(1)
if(usr in PlayersUsing || usr.House) // Be sure to check if a person is already sorting or has been sorted. If so, stop this from happening
usr << "You are already [usr.House? "sorted in to [usr.House]" : "sorting"]" // X?Y:Z is a compact if() statement

src.PlayersUsing += usr // Add the person to the sorting list
if("No" == alert("Are you sure you want to get sorted?","","Yes","No")) // If the person doesn't want to be sorted, remove them from the list and return to stop the rest from happening
src.PlayersUsing -= usr
return

// The person has chosen Yes for the following to happen since No has stopped above

var/DoNotWant = input("Do you have any specific house you do NOT want to be in?","NOT be in...") as null|anything in src.Houses // null| will add a cancel button which will return null
usr.House = pick(src.Houses - DoNotWant) // Remove the house the person does not want to be in (if any) and pick a random house
view() << {"[usr.name] is now in... <b><font size="+3" color=[src.Houses[usr.House]]> [usr.House]!</font></b>"} // {"..."} escapes quotes :) Without these, for +3, You would have to do: \"+3\"
src.PlayersUsing -= usr


Let me know if you have any questions of what was done. For the font color portion, see the Houses variable definition... which was list(House = Colour).

When you access lists/arrays, you have: list(Entry1 = Value1, Entry2 = Value2, Entry3, ...). For Entry3, because Value3 was not defined, it is set to null.

To access the value of the entry, you must do: List[Entry]. So, for example, Houses["Syltherin"] will return "green".
One thing I forgot to mention is WHY you were having that issue.

switch() is unique in that EACH possibility MUST be JUST "if". The "else" is the final keyword, terminating the switch.

So, for example, yours should have been:
switch(...)
if("Not Gryffindor!")
...
if("Not Ravenclaw!")
...
if("Not Hufflepuff!")
...
if("Not Slytherin!")
...
else
...



So what happened when you used "else if()"? This:
switch(...)
if("Not Gryffindor!")
...
else
if("Not Ravenclaw!")
This will always happen
else if("Not Hufflepuff!")
This will NOT happen
else if("Not Slytherin!")
This will NOT happen
else
This will NOT happen
So why would Ravenclaw happen but nothing else? It's because the if() is evaluating the statement as TRUE (FALSE being 0, "" or null)

Because you are doing else if(), the other statements will not happen; simply because Not Ravenclaw was evaluated as true.
Best response
Issue with sometimes not being selected

prob()

If I have four balls (3 green, and 1 red) in a bag, and I use prob(25), then there is 1/4 chance of getting the red ball. If I pull a green, next it is a 1/3 chance [prob(33.3)] of getting the red. If I pull another green, I now have two balls, with 1 green (1/2, or 50%), so the last one must be a red.

Now why does this matter? Consider the following:
if(prob(25))
first red
else if(prob(25))
second red
else if(prob(25))
third red
else if(prob(25))
fourth red
else
//wait, wut? no red balls?


This leaves the chance at 1/4 for each pull. Therefore, you're putting the ball you pulled out back in the bag. This condition is being reached for no houses found.
@GhostAnime, @Pirion Thank you for both of your responses, it really clarified some stuff for me. Thank you Pirion for the great metaphor i guess, really helped me understand my problem. and Thank you GhostAnime for your example and all the commenting. You showed me a few stuff that I did not know. and also clarifying where I was wrong. I really appreciate it guys. Thank you

Puzzle