Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting > New Scripting Engine (GS2)
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 03-04-2011, 03:24 AM
devilsknite1 devilsknite1 is offline
C:
devilsknite1's Avatar
Join Date: Jul 2006
Location: Florida, USA
Posts: 269
devilsknite1 has a spectacular aura about
Send a message via AIM to devilsknite1 Send a message via MSN to devilsknite1 Send a message via Yahoo to devilsknite1
savelines() new line in file?

PHP Code:
function onActionServerSideafisvar1svar2 ) {
  switch( 
afi ) {
    case 
"callTextTypeFile": {
      
temp.text_type_file.loadLinessvar1 );
      
triggerClient"gui"name"displayTextTypeFile"temp.text_type_file );
      break;
    }
    case 
"editTextTypeFile": {
      
temp.text_type_file = { svar1 };
      
temp.text_type_file.saveLinessvar2);
      break;
    }
  }
}

//#CLIENTSIDE

function onActionClientSideafifile ) {
  switch( 
afi ) {
    case 
"displayTextTypeFile": {
      for ( 
temp.file ) {
        
temp.ne @= temp."\n"; <-- This is the problem
      
}
      
onEditTextTypeFiletemp.ne );
      break;
    }
  }
}

function 
onPlayerChats() {
  
temp.tokens player.chat.tokenize();
  if ( 
player.chat.starts"/lf " ) ) {
    
this.file_selected temp.tokens];
    
triggerServer"gui"name"callTextTypeFile"temp.tokens] );
  }
}

function 
onEditTextTypeFilesvar ) {
  
Gui stuff hereremoved for space reasons

The problem is not in the GUI or loading the text file, it's the text file itself. \n obviously won't make a new line in the text file, but it will the GUI. How would I go about making a new line, in both, the text file and the GUI?
Reply With Quote
  #2  
Old 03-04-2011, 03:50 AM
0PiX0 0PiX0 is offline
Coder
0PiX0's Avatar
Join Date: Jan 2011
Posts: 130
0PiX0 is a jewel in the rough0PiX0 is a jewel in the rough
Try the NL concat operator to create a new line:
PHP Code:
function onActionClientSide(paramlines) {
  switch (
param) {
    case 
"displayTextTypeFile":
      for (
temp.0temp.lines.size(); temp.i++) {
        
temp.ne @= "" NL lines[temp.i];
      }
      
onEditTextTypeFile(temp.ne);
    break;
  }

__________________
Reply With Quote
  #3  
Old 03-04-2011, 03:59 AM
devilsknite1 devilsknite1 is offline
C:
devilsknite1's Avatar
Join Date: Jul 2006
Location: Florida, USA
Posts: 269
devilsknite1 has a spectacular aura about
Send a message via AIM to devilsknite1 Send a message via MSN to devilsknite1 Send a message via Yahoo to devilsknite1
Eek, didn't work.

This is the outcome:
This is an attempt to\nFigure out\nIf this works

Same thing
Reply With Quote
  #4  
Old 03-04-2011, 04:14 AM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
Here's some basic examples for the savestring and savelines functions.

PHP Code:
// Declare Filename
temp.filename "path/to/file.txt";
// Save Lines
temp.lines = {
  
"Line 0: Hello",
  
"Line 1: World!"
  "Line 2: How are you?"
};
temp.lines.savelines(temp.filename0);
// Save String
temp.str "Hello World!\n";
temp.str.savestring(temp.filename0);
// Append String to File
temp.str "Yeah!\n";
temp.str.savestring(temp.filename1);
// Append Lines to File
temp.lines.savelines(temp.filename1); 
__________________
Quote:
Reply With Quote
  #5  
Old 03-04-2011, 04:32 AM
devilsknite1 devilsknite1 is offline
C:
devilsknite1's Avatar
Join Date: Jul 2006
Location: Florida, USA
Posts: 269
devilsknite1 has a spectacular aura about
Send a message via AIM to devilsknite1 Send a message via MSN to devilsknite1 Send a message via Yahoo to devilsknite1
Quote:
Originally Posted by fowlplay4 View Post
Here's some basic examples for the savestring and savelines functions.

PHP Code:
// Declare Filename
temp.filename "path/to/file.txt";
// Save Lines
temp.lines = {
  
"Line 0: Hello",
  
"Line 1: World!"
  "Line 2: How are you?"
};
temp.lines.savelines(temp.filename0);
// Save String
temp.str "Hello World!\n";
temp.str.savestring(temp.filename0);
// Append String to File
temp.str "Yeah!\n";
temp.str.savestring(temp.filename1);
// Append Lines to File
temp.lines.savelines(temp.filename1); 
Yeah.. That's great and all, but there's still no solution to my original problem :s
My script loads a file from the server, displays it in a GUI, allows editing, but when it's saved, the new lines only show in the GUI and are not displayed in the original textfile, which could be a problem for things like guild text files, etc. If I could use the first thing shown (creating lines manually) I would, but that would destroy the use of the script all together.

I need to overwrite, not append the text files.

Lastly, what's being sent to the serverside part of the script to save the lines is the GUIs text.
Reply With Quote
  #6  
Old 03-04-2011, 05:07 AM
WhiteDragon WhiteDragon is offline
Banned
Join Date: Feb 2007
Posts: 1,002
WhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to behold
I'll be willing to bet your issue is that you're viewing the file on Windows, which doesn't properly display \n as linebreaks. You need to use \r\n.
Reply With Quote
  #7  
Old 03-04-2011, 05:10 AM
devilsknite1 devilsknite1 is offline
C:
devilsknite1's Avatar
Join Date: Jul 2006
Location: Florida, USA
Posts: 269
devilsknite1 has a spectacular aura about
Send a message via AIM to devilsknite1 Send a message via MSN to devilsknite1 Send a message via Yahoo to devilsknite1
No dice. Outcome:
I\'m currently\r\ntrying to figure out\r\nhow the hell\r\nthis thing\r\nworks\r

I was also in the process of reading up on line breaks when this was posted... What a coincidence
Reply With Quote
  #8  
Old 03-04-2011, 05:13 AM
WhiteDragon WhiteDragon is offline
Banned
Join Date: Feb 2007
Posts: 1,002
WhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to behold
Oh. If you are actually storing the control sequences as letters, then you'll need to do a conversion before/after you save/load the file. Just replace \n with an actual line break, and vice versa.
Reply With Quote
  #9  
Old 03-04-2011, 05:15 AM
devilsknite1 devilsknite1 is offline
C:
devilsknite1's Avatar
Join Date: Jul 2006
Location: Florida, USA
Posts: 269
devilsknite1 has a spectacular aura about
Send a message via AIM to devilsknite1 Send a message via MSN to devilsknite1 Send a message via Yahoo to devilsknite1
That's my problem; figuring out how to do that xP
Reply With Quote
  #10  
Old 03-04-2011, 05:26 AM
WhiteDragon WhiteDragon is offline
Banned
Join Date: Feb 2007
Posts: 1,002
WhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to behold
You can use shared.replacetext(string, search, replace) from http://forums.graalonline.com/forums...ad.php?t=81277.
Reply With Quote
  #11  
Old 03-04-2011, 05:39 AM
devilsknite1 devilsknite1 is offline
C:
devilsknite1's Avatar
Join Date: Jul 2006
Location: Florida, USA
Posts: 269
devilsknite1 has a spectacular aura about
Send a message via AIM to devilsknite1 Send a message via MSN to devilsknite1 Send a message via Yahoo to devilsknite1
Quote:
Originally Posted by WhiteDragon View Post
You can use shared.replacetext(string, search, replace) from http://forums.graalonline.com/forums...ad.php?t=81277.
And this would work inside of the text file?

EDIT: Tested, not sure what I should be replacing the saving part with instead of \n...
Reply With Quote
  #12  
Old 03-04-2011, 05:56 AM
WhiteDragon WhiteDragon is offline
Banned
Join Date: Feb 2007
Posts: 1,002
WhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to behold
Ah, I see your actual problem now.

If you use savelines and loadlines, it automatically converts actual line breaks to the string \n. If you use savestring and loadstring it won't do that.

So basically just use savestring and loadstring like in fp4's example and your problem should go away.
Reply With Quote
  #13  
Old 03-04-2011, 06:18 AM
devilsknite1 devilsknite1 is offline
C:
devilsknite1's Avatar
Join Date: Jul 2006
Location: Florida, USA
Posts: 269
devilsknite1 has a spectacular aura about
Send a message via AIM to devilsknite1 Send a message via MSN to devilsknite1 Send a message via Yahoo to devilsknite1
The only problem I have when doing that is loadstring(). It doesn't actually load the file, it just displays a 0 in the GUI

Last edited by devilsknite1; 03-04-2011 at 06:36 AM..
Reply With Quote
  #14  
Old 03-04-2011, 06:43 AM
0PiX0 0PiX0 is offline
Coder
0PiX0's Avatar
Join Date: Jan 2011
Posts: 130
0PiX0 is a jewel in the rough0PiX0 is a jewel in the rough
My guess is that you are sending a string to the server, not the lines.
Perhaps something like this will work for you:
PHP Code:
function onActionServerSide(afisvar1svar2) {
  switch (
afi) {
    case 
"callTextTypeFile":
      
temp.text_type_file.loadLines(svar1);
      
triggerClient("gui"name"displayTextTypeFile"temp.text_type_file);
    break;
    case 
"editTextTypeFile":
      
temp.text_type_file.saveLines(svar20);
    break;
  }
}

//#CLIENTSIDE

function sendLinesToServer() {
  
temp.lines MyGuiMultiLineTextControl.getlines();
  
triggerServer("gui"name"editTextTypeFile"temp.lines"MyFile.txt");

__________________
Reply With Quote
  #15  
Old 03-04-2011, 06:49 AM
devilsknite1 devilsknite1 is offline
C:
devilsknite1's Avatar
Join Date: Jul 2006
Location: Florida, USA
Posts: 269
devilsknite1 has a spectacular aura about
Send a message via AIM to devilsknite1 Send a message via MSN to devilsknite1 Send a message via Yahoo to devilsknite1
Quote:
Originally Posted by 0PiX0 View Post
My guess is that you are sending a string to the server, not the lines.
Perhaps something like this will work for you:
PHP Code:
function onActionServerSide(afisvar1svar2) {
  switch (
afi) {
    case 
"callTextTypeFile":
      
temp.text_type_file.loadLines(svar1);
      
triggerClient("gui"name"displayTextTypeFile"temp.text_type_file);
    break;
    case 
"editTextTypeFile":
      
temp.text_type_file.saveLines(svar20);
    break;
  }
}

//#CLIENTSIDE

function sendLinesToServer() {
  
temp.lines MyGuiMultiLineTextControl.getlines();
  
triggerServer("gui"name"editTextTypeFile"temp.lines"MyFile.txt");

Tried this already and got this as an outcome:
JUST,WORK,ALREADY

instead of what I want, which should be
JUST
WORK
ALREADY

it's getting closer, I'm just not sure what it is, exactly X.X

By the way, the outcomes are what is displayed in the text file.
PHP Code:
Tried this already and got this as an outcome:
JUST,WORK,ALREADY 
This is the only example where both the text file and the GUI displayed the same thing, but neither of them were line breaks, which is the goal instead of the commas.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 12:14 AM.


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