Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   this.attr[#] not carrying across, triggerclient not working either (https://forums.graalonline.com/forums/showthread.php?t=82881)

Raeiphon 11-23-2008 10:59 AM

this.attr[#] not carrying across, triggerclient not working either
 
NPC Code:

function onCreated()
{
showcharacter();
this.target = findplayer(this.owner);
this.attr[2] = new[5][2];
setTimer(.3);
}
function onPlayerChats()
{
if (player.account == "raeiphon" && player.chat.starts("/destroy")) { this.destroy(); }
if (player.account == "raeiphon" && player.chat.starts("/show")) { this.chat = this.attr[2][0]; }
if (player.account == "raeiphon" && player.chat.starts("/halt")) { triggerclient(); }
}
function onTimeout()
{
if (this.attr[2].size() > 5) { this.attr[2] = this.attr[2].subarray(0,5); }
this.attr[2].insert(0, {this.target.x,this.target.y});
triggerclient(this.attr[2]);
setTimer(.05);
}
//#CLIENTSIDE
function onCreated()
{
//setTimer(.3);
}
function onTimeout()
{
this.x = this.attr[3][4][0];
this.y = this.attr[3][4][1];
setTimer(.3);
}
function onActionClientside(var)
{
this.attr[3] = var;
}




Originally this started out just setting this.attr[3] on the serverside, since I was told by Tig that it apparently carries across through clientside/serverside barriers and whatnot. That quickly turned out to be false, so I stuck a triggerclient in the timeout to simulate this being the case.

However, it doesn't work. Simply does not work. This.attr[3] is 0 always. Don't tell me that attrs can't hold arrays either, because they can - a echo on the variable on the serverside tells us this (see /show).

Any ideas?

Crow 11-23-2008 11:07 AM

The problem here is that you are trying to use the attributes as arrays, which won't work. You can, however, use them as string, seperate each element with a comma, and use tokenize(",") on them when reading them. So they would be a semi-array, or something..
Anyway, when you've done converting your code to do that, it will also reflect itself between server- and clientside.

DustyPorViva 11-23-2008 11:10 AM

Try this:
PHP Code:

function onCreated()

{
  
showcharacter();
  
this.target findplayer(this.owner);
  
this.attr[2] = new[5][2];

  
setTimer(.3);
}

function 
onPlayerChats()

{
  if (
player.account == "raeiphon" && player.chat.starts("/destroy")) { this.destroy(); }
  if (
player.account == "raeiphon" && player.chat.starts("/show")) { this.chat this.attr[2][0]; }
  if (
player.account == "raeiphon" && player.chat.starts("/halt")) { triggerclient(); }
}

function 
onTimeout()

{
  if (
this.attr[2].size() > 5) { this.attr[2] = this.attr[2].subarray(0,5); }
  
this.attr[2].insert(0, {this.target.x,this.target.y});
  
//triggerclient(this.attr[2]);
  
setTimer(.1);
}

//#CLIENTSIDE
function onCreated()
{
 
setTimer(.3);
}

function 
onTimeout()
{
  
this.chat this.attr[2];
  
this.this.attr[2][4][0];
  
this.this.attr[2][4][1];
  
setTimer(.3);

}

function 
onActionClientside(var)
{
this.attr[3] = var;


You've proven they attr's can store arrays... I'm just not sure if they can be passed to the clientside.

DustyPorViva 11-23-2008 11:19 AM

This is what I've come up with:
PHP Code:

function onCreated() {
  
this.attr[5] = {{5,2},{6,8},{2,4}};
}
//#CLIENTSIDE
function onCreated() {
  
setTimer(0.1);
}

function 
onTimeout() {
  
temp.test = (this.attr[5]);
  
this.chat test[2][1];
  
setTimer(0.1);


Will echo 4.

xXziroXx 11-23-2008 12:24 PM

http://forums.graalonline.com/forums...ad.php?t=72413

:)

DustyPorViva 11-23-2008 12:27 PM

Quote:

Originally Posted by xXziroXx (Post 1444246)

No need to tokenize or anything, what I posted works fine :)

Crow 11-23-2008 12:40 PM

Quote:

Originally Posted by DustyPorViva (Post 1444248)
No need to tokenize or anything, what I posted works fine :)

Mh, I tried several things to get arrays working with attributes on Era, and it didn't work for some reason. Weird.

xXziroXx 11-23-2008 12:46 PM

Quote:

Originally Posted by Crow (Post 1444252)
Mh, I tried several things to get arrays working with attributes on Era, and it didn't work for some reason. Weird.

That's because attributes doesn't support arrays, and you have to convert it into a string and then "pretend" it's an array. The only drawback is that it's impossible to use sub-arrays in it, since it won't be able to tell a difference between it.

DustyPorViva 11-23-2008 01:17 PM

I had no problem with the script I posted. It works fine and I even did some pseudo-smooth-moving and such with the baddy. Subarrays worked and everything.


All times are GMT +2. The time now is 03:47 PM.

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