View Single Post
  #3  
Old 07-30-2011, 06:41 PM
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
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.filename, 0);
// Save String
temp.str = "Hello World!\n";
temp.str.savestring(temp.filename, 0);
// Append String to File
temp.str = "Yeah!\n";
temp.str.savestring(temp.filename, 1);
// Append Lines to File
temp.lines.savelines(temp.filename, 1); 
Quote:
Originally Posted by fowlplay4 View Post
This works just fine, the file will look messed up (all on one line) in regular Windows Notepad (Terriblepad) instead use Wordpad or Notepad++

PHP Code:
function onActionServerSide() {
  
temp.filename = "cartridge/test.txt";
  if (
params[0] == "load") {
    
temp.lines.loadlines(temp.filename);
    
player.triggerclient(this.name, "load", temp.lines);
  }
  else if (
params[0] == "save") {
    
params[1].savelines(temp.filename, 0);
  }
}

//#CLIENTSIDE

function onActionClientSide() {
  if (
params[0] == "load") {
    
TestWindowML.setlines(params[1]);
  }
}

function 
onCreated() {
  new 
GuiWindowCtrl("TestWindow") {
    
x = 100;
    
y = 100;
    
width = 300;
    
height = 300;
    new 
GuiScrollCtrl("TestWindowScroll") {
      
x = 4;
      
y = 20;
      
width = 296;
      
height = 280;
      new 
GuiMLTextEditCtrl("TestWindowML") {
        
x = y = 2;
        
width = 280;
        
height = 280;
      }
    }
  }
  
triggerserver("gui", name, "load");
}

function 
ChatBar.onAction() {
  if (
ChatBar.text == "/save") {
    
temp.lines = TestWindowML.getlines();
    
triggerserver("gui", this.name, "save", temp.lines);
    
ChatBar.text = "";
  }
} 
Also linked on my tutorial.
__________________
Quote:
Reply With Quote