Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   New Scripting Engine (GS2) (https://forums.graalonline.com/forums/forumdisplay.php?f=153)
-   -   savelines() new line in file? (https://forums.graalonline.com/forums/showthread.php?t=134262303)

devilsknite1 03-04-2011 03:24 AM

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?

0PiX0 03-04-2011 03:50 AM

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;
  }



devilsknite1 03-04-2011 03:59 AM

Eek, didn't work.

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

Same thing :(

fowlplay4 03-04-2011 04:14 AM

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); 


devilsknite1 03-04-2011 04:32 AM

Quote:

Originally Posted by fowlplay4 (Post 1634392)
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.

WhiteDragon 03-04-2011 05:07 AM

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.

devilsknite1 03-04-2011 05:10 AM

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 :p

WhiteDragon 03-04-2011 05:13 AM

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.

devilsknite1 03-04-2011 05:15 AM

That's my problem; figuring out how to do that xP

WhiteDragon 03-04-2011 05:26 AM

You can use shared.replacetext(string, search, replace) from http://forums.graalonline.com/forums...ad.php?t=81277.

devilsknite1 03-04-2011 05:39 AM

Quote:

Originally Posted by WhiteDragon (Post 1634405)
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...

WhiteDragon 03-04-2011 05:56 AM

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.

devilsknite1 03-04-2011 06:18 AM

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

fowlplay4 03-04-2011 06:36 AM

Are you accessing the text via object.text or object.getlines()?

Your example seems to leave out the GUI part of your problem.

devilsknite1 03-04-2011 06:39 AM

object.text as it doesn't return in "","" form


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

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