Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   onActionClientSide Weirdness (https://forums.graalonline.com/forums/showthread.php?t=134264363)

iBeatz 08-26-2011 03:20 AM

onActionClientSide Weirdness
 
This has happened to me on two seperate occassions, and for the life of me I cannot work out why.
What happens is that when I trigger the client from serverside, the function onActionClientSide appears to execute twice, instead of once from the trigger on the serverside.
Normally, this wouldn't be a problem for me, but for functions which add text to a list, this is quite frustrating, as I get double the amount of text that I should.
Can anyone explain this?

cbk1994 08-26-2011 03:26 AM

Post your code (at least relevant sections, i.e. the triggers).

Also, check that the triggerClient isn't actually being called twice (add an echo near it—if you see it twice, it's something else).

fowlplay4 08-26-2011 03:28 AM

PHP Code:

function onActionServerSide() {
  if (
params[0] == "test") {
    
player.triggerclient(this.name"msg"timevar2);
  }
}

//#CLIENTSIDE

function onCreated() {
  
triggerserver("gui"this.name"test");
}

function 
onActionClientSide() {
  if (
params[0] == "msg") {
    echo(
params[1]);
  }


Does the above only show one 'test <number>" when you apply the script?

iBeatz 08-26-2011 03:34 AM

Quote:

Originally Posted by cbk1994 (Post 1665506)
Post your code (at least relevant sections, i.e. the triggers).

Also, check that the triggerClient isn't actually being called twice (add an echo near it—if you see it twice, it's something else).

I've checked the trigger on the serverside with an echo, it's being called once.

PHP Code:

if(params[0] == "LoadPlayers"){
  for(
temp.pl allplayers){
    if(
temp.pl.level != NULL){
      
temp.plyrs.add(temp.pl);
    }
    else {
      
temp.rcs.add(temp.pl);
    }
  }
  
triggerClient("gui",name,"GotPlayers",temp.plyrs,temp.rcs);


And then when this info is sent to the client, which I've checked with an echo and it executes twice:

PHP Code:

function onActionClientSide(){
  
showInterface(Category_Tabs.getSelectedText());
}

function 
showInterface(opt){
  
  
with("Operations_List"){
    switch(
opt){
    case 
"Players":
      
addRow(0,"Warpto");
      
addRow(1,"Profile");
      
addRow(2,"Summon");
      
addRow(3,"Warp Player");
      
addRow(4,"Client flags");
      for(
temp.0temp.<= 4temp.++){
        
rows[temp.r].active false;
      }
   }


This is the only way the showInterface function could be called, which is what is causing the problem.

salesman 08-26-2011 03:38 AM

Not sure if it would be the cause, but you're missing a closing bracket

iBeatz 08-26-2011 03:42 AM

Quote:

Originally Posted by salesman (Post 1665509)
Not sure if it would be the cause, but you're missing a closing bracket

That's my bad.
Was copying and pasting it out of the middle of a function and adding brackets on the forums.
It's okay in my script.

fowlplay4 08-26-2011 03:42 AM

You should be verifying that params[0] is "GotPlayers" in your onActionClientSide. I question your switch statement as well because it doesn't appear you're using a break for each, which could cause a falling through and adding rows for no reason.

iBeatz 08-26-2011 03:47 AM

Quote:

Originally Posted by fowlplay4 (Post 1665511)
You should be verifying that params[0] is "GotPlayers" in your onActionClientSide. I question your switch statement as well because it doesn't appear you're using a break for each, which could cause a falling through and adding rows for no reason.

Again, the break is there, I just didn't copy and paste it properly.
I was verifying params[0] after that function was called, so that the function would be called no matter what params[0] was, but it seems that placing the function after the verification fixes the problem, so thanks fowlplay.

Why would it be called twice in the first place though?

fowlplay4 08-26-2011 03:55 AM

Quote:

Originally Posted by iBeatz (Post 1665512)
Again, the break is there, I just didn't copy and paste it properly.
I was verifying params[0] after that function was called, so that the function would be called no matter what params[0] was, but it seems that placing the function after the verification fixes the problem, so thanks fowlplay.

Why would it be called twice in the first place though?

You can triggerclient any weapon from any script on the server-side so you should be validating the first parameter to make sure a rogue script isn't just sending it random data.

ffcmike 08-26-2011 03:47 PM

Quote:

Originally Posted by salesman (Post 1665509)
Not sure if it would be the cause, but you're missing a closing bracket

Iirc any improperly defined function will occur as a result of any other properly defined function within the script.

If you were to make an NPC script of:

PHP Code:

//#CLIENTSIDE
function onCreated(){
  
//
}

function 
onPlayerEnters(){
  
//
}

function 
onPlayerChats(){
  
//
}

//as opposed to function lol(){
lol(){
  
this.chat ++;


"lol()" would occur when the NPC is created, the player enters, the player chats etc.
So the missing bracket probably is the cause here.

furry_mougle 08-31-2011 08:29 AM

I remember having a similar problem before with NPCs joined to the same class in one level, and if the player was in that level and executed a block of code with that NPC it'd execute twice. Though, I don't think that's the case here. Probably the missing bracket.


All times are GMT +2. The time now is 09:11 PM.

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