Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   loadlines() problem (https://forums.graalonline.com/forums/showthread.php?t=134260253)

devilsknite1 08-19-2010 01:17 AM

loadlines() problem
 
Chris Vimes' news system with a twist... Editing in game through a GUI. Basically, everything works and loads up fine, except for the editing of the Progress, Staff, and Hirings. News works perfect, the same code is repeated and no dice. Any ideas? (Text limited -- Using two posts)

devilsknite1 08-19-2010 01:19 AM

Because Graal Forums don't like me, I cut out the main login message (text too long)

PHP Code:

function onActionServerSide( afi, var ) {
  switch( 
afi ) {
    case 
"receiveNews": {
      
temp.news.loadLines( "control/s_news.txt" );
      
triggerClient( "gui", name, "getNews", temp.news );
      break;
    }
    case 
"receiveProgress": {
      
temp.progress.loadLines( "control/s_progress.txt" );
      
triggerClient( "gui", name, "getProgress", temp.progress );
      break;
    }
    case 
"receiveStaff": {
      
temp.staff.loadLines( "control/s_staff.txt" );
      
triggerClient( "gui", name, "getStaff", temp.staff );
      break;
    }
    case 
"receiveHirings": {
      
temp.hirings.loadLines( "control/s_hirings.txt" );
      
triggerClient( "gui", name, "getHirings", temp.hirings );
      break;
    }
    case 
"editNews": {
      
temp.news = { var };
      
temp.news.saveLines( "control/s_news.txt", 0 );
      break;
    }
    case 
"editProgress": {
      
temp.progress = { var };
      
temp.progress.saveLines( "control/s_progress.txt", 0 );
      break;
    }
    case 
"editStaff": {
      
temp.staff = { var };
      
temp.staff.saveLines( "control/s_staff.txt", 0 );
      break;
    }
    case 
"editHirings": {
      
temp.hirings = { var };
      
temp.hirings.saveLines( "control/s_hirings.txt", 0 );
      break;
    }
  }
}

//#CLIENTSIDE

function onActionClientSide( afi, news, progress, staff, hirings ) {
  switch( 
afi ) {
    case 
"getNews": {
      for ( 
temp.a : news ) {
        
temp.ne @= temp.a @ "\n";
      }
      
onEditNews( temp.ne );
      break;
    }
    case 
"getProgress": {
      
// Nothing is received here (progress = 0, temp.pro = 0, temp.a = 0)
      
for ( temp.a : progress ) {
        
temp.pro @= temp.a @ "\n";
      }
      
onEditProgress( temp.pro );
      break;
    }
    case 
"getStaff": {
      
// Same thing as progress, nothing receives here.
      
for ( temp.a : staff ) {
        
temp.s @= temp.a @ "\n";
      }
      
onEditStaff( temp.s );
      break;
    }
    case 
"getHirings": {
      
// Ditto
      
for ( temp.a : hirings ) {
        
temp.h @= temp.a @ "\n";
      }
      
onEditHirings( temp.h );
      break;
    }
  }
}

function 
onPlayerChats() {
  if ( 
player.chat == ":edit news" ) {
    
player.chat = "";
    
triggerServer( "gui", name, "receiveNews" );
  }
  if ( 
player.chat == ":edit progress" ) {
    
player.chat = "";
    
triggerServer( "gui", name, "receiveProgress" );
  }
  if ( 
player.chat == ":edit staff" ) {
    
player.chat = "";
    
triggerServer( "gui", name, "receiveStaff" );
  }
  if ( 
player.chat == ":edit hirings" ) {
    
player.chat = "";
    
triggerServer( "gui", name, "receiveHirings" );
  }
}

function 
onEditNews( news ) {
  new 
GuiWindowCtrl( "News_Window" ) {
    
profile = GuiWindowProfile;
    
x = screenwidth / 2 - ( width / 2 );
    
y = screenheight / 2 - ( height / 2 );
    
clientRelative = true;
    
clientExtent = "428,338";
    
canMaximize = false;
    
canMove = true;
    
canResize = false;
    
canClose = true;
    
closeQuery = false;
    
destroyOnHide = true;
    
text = "Editing Tab: News";

    new 
GuiScrollCtrl( "News_News_Scroll" ) {
      
profile = GuiScrollProfile;
      
height = 292;
      
hScrollBar = "dynamic";
      
vScrollBar = "alwaysOff";
      
width = 428;

      new 
GuiMLTextEditCtrl( "News_News" ) {
        
profile = GuiMLTextEditProfile;
        
height = 16;
        
horizSizing = "width";
        
text = news;
        
width = 403;
      }
    }
    
    new 
GuiButtonCtrl( "News_Save" ) {
      
profile = GuiButtonProfile;
      
height = 43;
      
text = "Save Tab: News";
      
width = 428;
      
y = 295;
    }
  }
}

function 
News_Save.onAction() {
  
triggerServer( "gui", name, "editNews", News_News.text );
  
News_Window.destroy();
}

function 
onEditProgress( progress ) {
  new 
GuiWindowCtrl( "Progress_Window" ) {
    
profile = GuiWindowProfile;
    
x = screenwidth / 2 - ( width / 2 );
    
y = screenheight / 2 - ( height / 2 );
    
clientRelative = true;
    
clientExtent = "428,338";
    
canMaximize = false;
    
canMove = true;
    
canResize = false;
    
canClose = true;
    
closeQuery = false;
    
destroyOnHide = true;
    
text = "Editing Tab: Progress";

    new 
GuiScrollCtrl( "Progress_Scroll" ) {
      
profile = GuiScrollProfile;
      
height = 292;
      
hScrollBar = "dynamic";
      
vScrollBar = "alwaysOff";
      
width = 428;

      new 
GuiMLTextEditCtrl( "Progress_Progress" ) {
        
profile = GuiMLTextEditProfile;
        
height = 16;
        
horizSizing = "width";
        
text = progress;
        
width = 403;
      }
    }
    
    new 
GuiButtonCtrl( "Progress_Save" ) {
      
profile = GuiButtonProfile;
      
height = 43;
      
text = "Save Tab: Progress";
      
width = 428;
      
y = 295;
    }
  }
}

function 
Progress_Save.onAction() {
  
triggerServer( "gui", name, "editProgress", Progress_Progress.text );
  
Progress_Window.destroy();
}

function 
onEditStaff( staff ) {
  new 
GuiWindowCtrl( "Staff_Window" ) {
    
profile = GuiWindowProfile;
    
x = screenwidth / 2 - ( width / 2 );
    
y = screenheight / 2 - ( height / 2 );
    
clientRelative = true;
    
clientExtent = "428,338";
    
canMaximize = false;
    
canMove = true;
    
canResize = false;
    
canClose = true;
    
closeQuery = false;
    
destroyOnHide = true;
    
text = "Editing Tab: Staff";

    new 
GuiScrollCtrl( "Staff_Staff_Scroll" ) {
      
profile = GuiScrollProfile;
      
height = 292;
      
hScrollBar = "dynamic";
      
vScrollBar = "alwaysOff";
      
width = 428;

      new 
GuiMLTextEditCtrl( "Staff_Staff" ) {
        
profile = GuiMLTextEditProfile;
        
height = 16;
        
horizSizing = "width";
        
text = staff;
        
width = 403;
      }
    }
    
    new 
GuiButtonCtrl( "Staff_Save" ) {
      
profile = GuiButtonProfile;
      
height = 43;
      
text = "Save Tab: Staff";
      
width = 428;
      
y = 295;
    }
  }
}

function 
Staff_Save.onAction() {
  
triggerServer( "gui", name, "editStaff", Staff_Staff.text );
  
Staff_Window.destroy();
}

function 
onEditHirings( hirings ) {
  new 
GuiWindowCtrl( "Hirings_Window" ) {
    
profile = GuiWindowProfile;
    
x = screenwidth / 2 - ( width / 2 );
    
y = screenheight / 2 - ( height / 2 );
    
clientRelative = true;
    
clientExtent = "428,338";
    
canMaximize = false;
    
canMove = true;
    
canResize = false;
    
canClose = true;
    
closeQuery = false;
    
destroyOnHide = true;
    
text = "Editing Tab: Hirings";

    new 
GuiScrollCtrl( "Hirings_Hirings_Scroll" ) {
      
profile = GuiScrollProfile;
      
height = 292;
      
hScrollBar = "dynamic";
      
vScrollBar = "alwaysOff";
      
width = 428;

      new 
GuiMLTextEditCtrl( "Hirings_Hirings" ) {
        
profile = GuiMLTextEditProfile;
        
height = 16;
        
horizSizing = "width";
        
text = hirings;
        
width = 403;
      }
    }
    
    new 
GuiButtonCtrl( "Hirings_Save" ) {
      
profile = GuiButtonProfile;
      
height = 43;
      
text = "Save Tab: Hirings";
      
width = 428;
      
y = 295;
    }
  }
}

function 
Hirings_Save.onAction() {
  
triggerServer( "gui", name, "editHirings", Hirings_Hirings.text );
  
Hirings_Window.destroy();
} 


fowlplay4 08-19-2010 01:39 AM

Change var at the top to svar, and replace { var } with { svar }.

var is a keyword for whatever reason and doesn't work properly with scripts.

cbk1994 08-19-2010 01:42 AM

Quote:

Originally Posted by fowlplay4 (Post 1595188)
var is a keyword for whatever reason and doesn't work properly with scripts.

I thought it worked serverside?

Either way I'd avoid it just to prevent confusion. I don't see anything else wrong with the script after a quick look.

Admins 08-19-2010 01:43 AM

onActionClientSide(afi, datalines) should only have two parameters, second parameter is always the data lines, and then instead of for (temp.a: news), for (temp.a: progress) etc. always do for (temp.a: datalines) (or for (temp.a: params[1]))

WhiteDragon 08-19-2010 02:04 AM

Feel lucky, Stefan just personally looked at your script and told you what to fix!

devilsknite1 08-19-2010 02:55 AM

Quote:

Originally Posted by Stefan (Post 1595191)
onActionClientSide(afi, datalines) should only have two parameters, second parameter is always the data lines, and then instead of for (temp.a: news), for (temp.a: progress) etc. always do for (temp.a: datalines) (or for (temp.a: params[1]))

I did that because I also have:

PHP Code:

function onActionClientSide( afi, news, progress, staff, hirings ) {
  switch( 
afi ) {
    case 
"getMessage": {
      for ( 
temp.a : news ) {
        
temp.ne @= temp.a @ "\n";
      }
      for ( 
temp.a : progress ) {
        
temp.pro @= temp.a @ "\n";
      }
      for ( 
temp.a : staff ) {
        
temp.st @= temp.a @ "\n";
      }
      for ( 
temp.a : hirings ) {
        
temp.hi @= temp.a @ "\n";
      }
      
onShowMessage( temp.ne, temp.pro, temp.st, temp.hi );
      break;
    }
  }
} 

So yeah, usually I would use one parameter. And I just noticed that I should be using the second parameter for all of them lol

adam 08-19-2010 03:04 AM

Your so lucky!!!!


All times are GMT +2. The time now is 06:32 AM.

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