ID:141248
 
Code:
mob
var/list/Bark_Acs=list(1="One",2="Two")//etc
var/list/Vilz_Acs=list(1="Nine",2="Eight")//etc
var/Which_L = "Bark"
var/Which_N = 1
verb/GetWhich()
src << vars["[Which_L]_Acs\[[Which_N]\]"]


Problem description:

I am trying to show the user the value of the variable that begins with either "Bark" or "Vilz", whichever Which_L is equal to (which in this case would be One for Bark or Nine for Vilz)

Am I doing this right? Or is there another way?
KingCold999 wrote:
Am I doing this right?

No. The expression
"[Which_L]_Acs\[[Which_N]\]"

Will evaluate to the (final) text string "Bark_Acs[1]". This means you're effectively trying to use vars like this:
src << src.vars["Bark_Acs\[1\]"]

This attempts to output a var of src which is named "Bark_Acs[1]", but no such var exists (since it's just a text string, [] has no special meaning...). What you wanted was to access the text string in the "Bark_Acs" list first, which is supposedly a var name (e.g. "One"), then use that in vars so you get that var's value.

You're also using associative lists incorrectly. Keys/elements that are numbers can't have associated values, as when you use a number in square brackets ([]) you're accessing using an index (to get a specific positioned element in the list), so you're not going to get any associated value of anything, even if it exists. In other words, List[1] will always return the first item in List (or if there isn't an item (or a list), it will cause an error). The fact you've tried to use an associative list in this way seems to indicate you don't understand lists correctly, as, as I've just said, you don't need an associative list to access a list item by its position. That is available with all lists - they'd be useless if it wasn't.
In summary, here's what it should actually have looked like:
mob
var/list
List_One = list("a_var","b_var","c_var")
List_Two = list(whatever)
var
a_var = 10
b_var = 20
c_var = 30

use_list = "One"
...
var/list_var_name = "List_[src.use_list]"
var/list/L = src.vars[list_var_name]
var/wanted_var_name = L[1] //access the first element in the list
src << src.vars[wanted_var_name]

For clarity, here's how that code would look like with its runtime values while being executed:
var/list_var_name = "List_One"
var/list/L = src.vars["List_One"]
var/wanted_var_name = "a_var"
src << 10

I wonder if this is the right (or even a good) way to design whatever you're trying to do here, though.
In response to Kaioken
Thanks for the help. I found an easy way of doing this because of you're examples :D