ID:168070
 
I'm wanting to know how to use some form of list for a situation I'm about to describe, if at all possible.

So, say in example I want to call a list to add something to the variables described in the list, adding the values the variable holds.

var/list/LevelUp=list("HP"=(algorithm),"MP"=(algorithm))
mob
var{HP,MP}
proc/LevelUp()
//something to call LevelUp variable to distribute statistics
Are you trying to change mathematical equations at runtime by placing an aglorithm in a list?

Well, I'm not quite sure you can do that. However, you can make a algabraic equation based on variables the player has and such. That hard part is actually finding an equation that suits you.
In response to CaptFalcon33035
No, what I'm trying to do, say for example, is do something to call a list with a format like "HP"=(somealgorithmformultiplyinghponlevelup) then compare each text string in the list with the variables that the atom it's called by contains, and if a match is found, add the =(algorithm) bit to the variable, say as an alternative for in a typical BYOND RPG to doing something like;
 if(somerace)
long.10.line.block.of.variable.addition
if(anotherrace)
same.thing.as.above
In response to Artemio
So as to give a player some extra stats if that player has reached a certain level in the variable you are comparing?
In response to CaptFalcon33035
I really can't get any clearer than what I said, but maybe this, as an example;


for(var/A in typesof(/mob/var))
if(LevelUps.Find("[A]")) A+=valueforA'spositioninLevelUps


Or something like that.
If I understand what you mean, then you can use AbyssDragon's SET library to parse text as equations. You then can just replace the variable with a number.

var/list
LevelUp = list("HP" = "2*(str)", "MP" = "2*(int)")

proc
expr(n)
return text2num(SET(n))

replacetext(t, f, r)
var/newtext = t
while(1)
var/i = findtext(newtext, f)
if(!i) break
newtext = copytext(newtext,1,i-1) + r + copytext(newtext, i+length(r))
return newtext

mob
var
HP
MP
str
int

proc/LevelUp()
for(var/i in LevelUp)
var/alg = LevelUp[i]
for(var/j in src.vars)
while(findText(alg, j))
alg = replacetext(alg, "([j])", src.vars[j])
var/increase = expr(alg)
src << "Your [i] has increased by [increase]!"
src.vars[i] += increase


~~> Unknown Person
Unknown Person's suggestion will work, although it's a mystery why you'd need those formulas to be set at runtime. Why couldn't the calculations for HP and MP be hardcoded?

Lummox JR