Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 08-21-2008, 08:11 PM
The_Kez The_Kez is offline
N-Pulse Asst. Manager
The_Kez's Avatar
Join Date: Dec 2007
Posts: 106
The_Kez is on a distinguished road
Send a message via MSN to The_Kez
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
Reply With Quote
  #2  
Old 08-21-2008, 08:24 PM
xXziroXx xXziroXx is offline
Malorian
xXziroXx's Avatar
Join Date: May 2004
Posts: 5,289
xXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant future
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.
__________________
Follow my work on social media post-Graal:Updated august 2025.
Reply With Quote
  #3  
Old 08-21-2008, 08:24 PM
Admins Admins is offline
Graal Administration
Join Date: Jan 2000
Location: Admins
Posts: 11,693
Admins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud of
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
Reply With Quote
  #4  
Old 08-21-2008, 08:55 PM
The_Kez The_Kez is offline
N-Pulse Asst. Manager
The_Kez's Avatar
Join Date: Dec 2007
Posts: 106
The_Kez is on a distinguished road
Send a message via MSN to The_Kez
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.
Reply With Quote
  #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
  #6  
Old 08-21-2008, 09:18 PM
The_Kez The_Kez is offline
N-Pulse Asst. Manager
The_Kez's Avatar
Join Date: Dec 2007
Posts: 106
The_Kez is on a distinguished road
Send a message via MSN to The_Kez
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

Last edited by The_Kez; 08-21-2008 at 09:44 PM..
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 04:44 PM.


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