Quote:
Originally Posted by The_Kez
I'm starting to think that maybe I can't use savevarstoarray on an object who's subvariables are also objects.
|
You can't.
Variables are saved to array like {"varname=value", "varname2=value"} meaning its a string and if the value can't be represented as a string its not going to work.
Perhaps if it did {{varname, value}, {varname2, value2}} instead that would be possible as long as you didn't convert array to string, but you still can't send objects to client.
I never use savevarstoarray() for sending item data to client because that means the amount of data sent would be a lot larger than it needs to be. I put it in a format like:
{{varname1, varname2}, {value1, value2}, {value1-2, value2-2}, {value1-3, value2-3}}
When the data gets to client new objects are created.
Here is code snippet from Inventory:
PHP Code:
public function config() {
this.clientvars = {
"number",
"equipped",
"fullname",
"totalweight",
"type",
"icon",
"value",
"weight",
"questitem",
"slot",
"id",
};
}
function onCreated() {
this.config();
this.join("util_triggercontrol");
this.join("util_catchevent2");
}
function onMudPlayerObjectCalculated(obj) {
with (temp.obj.graal) {
if (client.inventoryopen) {
this.trigger("RequestItems", 0);
}
}
}
function onRequestItems(clienttime) {
if (temp.clienttime < player.mud.calculatetime || player.mud.calculatetime == null) {
temp.out = {};
for (temp.i: player.mud.items) {
temp.part = {};
for (temp.e: this.clientvars) {
temp.part.add(temp.i.(@ temp.e));
}
temp.out.add(temp.part);
}
this.clientfunction2(null, "onRecieveItems", player.mud.calculatetime, this.clientvars, temp.out, player.mud.gold);
}
}
//#CLIENTSIDE
public function requestitems() {
this.serverfunction2(null, "onRequestItems", staticdata.invcalculatetime);
}
public function clearitems() {
for (temp.i = staticdata.invitems.size() - 1; temp.i > -1; temp.i --) {
if (staticdata.invitems[temp.i].type() == 2) {
staticdata.invitems[temp.i].destroy();
}
}
staticdata.invitems = {};
}
function onRecieveItems(calculatetime, vars, items, gold) {
this.clearitems();
staticdata.invcalculatetime = temp.calculatetime;
staticdata.invitemscount = temp.items.size();
staticdata.invvars = temp.vars;
staticdata.invgold = temp.gold;
for (temp.i = 0; temp.i < temp.items.size(); temp.i ++) {
temp.item = new TStaticVar("InventoryItemData" @ temp.i);
for (temp.e = 0; temp.e < temp.vars.size(); temp.e ++) {
temp.item.(@ temp.vars[temp.e]) = temp.items[temp.i][temp.e];
}
staticdata.invitems.add(temp.item);
}
if (client.inventoryopen) {
this.refreshall();
}
}