Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Triggerserver with object (https://forums.graalonline.com/forums/showthread.php?t=134268223)

JohnnyChimpo 05-15-2013 09:35 PM

Triggerserver with object
 
Im trying to send an object through triggerserver but getting no results.
PHP Code:


  
else if (params[0] == "saveall")
  {
    
temp.data1 params[1];
    
//temp.savedata = new TStaticVar();
    //temp.savedata.loadvarsfromarray(temp.data1);
    
for (temp.i=0;i<langNumber;++i){
      
temp.data2 temp.data1[i];
      
temp.file filename[i];
      
temp.data2.savelines(temp.file);
    }
    
player.triggerclient("gui"this.name"savedall");
   }


//#CLIENTSIDE
function SaveAll_Button.onAction(){
  
temp.data trans.fileArray;
  
triggerserver("gui"this.name"saveall"temp.data);


The button for save works fine, but another weird thing is that when it goes to load the files back into multi line text edit, they are the same as they were like it was untouched. But if you go and download from server they are different. That confuses the heck out of me.

JohnnyChimpo 05-18-2013 06:55 PM

Any suggestions?? Thats not the whole script btw

cbk1994 05-18-2013 08:15 PM

Is trans.fileArray just an array? You shouldn't have problems sending an array via a trigger. You can't send objects, though (you can serialize them first if you must).

fowlplay4 05-18-2013 08:41 PM

Quote:

Originally Posted by cbk1994 (Post 1718072)
You can't send objects, though (you can serialize them first if you must).

I.e.

PHP Code:

function onActionServerSide() {
  if (
params[0] == "data") {
    
temp.obj.loadvarsfromarray(params[1]);
    echo(
"hello" SPC temp.obj.hello); // echos "hello world"
  
}
}

//#CLIENTSIDE

function onCreated() {
  
temp.data.hello "world";
  
triggerserver("gui"this.name"data"temp.data.savevarstoarray(false));


Also OP is missing the second parameter in savelines. I.e.

PHP Code:

temp.lines = {
 
"a",
 
"b",
 
"c"
};
temp.lines.savelines("path/to/file.txt"0); // 0 for overwrite, 1 for append 


JohnnyChimpo 05-19-2013 04:16 AM

Yes Cbk it is just an array, its just labeled as trans.fileArray but that is transs' only member, and after a few more checks it does seem to pass with no problems. The problem it seems is that its not stepping into the for loop for some reason, i tried an echo in the for loop didnt get any output on RC. This is after i added the overwrite to the savelines function.

cbk1994 05-19-2013 03:17 PM

Quote:

Originally Posted by JohnnyChimpo (Post 1718087)
Yes Cbk it is just an array, its just labeled as trans.fileArray but that is transs' only member, and after a few more checks it does seem to pass with no problems. The problem it seems is that its not stepping into the for loop for some reason, i tried an echo in the for loop didnt get any output on RC. This is after i added the overwrite to the savelines function.

Is langNumber greater than zero? You cut out all the relevant parts of that script. The problem seems not to be the trigger, but instead the for loop.

JohnnyChimpo 05-19-2013 04:08 PM

Serverside
PHP Code:

this.serverName "server";
this.lngArray = {"de","es","fr","it","ne","no","po","sw"};
this.lngNumber 8;
this.fileArray = {null};
this.filename null;

function 
onActionServerside() {
  for (
temp.=0;i<8;++i){
    
filename.add("levels/translations/"@serverName@"_"@lngArray[i]@".po");
  }
  if ( 
params[0] == "loadfile" 
  {
    for ( 
temp.i=0i<8;i++){
      
temp.lines loadlines(filename[i]);
      
fileArray.add(temp.lines);
    }
    echo(
fileArray[1]);
    
player.triggerclient("gui",this.name"loaded"fileArray);
  }
  else if (
params[0] == "save")
  {
    
temp.rowId params[2];
    
temp.file filename[temp.rowId];
    
params[1].savelines(temp.file0);
    
player.triggerclient("gui",this.name"saved");
  }
  else if (
params[0] == "saveall")
  {
    
fileArray params[1];
    echo(
filename[j]);
    
//temp.savedata = new TStaticVar();
    //temp.savedata.loadvarsfromarray(temp.data1);
    
for ( temp.j=0j<8; ++j){
      
temp.data2 this.fileArray[j];
      
temp.file filename[j];
      
//echo(temp.file);
      
fileArray[j].savelines(temp.file0);
    }
    
triggerclient("gui"this.name"saved");
   }



PHP Code:

//ACTIONS

function onTabSelect(){
  
trans.fileArray[prevTab] = EditTextML.getlines();
  
prevTab Trans_Tabs.getselectedid();
  
output trans.fileArray[prevTab];
  
EditTextML.setlines(output);
}
// FOR SEARCH FUNCTION TO WORK PERFECTLY EACH ENTRY MUST BE ON ONE LINE ONLY
function Search_Button.onAction(){
  
temp.toFind Search_Field.gettext();
  
temp.data EditTextML.getlines();
  
temp.numOfArray temp.data.size();
  
temp.found false;
  
this.foundx=0;
  
this.foundy=0;
  for (
temp.0;i<temp.numOfArray +1; ++i){
    
temp.str temp.data[i].tokenize();
    
temp.count 0;
    for (
word temp.str){
      
temp.count temp.count+1;
      if (
temp.toFind == word){
        
this.foundx count;
        
this.foundy i;
        
temp.found true;
        
player.chat "found at"@count@","@i@"yea";
      }
     }
    }
   
EditTextML_ScrollField.scrollto(0,(this.foundy*16)+10);
   if (!
temp.found){
  
player.chat "Could not find Word";
  }
  
}
function 
Save_Button.onAction(){
  
temp.saveStr EditTextML.getlines();
  
rowid Trans_Tabs.getselectedid();
  
trans.fileArray[rowId] = temp.saveStr;
  
EditTextML.setlines(trans.fileArray[rowId]);
  
triggerserver("gui"this.name"save"temp.saveStrrowid );
  }
function 
SaveAll_Button.onAction(){
  
triggerserver("gui"this.name"saveall"trans.fileArray);
}
function 
updateLines(){
  
triggerserver("gui"this.name"update"rowId);
  } 

Its not letting me post the clientside GUI for whatever reason its say im restricted by the host server of the forums. so if you need that let me know.


All times are GMT +2. The time now is 09:05 AM.

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