PDA

View Full Version : Objects in player.attr?


JkWhoSaysNi
03-04-2007, 05:19 PM
Is there any reason why objects cant be stored in player.attr?

For example using my associative array class (http://forums.graalonline.com/forums/showthread.php?t=68643)


test = new TStaticVar();
test.join("assocarray");
test.make({"a","b","c"},{"one","two","three"});

player.attr[8] = test;
player.chat = player.attr[8].item("a");


Doesn't work.

or


player.attr[8]= new TStaticVar();
player.attr[8].join("assocarray");
player.attr[8].make({"a","b","c"},{"one","two","three"});
player.chat = player.attr[8].item("a");


Also doesnt work.

Replacing player.attr[8] with a standard var name there works fine.

Is there any reason objects cant be stored in player.attr?


What i'm trying to do is work out how I can store objects between logins.

I want to make objects persistent. I can't store them in clientr.


The only way I think I can do it is storing the objects in a DB NPC with the player account. However, this seems kinda wasteful because the info on the player would be in memory in the DB NPC when the player is not even online.

Skyld
03-04-2007, 05:20 PM
I think attr[]s are only capable holding strings.

JkWhoSaysNi
03-04-2007, 05:38 PM
Is there any way to store objects between logins then?


I could serialise the object but I intend to have a tree like structure of objects (in proper OO fashion) so going through each object and storing all the value would be kinda annoying.

Admins
03-04-2007, 07:29 PM
attr[] are built-in attributes which can only store strings, right. The engine is currently not serializing objects automatically. You have functions like savevarstoarray(sort), but it's not saving object links or recursive stuff.

Chandler
03-04-2007, 07:48 PM
attr[] are built-in attributes which can only store strings, right. The engine is currently not serializing objects automatically. You have functions like savevarstoarray(sort), but it's not saving object links or recursive stuff.

Would you mind changing player.attr so that it doesn't just support strings?