ID:160047
 
I'm trying to put all my races in a list and make them equal to a number, so when they pick the number they will select the race.

Help...?
mob/verb/Pick_Number()
var/list/Pick = list("One" = "Race1", "Two" = "Race2") // Create the associative list
var/a =input("Pick your race") in Pick // input the list to the player
race = Pick[a] // makes his race, the associated value of what he picked in the list.
In response to Andre-g1
You could have it index based, and use actual numbers instead of using an associative list.
In response to Kaioken
Indeed, but is there a difference ? Since both just exist during the duration of the proc.
In response to Andre-g1
Well, it's simpler and more efficient. It also uses actual numbers instead of text strings.
In response to Kaioken
Show me an example..
In response to Lundex
//Andre-G1's edited code
mob/verb/Pick_Number()
var/list/Pick = list("Race1","Race2") // Create the list
var/a = Pick.Find(input("Pick your race") in Pick) // input the list to the player
race = Pick[a] // makes his race, the associated value of what he picked in the list.


a would be equal to the index of what the player selects. It would be a lot easier to cut out the Find() and association altogether and say race = input() instead, though.
In response to Lundex
mob/verb/Pick()
var/list/List= list("Race1","Race2","Race3")
var/index = input("Choose race") as null|num
race = List[index]


I think something like this is what he meant.
In response to Lundex
The method I said uses a regular list by using the position/order of the items in the list to access them. You could build a list with the available numbers to use and use it as a choices list in input(), or have the player type a number (and then check if it's valid).
In response to Andre-g1
Yeah, that's right. Though you have to check if the player typed in a correct number.
In response to Kaioken
I have a question about something like that to be honest.

Would it work if I did something like:

if(index in(1 to 3))


Hum ?
In response to Andre-g1
Yes, that's valid syntax (and you don't need the parentheses). Basically a shortcut for a range check, you could also use the >=,&&,<= operators of course.