Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Object transfering (https://forums.graalonline.com/forums/showthread.php?t=81370)

The_Kez 08-21-2008 08:11 PM

Object transfering
 
I've heard of this problem before but I've never actually had to deal with this before until now; I have a mudlib that I'm creating and I'm having problems transferring the info from the server to the client.

I've tried a couple ways to get around this: setting the object as a player.attr which didn't work. I've tried saving the object vars to an array and transfering the array, but for some reason that didn't work either, maybe it was something wrong with my coding.

This is my function which returns a player's mud file:

PHP Code:

public function loadMudFileacct ) {
  
temp.e.loadvarsgetAccountPath(acct) );
  for ( 
temp.e.getDynamicVarNames() ) {
    if ( 
i.tokenize("_")[2] > 9999 || i.starts("spells_") ) {
      
temp.objnum++;
      
makevar"temp.obj" objnum ) = new TStaticVar();
      
makevar"temp.obj" objnum ).loadvarsfromarray(e.( @ ));
      
temp.("obj" objnum).addtemp.playeritems );
    }
  }
  
temp.= new TStaticVar();
  for ( 
temp.i=1temp.i<=objnumtemp.i++ ) {
    
makevar"temp.e.item" ) = makevar"temp.obj" );
  }
  return 
e;


So it loads each item into a tstaticvar, then creates a tstaticvar that holds each item as a subvariable. So to return an item stat I can say:

PHP Code:

temp.items loadMudFileplayer );
echo( 
items.item1.displayname );
echo( 
items.item4.range ); 

The problem like I said is just taking the info and getting it to the clientside. To do that I tried this:

PHP Code:

  temp.items loadMudFileplayer.account );
  for ( 
temp.items.getDynamicVarNames() ) {
    
temp.objnum++;
    
makevar"temp.arry" objnum ) = makevar"temp.items." ).savevarstoarray(0);
    
temp.("arry" objnum).addtemp.itemxfer );
    echo( 
temp.("arry" objnum) );
  }
  
triggerClient"gui" name "pullMUDclientside" itemxfer ); 

savevarstoarray is woking just fine. But when I take the arrays and add them into itemxfer, the info just seems to get lost. If anyone has any ideas on what's wrong or a better way to do it that'd be great ^^

xXziroXx 08-21-2008 08:24 PM

PHP Code:

  temp.items loadMudFileplayer.account );
  
temp.items temp.items.savevarstoarray(false);
  
  
triggerClient"gui" name "pullMUDclientside"temp.items);

//#CLIENTSIDE
function onActionClientSide()
{
  if (
params[0] == "pullMUDclientside"this.items.loadVarsFromArray(params[1]);


Should work flawlessly.

Admins 08-21-2008 08:24 PM

I would stick to loadvars()/savevars() and loadvarsfromarray()/savevarstoarray(), not using those getdynamicvarnames() stuff, like ziro said.

Your code also contains a lot of undefined stuff (temp.playeritems, temp.itemxfer are never assigned a value) so it's not easy to help

The_Kez 08-21-2008 08:55 PM

It seems to be a problem with the savevarstoarray command.

PHP Code:

temp.items loadMudFileplayer.account );
temp.temp.items.savevarstoarray(0);
player.chat t[0]; 

That returned nothing. I also tried simply

PHP Code:

temp.items.savevarstoarray(0); 

I'm starting to think that maybe I can't use savevarstoarray on an object who's subvariables are also objects.

Inverness 08-21-2008 09:15 PM

Quote:

Originally Posted by The_Kez (Post 1416314)
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();
  }



The_Kez 08-21-2008 09:18 PM

Yeah. That's why my first attempt was to use getdynamicvarnames to save the subvariables of each item but I'm still not sure why that isn't working.

Ohh that helps I see how I can get it to the client now. I like the idea of defining player.mud better then what I did also ^^


All times are GMT +2. The time now is 09:41 PM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.