ID:162850
 
I have a list

mob/var/upgrade = list(1="204",2="420",3="800")

(There are alot more values than this)

How would I input 1 and get 204, input 3 and get 800 ect. without using

if(input = 1)
//do this
else if(input = 3)
//do this

//or
switch(input)
if(1)
//do this
if(2)
//do this
upgrade[1] will recall the FIRST POSITION of the list (numbers don't work well as identifiers in lists, as DM will think it is the position you want rather than the value).

mob/var/upgrade = list(1="204",2="420",3="800")

mob.upgrade[1] will return "204" // I think... or it'll the number 1... I forgot
mob.upgrade[2] will return "420"
mob.upgrade[3] will return "800"

mob/var/upgrade = list(1="204",200="420",2="800","X"=222)

mob.upgrade[1] will return "204"
mob.upgrade[200] will give you an out-of-bound error (it's looking for the 200th position in the list, which doesn't exit
mob.upgrade[2] will return "420", not "800", as mentioned before that it is looking for the position not the identifier
mob.upgrade[4] will return "X" (the identifier will be returned instead of the placed value... I think)
mob.upgrade["X"] will return 222
KingCold999 wrote:
I have a list

mob/var/upgrade = list(1="204",2="420",3="800")

(There are alot more values than this)

If you define an associative list like this, it isn't actually an associative list. Instead, what you get is just <code>list("204", "420", "800")</code>

How would I input 1 and get 204, input 3 and get 800 ect. without using

> if(input = 1)
> //do this
> else if(input = 3)
> //do this
>
> //or
> switch(input)
> if(1)
> //do this
> if(2)
> //do this
>


Because what you have isn't an associative list, you just have to use upgrade[input] to the (input)th entry in upgrade.
You don't need an associative list there, because everything is ordered mathematically already :-) ! Ordered lists are generally for when you need references, like:

var/orders = list(Jerry="Coke",John="Dr. Pepper",Josh="Mt. Dew")


In this case it's helpful because you are associating values with important identifiers. You want to be able to ask, "What does Jerry want?", "What does John want?", etc and get an answer back.

Your list is much too efficient to need that! You decided that you only need things in a simple and logical order:

1: 204, 2: 420, 3: 800. Your list can be as simple as

var/upgrade = list("204","420","800")


The only question you can ask a list like this is, "What is the 1st item?", "What is the 5th item?", etc. But this is exactly what you seem to want here. To do that:

usr << "Upgrade level one costs: [upgrade[1]]"
usr << "Upgrade level five costs: [upgrade[5]]"


list[#] is a reference to the item in the # slot you ask for.

I'm not quite clear on what you mean by "input" but hopefully this is enough of the basics to give you what you need.