Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 07-30-2011, 05:40 PM
Astram Astram is offline
Era iPhone PR
Astram's Avatar
Join Date: Aug 2010
Posts: 324
Astram can only hope to improve
Send a message via AIM to Astram
Editing .txt files

How can you edit .txt files online, with multiline edit, and then save it? Like
lets say this is in pwn.txt "HI there". Then, how would you edit pwn.txt from "HI there" to "NOOB" and save it?
__________________
-Toad
The worlds biggest Toad fan...
Era iPhone FTW!


Reply With Quote
  #2  
Old 07-30-2011, 06:19 PM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
PHP Code:
temp.lines = {
  
"first line",
  
"second line",
  
"third line"
};

// if you want to append to the file instead of replacing, second parameter
// should be true
temp.lines.saveLines("path/to/file.txt"false); 
Serverside, obviously, and (npcserver) needs rw (folder rights) to the specified file.

To get an array of lines from a text file,

PHP Code:
temp.lines.loadLines("path/to/file.txt"); 
__________________
Reply With Quote
  #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.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:
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.filename0);
  }
}

//#CLIENTSIDE

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

function 
onCreated() {
  new 
GuiWindowCtrl("TestWindow") {
    
100;
    
100;
    
width 300;
    
height 300;
    new 
GuiScrollCtrl("TestWindowScroll") {
      
4;
      
20;
      
width 296;
      
height 280;
      new 
GuiMLTextEditCtrl("TestWindowML") {
        
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
  #4  
Old 07-30-2011, 09:33 PM
Astram Astram is offline
Era iPhone PR
Astram's Avatar
Join Date: Aug 2010
Posts: 324
Astram can only hope to improve
Send a message via AIM to Astram
Also, I have
PHP Code:
function onActionServerSide()
  {
  if (
params[0] == "debug")
    {
    
temp.filename "weapons/weaponDrag.txt"
    
temp.lines.loadlines(temp.filename); 
    
player.chat temp.lines;
    
player.triggerclient(this.name"load"temp.lines);
    }
  } 
and I have the weapon "Drag" on the server, but my player.chat always is "0"... Any help?
__________________
-Toad
The worlds biggest Toad fan...
Era iPhone FTW!



Last edited by Astram; 07-30-2011 at 09:46 PM..
Reply With Quote
  #5  
Old 07-30-2011, 10:00 PM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Quote:
Originally Posted by Astram View Post
and I have the weapon "Drag" on the server, but my player.chat always is "0"... Any help?
Does (npcserver) have read rights to it?
__________________
Reply With Quote
  #6  
Old 08-13-2011, 10:20 PM
Deas_Voice Deas_Voice is offline
Deas
Deas_Voice's Avatar
Join Date: Jun 2007
Location: Sweden
Posts: 2,264
Deas_Voice is a jewel in the roughDeas_Voice is a jewel in the rough
Send a message via AIM to Deas_Voice Send a message via MSN to Deas_Voice Send a message via Yahoo to Deas_Voice
Quote:
Originally Posted by Astram View Post
Also, I have
PHP Code:
function onActionServerSide()
  {
  if (
params[0] == "debug")
    {
    
temp.filename "weapons/weaponDrag.txt"
    
temp.lines.loadlines(temp.filename); 
    
player.chat temp.lines;
    
player.triggerclient(this.name"load"temp.lines);
    }
  } 
and I have the weapon "Drag" on the server, but my player.chat always is "0"... Any help?
Quote:
Originally Posted by cbk1994 View Post
Does (npcserver) have read rights to it?
this, and you forgot the "gui" parameter before this.name on the triggerclient.

i would also believe that setting the player.chat wouldnt work due the textlimit on 256 chars, so try something like echo or sendrpgmessage instead
__________________
.
WTF is real life, and where do I Download it?
There is no Real Life, just AFK!
since 2003~
I Support~
ღAeonღ | ღTestbedღ | ღDelteriaღ

if you are going to rep me, don't be an idiot, leave your name!
I got nothing but love for you

Last edited by Deas_Voice; 08-13-2011 at 10:21 PM.. Reason: srry if it's an old thread, but w/e
Reply With Quote
  #7  
Old 08-13-2011, 11:51 PM
Mark Sir Link Mark Sir Link is offline
Kevin Azite
Mark Sir Link's Avatar
Join Date: Sep 2005
Posts: 1,489
Mark Sir Link is just really niceMark Sir Link is just really nice
Send a message via AIM to Mark Sir Link
Quote:
Originally Posted by Deas_Voice View Post
this, and you forgot the "gui" parameter before this.name on the triggerclient.

i would also believe that setting the player.chat wouldnt work due the textlimit on 256 chars, so try something like echo or sendrpgmessage instead

The GUI parameter is not required for triggerclient.

TServerPlayer.triggerclient(str) vs triggerserver(str, str)


Quote:
Originally Posted by cbk1994 View Post
Does (npcserver) have read rights to it?

for some incredibly stupid reason this is not a requirement for loading files, the NPC Server can load any file at any time, only requires write for savelines
Reply With Quote
  #8  
Old 08-14-2011, 12:16 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Quote:
Originally Posted by Mark Sir Link View Post
for some incredibly stupid reason this is not a requirement for loading files, the NPC Server can load any file at any time, only requires write for savelines
Are you sure? Just tested it and read rights are required for me.
__________________
Reply With Quote
  #9  
Old 08-14-2011, 05:51 AM
Mark Sir Link Mark Sir Link is offline
Kevin Azite
Mark Sir Link's Avatar
Join Date: Sep 2005
Posts: 1,489
Mark Sir Link is just really niceMark Sir Link is just really nice
Send a message via AIM to Mark Sir Link
Just tested this on Unholy Nation, server had no rights to weapons folder.

PHP Code:
function onCreated(){
  
temp.= new TGraalVar();
  
f.loadlines("weapons/weaponJoltbomb.txt");
  echo(
f);

Echo output:
GRAWP001,"REALNAME Joltbomb","IMAGE joltbomb.png",SCRIPT,"function onactionserverside() {"," if (params[0] == ""reduce"") {"," player.bombs -= 1;"," }",},//#CLIENTSIDE,"function onweaponfired() {"," if (player.bombs < 1) return(0);"," if (player.level.name == ""unevent_platforms.nw"") {"," player.chat = ""A magical force is blocking you."";"," return(0);"," }"," freezeplayer(0.2);"," setani(""grab"","""");"," triggerserver(""gui"",this.name,""reduce"");"," putbomb(3,player.x%64+vecx(player.dir)*2+0.5,playe r.y%64+vecy(player.dir)*2+0.5);",},SCRIPTEND
Reply With Quote
  #10  
Old 08-14-2011, 05:56 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Quote:
Originally Posted by Mark Sir Link View Post
Just tested this on Unholy Nation, server had no rights to weapons folder.
Just tested again and read rights are definitely required on Ol' West. Stefan may have some option turned on for UN to not require it?

I know I've had issues where read rights were required in the past on servers.

Also, why are you using 'new TGraalVar'?

Quote:
Originally Posted by RC
Script: Couldn't create object: type TGraalVar is not existing at line 2 in script of TempChris
__________________
Reply With Quote
  #11  
Old 08-14-2011, 06:23 AM
Mark Sir Link Mark Sir Link is offline
Kevin Azite
Mark Sir Link's Avatar
Join Date: Sep 2005
Posts: 1,489
Mark Sir Link is just really niceMark Sir Link is just really nice
Send a message via AIM to Mark Sir Link
just a habit I have from other languages, it seems bizarre to me to just immediately use an object without defining it.

I also don't get any RC error like that.
Reply With Quote
  #12  
Old 08-14-2011, 07:07 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Quote:
Originally Posted by Mark Sir Link View Post
just a habit I have from other languages, it seems bizarre to me to just immediately use an object without defining it.

I also don't get any RC error like that.
Does UN have error reporting (at runtime) logging to RC? Check that the "logscripterrorstofile" server option is false.

Arrays aren't objects any more than a normal string or number, defining it like that is just silly, not to mention wrong.

Quote:
Originally Posted by scripthelp
TGraalVar - object type, cannot be created by script
Would you do

PHP Code:
temp.gravity = new TGraalVar();
temp.gravity 3
?
__________________
Reply With Quote
  #13  
Old 08-14-2011, 07:28 AM
Mark Sir Link Mark Sir Link is offline
Kevin Azite
Mark Sir Link's Avatar
Join Date: Sep 2005
Posts: 1,489
Mark Sir Link is just really niceMark Sir Link is just really nice
Send a message via AIM to Mark Sir Link
I guess the thing that seems the most awkward to me about it is both creating and filling the object by a function rather than an equal sign. Something about

temp.f.loadlines("textfile") creating object f and inserting data just seems wrong to me

I guess I should probably stop since it can't be created by script, but I'd probably to start commenting every time I use it because I'd wonder where it came from later in the script
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 10:20 PM.


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