Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Passing Objects (https://forums.graalonline.com/forums/showthread.php?t=66456)

KuJi 06-04-2006 08:22 PM

Passing Objects
 
How can you pass an object from clientside to serverside and serverside to client?

IE:
hotel.test=wow
hotel.test2=wow2
hotel.test3=wow3

How could I send the hotel object to serverside aswell as clientside :p

Warcaptain 06-04-2006 08:43 PM

I do not think there is a way as of yet.. perhaps try setting it to an attribute? ie:
NPC Code:

this.attr[20]=hotel;


Projectshifter 06-04-2006 09:32 PM

Quote:

Originally Posted by Warcaptain
I do not think there is a way as of yet.. perhaps try setting it to an attribute? ie:
NPC Code:

this.attr[20]=hotel;


I tried setting a client.var to an object, it didn't work. I could do like client.obj = obj; and then sendtonc("Blah: " @ client.obj.var); and it would work, but it didn't actually set it on the client because if I tried to use it elsewhere or view it in my attributes it pulled up nothing. This is the very reason why I've decided not to come back to Graal. I used to think that the language was pretty versatile, but it really doesn't much in the way of data handling. Don't get me wrong, it has a great API in accordance with the game itself, but it doesn't handle data very well =(

ApothiX 06-04-2006 11:05 PM

There is no way to pass them via triggeractions, but I did come up with a little way to avoid that.

To send it:
PHP Code:

temp.object = new TStaticVar();
temp.object.test "Testing 123";

temp.arrayholder NULL
for(temp.vnametemp.object.getdynamicvarnames()) {
  
temp.arrayholder.add(temp.vname "=" temp.object.(@temp.vname));
}

triggerserver("gui"this.name"sendobject"temp.arrayholder); 

To receive it:
PHP Code:

function onActionServerside() {
  if(
params[0] == "sendobject") {
    
temp.object.loadvarsfromarray(params[1]);
    echo(
temp.object.test);
  }



Projectshifter 06-04-2006 11:08 PM

Quote:

Originally Posted by ApothiX
There is no way to pass them via triggeractions, but I did come up with a little way to avoid that.

To send it:
PHP Code:

temp.object = new TStaticVar();
temp.object.test "Testing 123";

temp.arrayholder NULL
for(temp.vnametemp.object.getdynamicvarnames()) {
  
temp.arrayholder.add(temp.vname "=" temp.object.(@temp.vname));
}

triggerserver("gui"this.name"sendobject"temp.arrayholder); 

To receive it:
PHP Code:

function onActionServerside() {
  if(
params[0] == "sendobject") {
    
temp.object.loadvarsfromarray(params[1]);
    echo(
temp.object.test);
  }



But that wouldn't accept multilevel vars though would it?

ApothiX 06-04-2006 11:12 PM

Quote:

Originally Posted by Projectshifter
But that wouldn't accept multilevel vars though would it?

Probably not. Not sure if you do something like:

temp.array = { "foo.bar.baz = 10" };
temp.obj.loadvarsfromarray(temp.array);

if it will load the temp.foo.bar.baz or not. If it does function that way, it wouldn't be hard to modify my code to support multiple-levels.

Projectshifter 06-04-2006 11:39 PM

Quote:

Originally Posted by ApothiX
Probably not. Not sure if you do something like:

temp.array = { "foo.bar.baz = 10" };
temp.obj.loadvarsfromarray(temp.array);

if it will load the temp.foo.bar.baz or not. If it does function that way, it wouldn't be hard to modify my code to support multiple-levels.

But it would be a pain in the ass if you didn't know how many levels there were and it could be up to 10 or so x.x

ApothiX 06-05-2006 04:01 AM

Quote:

Originally Posted by Projectshifter
But it would be a pain in the ass if you didn't know how many levels there were and it could be up to 10 or so x.x

Not really. if(makevar("temp.varname." @ temp.levels).getdynamicvarnames() >= 2 /* or whatever the minimum is; always includes some timeout and scriptlogfunctions or something */) { in some sort of for loop iterating through the levels.

Yen 06-05-2006 06:05 AM

I didn't bother to read anything, so I'm just throwing in some (hopefully) related information.
On my server, I reserve attr[2] to attr[5] of every NPC for specific things.
attr[4] is the NPC's identifier; it's a value based on the NPC's index. If I want to refer the serverside to a specific NPC found on the clientside, it uses this to figure out which NPC I want.
It's basically a way for me to pass a reference to this NPC from the clientside to the serverside, or vice-versa.

xXziroXx 06-05-2006 03:13 PM

Why dont you guys just use the inbuilt save[] functions..?

ApothiX 06-05-2006 07:23 PM

Quote:

Originally Posted by xXziroXx
Why dont you guys just use the inbuilt save[] functions..?

They are variables, not functions. Can you use even them as objects?

xXziroXx 06-05-2006 08:40 PM

Ah sorries, didnt read everything :p

Riot 06-10-2006 06:52 PM

Quote:

Originally Posted by ApothiX
There is no way to pass them via triggeractions, but I did come up with a little way to avoid that.

To send it:
PHP Code:

temp.object = new TStaticVar();
temp.object.test "Testing 123";

temp.arrayholder NULL
for(temp.vnametemp.object.getdynamicvarnames()) {
  
temp.arrayholder.add(temp.vname "=" temp.object.(@temp.vname));
}

triggerserver("gui"this.name"sendobject"temp.arrayholder); 

To receive it:
PHP Code:

function onActionServerside() {
  if(
params[0] == "sendobject") {
    
temp.object.loadvarsfromarray(params[1]);
    echo(
temp.object.test);
  }



You know there is a built-in savevarstoarray function

HTML Code:

temp.object = new TStaticVar();
temp.object.test = "test";
temp.object.test.bar = "test2";

temp.arrayholder = temp.object.savevarstoarray(false);

echo(temp.arrayholder) outputs
HTML Code:

scriptlogmissingfunctions=false,timeout=0,joinedclasses=,test=test,test.bar=test2
http://wiki.graal.net/index.php/Crea...lVar#Functions

ApothiX 06-12-2006 05:31 AM

Quote:

Originally Posted by Riot
You know there is a built-in savevarstoarray function

HTML Code:

temp.object = new TStaticVar();
temp.object.test = "test";
temp.object.test.bar = "test2";

temp.arrayholder = temp.object.savevarstoarray(false);

echo(temp.arrayholder) outputs
HTML Code:

scriptlogmissingfunctions=false,timeout=0,joinedclasses=,test=test,test.bar=test2
http://wiki.graal.net/index.php/Crea...lVar#Functions

Ah, nice. I couldn't find a function like that when I originally wrote that code. It was probably there, I just wasn't looking hard enough.


All times are GMT +2. The time now is 03:11 AM.

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