Quote:
Originally Posted by Tigairius
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

.