ID:160177
 

ADD_Var(mob/M as mob in world)
set category = "Add Admin"
var/X = input("Which var?","Var") in M.vars
var/N = input("Add how much to [X]") as num
M.X+= N
usr<<"You Added [N] [X] to [M]"


is there a way to make this work? I'm missing how to allow M.X?
Kylemark wrote:
ADD_Var(mob/M as mob in world)
set category = "Add Admin"
var/X = input("Which var?","Var") in M.vars
var/N = input("Add how much to [X]") as num
M.X+= N
usr<<"You Added [N] [X] to [M]"

is there a way to make this work? I'm missing how to allow M.X?

Variable names accessed via the . operator must be identifiers, not non-constant values like text strings. In order to use a non-constant value to access a variable, you can use the vars list.
ADD_Var(mob/M as mob in world)
set category = "Add Admin"
var/X = input("Which var?","Var") in M.vars
var/N = input("Add how much to [X]") as num
var/old_value = M.vars[X]
old_value += M
M.vars[X] = old_value
usr<<"You Added [N] [X] to [M]"
In response to IainPeregrine
Note associative lists do support just doing List[key] += num and as such directly.