ID:140442
 
Code:
var
level
mexp
list
M = list()
proc
hstat_update()
M.mexp = M.level*100


Problem description:
whats going on is, i have a list of mobs and global variables, im trying to update the global variable of the units in that list. no matter what ive tried for the last hour i cant seem to "define" my variable here, any help is appreciated. im not sure if i havent properly defined level and mxep or if my referencing is incorrect
I think I understand what your trying to do...

Are you trying to do this?

mob
var
level
mexp
var
list
Units = new
proc
hstat_update()
for(var/mob/M in Units)
M.mexp = M.level*100
Even though Chowder may have solved your problem. I think it's important to know what went wrong and exactly what is going on (so that you remember how to fix this next time).

You're trying to access a variable from another variable. Which doesn't make sense. This an object oriented language, everything's based on inheritance.

Cat/var
scratch_strength
leeping_level

Cat
Scratch()

Leep()


What you did was basically "scratch_strength.leeping_level". Scratch_strength does not inherit leep_leveling, they're both children of the parent Cat.

To access properties from another tree where there is no inheritance (under other trees that aren't under Cat) we'd do...
Cat.scratch_strength or Cat.Scratch()

Which also means for the two to even be referenced(again, outside of Cat) or compared you'd have to reference them from "Cat".
Cat.scratch_strength && Cat.leeping_level
In response to Hulio-G
That entire post is wrong. I'd suggest anybody who just read it to ignore it.

The issue is that he was trying to access a variable from a list object which lists do not have. To use your example, it would be like trying to access a Cat's barkiness variable. It does not exist. Hence, undefined variable.
In response to Chowder
thanks, yeah thats what i was trying to do, it works now, i was trying to make my code work without the for statement because i didnt understand what it did but now i do