var/list/stats = list("str", "dur", "res", "off", "def", "spd", "frc", "energy")
mob
verb
Train()
set waitfor = FALSE
set category = "Skills"
usr << output("You have attempted to train.","chat")
if(stopState())
return FALSE
if(state != STATE_TRAINING)
state = STATE_TRAINING
state2 = NULL_STATE
icon_state = "Training"
else
nullState()
training = FALSE
while(state == STATE_TRAINING)
if(energy <= 5)
training = FALSE
usr << output("You have run out of energy.","chat")
nullState()
else
usr << output("You are training and have [energy] energy.","chat")
training = TRUE
energy -= 5
var/stat = pick(stats)
if(stat == "energy")
maxEnergy += (maxEnergy / 100) * energyGain
else
// Add to other stat.
sleep(50)
Problem description:
Currently, I have the above code. I'd like a user's stat to be added to depending on which was picked from the list. How would I do so? Originally, I thought [stat] += 1 would work, but it does not.
Ignore the sloppy state code, I'll be changing that so that it just calls a proc (similar to Ter13's method) and changes based on passed variables.
The other way would involve associating the list items in stats with the actual var name of the stat and using that.
Personally, I'd avoid both of these methods because they both involve using the vars list, which can be slow to access. A better option would be to organize mob stats using a list as opposed to using separate variables.