ID:2147160
 
Code:
mob/var
Char[3]
Stat
HP = 100
Str = 1
Def = 1


Problem description:
I want to create a nested variable (don't know if that's the proper term) if possible.... for instance this makes an array of 3 characters in a players party (rpg-like party).


but this doesn't work correctly I cannot access usr.Char[1].Stat.HP as it doesn't exist.

Is there a way to define this type of variable/array?

Thanks for helping a newbie! This isnt documented at all in DM guide so I'm lost.
As for as I know you can't access variables directly through an array, but you can store the array element in a variable that can access those variables.
mob
var
list/Char[3]
HP = 100
Str = 1
Def = 1
mob
verb
CheckParty()
for(var/i in 1 to 3)
var/mob/M=Char[i]
if(M)
src<<"[M] HP is [M.HP]"
src<<"[M] STR is [M.Str]"
src<<"[M] Def is [M.Str]"
And this will store different HP/Str/Def variables for each Char[x]?

I will test it either way just curious and thanks :)
Yes Char[3] is an array of 3 separate elements. The array is empty, you will have to fill them of course.

So Char[1]=Player1
Char[2]=Player
etc

So each element is different and which means their variables have different values.
Defining the list as Char[3] means that it will always be initialized, for every mob, in a hidden init proc. This is not good. You only want this list for certain mobs, and even then you won't need it instantly. You should just define it as var/list/Char, and only create the list once you're ready to use it.
Yeah he makes a good point. You only want to initialize list on objects you know that will utilize it or you will be using excessive resources. I once defined an array of like 20 on an atom, and it was one of the worst things Ive ever done. Not only that it was extremely difficult to pinpoint what I did wrong.