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
  #16  
Old 07-04-2012, 11:03 PM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Quote:
Originally Posted by Tigairius View Post
It works fine, and the class is available immediately. The only time I have problems is when I join a class to an object that's already been created, but in my example, it's being joined upon creation.
Joining classes on clientside requires a round-trip to the server; it's not immediately available, although you can use it immediately (in v6). For example:

Class "test":
PHP Code:
//#CLIENTSIDE
public function test() {
  return 
"it works!";

Weapon "test":
PHP Code:
//#CLIENTSIDE
function onCreated() {
  
temp.start timevar2;
  
  
temp.obj = new TStaticVar();
  
temp.obj.join("test");
  echo(
"result: " temp.obj.test());
  
  echo(
"total time: " @ (timevar2 temp.start));

On a low-latency network, the delay is generally tolerable:
Quote:
result: it works!
total time: 0.108752069
On an (artificially) high-latency network, however, it becomes a real problem:

Quote:
result: it works!
total time: 0.901618003
This can be very problematic depending on the situation: the best case is that nothing happens for a second, the worst is that the player's left with a half-drawn interface on the screen while the class is fetched.

And even worse, on v5:

Quote:
result: 0
total time: 0.000670057
v5 doesn't even wait for the class -- and 32% of Era is still using v5 right now.

An easy fix is to join the class serverside before joining it to any objects clientside:

PHP Code:
function onCreated() {
  
this.join("test");
}

//#CLIENTSIDE
function onCreated() {
  
temp.start timevar2;
  
  
temp.obj = new TStaticVar();
  
temp.obj.join("test");
  echo(
"result: " temp.obj.test());
  
  echo(
"total time: " @ (timevar2 temp.start));

Now your clientside class works on v5 and v6, and without waiting for the network .
__________________
Reply With Quote
  #17  
Old 07-04-2012, 11:11 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
I share Chris' experience with loading classes on clientside, and even had to write a work around for it:

PHP Code:
//#CLIENTSIDE
function onCreated()
{
//echo("Classes:" SPC player.joinedclasses);
//return;
  
temp.classList = {
    
"functions_buffs",
    
"functions_items",
    
"functions_messages",
    
"functions_misc",
    
"functions_stats",
    
"functions_skills",
    
"gui_initializer",
    
"gui_basics",
    
"gui_buff",
    
"gui_item",
    
"gui_skill",
    
"gui_spell",
    
"player_system",
    
//"quest_npc"
  
};
  
  for (
temp.classNametemp.classList) {
    
// Load the class to the player
    
if (!player.isInClass(temp.className))
      
player.join(temp.className);
    
    
// Maybe the class is loaded already?
    
if (isClassLoaded(temp.className))
      continue;
    
    
loadClass(temp.className);
    
    while (!
isClassLoaded(temp.className))
      
sleep(0.05);
  }
  
  
triggerServer("gui"this.name"initialized");

Causes a 1-5 second delay in our "login level" depending on your latency when you first login during the session, but it's worth not getting any errors because of classes not having loaded yet.
__________________
Follow my work on social media post-Graal:Updated august 2025.

Last edited by xXziroXx; 07-05-2012 at 07:02 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 08:58 AM.


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