ID:2841666
 
(See the best response by Albro1.)
I'm currently trying to learn how to use lists, but I'm having trouble understanding how to output a specific value.

mob
var
list/mob_values = new

verb
TestA()
set name = "SetValues"
usr.mob_values.Add("HP",50)
usr.mob_values.Add("Off",10)
usr.mob_values.Add("Dex",5)
usr << output ("Values have been set.","debug")

TestB()//Idk what to do here
set name = "ReadHP"
usr << output ("HP: [idk].","debug")


I would just like to output the HP.
You're adding both strings and ints with your current method.

Essentially, your list will look like
mob_values = list("HP",50,"Off",10,"Dex",5)

To make an associative list, you need to make use of [].
mob_values["HP"]=50
mob_values["Off"]=10
mob_values["Dex"]=5
src << "HP: [mob_values["HP"]]"
//or if you want to debug all values
for(var/x in mob_values)
src << "[x]: [mob_values[x]]"
Best response
Two main ways you'll probably want to tackle this:

The first method is to assume that the HP value will always be the first value in the list. If so, you can output it like this:
usr << output("HP: [usr.mob_values[1]]", "debug")


The second method is to use associative lists:
mob
var
list/mob_values = new

verb
TestA()
usr.mob_values["hp"] = 50
TestB()
usr << output("HP: [usr.mob_values["hp"]]", "debug")


Looks like you're trying to make associative lists, but the Add() proc adds each argument as its own item, not as associated items.
This seems like a strange place to use lists.
Feels like something that would be better handled using just like, variable on /mob
I guess if you're practicing with lists it makes sense, but this isn't really a good usecase
In response to LemonInTheDark
LemonInTheDark wrote:
This seems like a strange place to use lists.
Feels like something that would be better handled using just like, variable on /mob
I guess if you're practicing with lists it makes sense, but this isn't really a good usecase

I could see it all being encapsulated under a character sheet sorta datum, if you were averse to saving atoms.

I do something similar to what OP is doing in some of my projects though, except instead of storing the final stat value in a list, I store it as a variable, and the stat list is more for storing temporary buffs to a variety of stats tied together in a list to a unique-id for reversibility reasons.
Okay! I see what I'm doing wrong. Thanks a lot for all your replies.