How to output properties and values in a player class

Started by PSL, Today at 07:56 AM

Previous topic - Next topic

PSL

How to output properties and values in a player class?
        if(cmd=="getglobal")
{
MessagePlayer("[#00FF00]Your Global: ",player);
foreach(i,j in state[player.ID])
{
MessagePlayer("[#00FF00]"+i+" = "+j,player);
}
}


AN ERROR HAS OCCURED [_nexti failed]

CALLSTACK
*FUNCTION [onPlayerCommand()] store/main.nut line [1173]

LOCALS
[j] NULL
[i] NULL
[text] NULL
[cmd] "getglobal"
[player] INSTANCE
[this] TABLE

habi2


PSL

Hi Habi, This is a class that I've defined to store the current state of a player in an array, and now I want to quickly print out the properties and values of a player's class
class PlayerClass
{
constructor(id)
{
DefaultName=::FindPlayer(id).Name;
splayer=::FindPlayer(id);
}

DefaultName=null;
splayer=null;
DiePos=null;
Vehlist=[];
PickPickupID=null;
NearObjPos=null;
AddObjName=null;
AutoAngle=false;
CreateMode="Cross";
IsFirstSpawn=false;
EditObj=null;
AutoCreateSave=false;
}
function onScriptLoad()
{
state<-array(101,null);
}
function onPlayerJoin(player)
{
state[player.ID]=PlayerClass(player.ID);
}
function onPlayerPart(player,reason)
{
state[player.ID]=null;
}

habi2

foreach(a,b in state[player.ID].getclass())  //get the class of instance
    print( a+ " "+state[player.ID].rawget(a) )  //instance.rawget works !