View Single Post
  #5  
Old 08-21-2008, 09:15 PM
Inverness Inverness is offline
Incubator
Inverness's Avatar
Join Date: Aug 2004
Location: Houston, Texas
Posts: 3,613
Inverness is a jewel in the roughInverness is a jewel in the rough
Quote:
Originally Posted by The_Kez View Post
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.iplayer.mud.items) {
      
temp.part = {};
      for (
temp.ethis.clientvars) {
        
temp.part.add(temp.i.(@ temp.e));
      }
      
temp.out.add(temp.part);
    }
    
this.clientfunction2(null"onRecieveItems"player.mud.calculatetimethis.clientvarstemp.outplayer.mud.gold);
  }
}
//#CLIENTSIDE
public function requestitems() {
  
this.serverfunction2(null"onRequestItems"staticdata.invcalculatetime);
}
public function 
clearitems() {
  for (
temp.staticdata.invitems.size() - 1temp.> -1temp.--) {
    if (
staticdata.invitems[temp.i].type() == 2) {
      
staticdata.invitems[temp.i].destroy();
    }
  }
  
staticdata.invitems = {};
}
function 
onRecieveItems(calculatetimevarsitemsgold) {
  
this.clearitems();
  
staticdata.invcalculatetime temp.calculatetime;
  
staticdata.invitemscount temp.items.size();
  
staticdata.invvars temp.vars;
  
staticdata.invgold temp.gold;
  for (
temp.0temp.temp.items.size(); temp.++) {
    
temp.item = new TStaticVar("InventoryItemData" temp.i);
    for (
temp.0temp.temp.vars.size(); temp.++) {
      
temp.item.(@ temp.vars[temp.e]) = temp.items[temp.i][temp.e];
    }
    
staticdata.invitems.add(temp.item);
  }
  if (
client.inventoryopen) {
    
this.refreshall();
  }

__________________
Reply With Quote