- Joined
- Sep 6, 2013
- Messages
- 6,742
I know there is File IO by Nestharus to read/write localy with JASS.
However, someone (@Wietlol ) needed to create a plain .txt file without the extra Preload-bullshit texts.
He wants clear output, because he does not read it with jass.
The output will be read by an other 3rd party program or so.
So the solution is to create a preload function that creates a .bat file.
Then you run the .bat file (manualy) and it will create a clean .txt file for you.
Just in case someone else is interested, here is a sample code:
Demo:
However, someone (@Wietlol ) needed to create a plain .txt file without the extra Preload-bullshit texts.
He wants clear output, because he does not read it with jass.
The output will be read by an other 3rd party program or so.
So the solution is to create a preload function that creates a .bat file.
Then you run the .bat file (manualy) and it will create a clean .txt file for you.
Just in case someone else is interested, here is a sample code:
JASS:
library Batch// v1.0 --hiveworkshop.com/threads/textfile.290375/
// Creates a .bat file.
//! novjass
//============ --------- API --------- =============
struct Batch
printStart takes nothing returns nothing
// just call when you start
print takes string s returns nothing
// prints "s"
printEnd takes nothing returns nothing
// call it when you end
string NL
// use to write in a new line
// it is 100% senseless to print it as standalone,
// so only use as part of your input
//! endnovjass
struct Batch extends array
public static string FOLDER = "Batch"
public static string NAME = "MyBat"
public static constant string NL = "\n"
public static method printStart takes nothing returns nothing
call PreloadGenClear()
call PreloadGenStart()
endmethod
public static method printEnd takes nothing returns nothing
set FOLDER = FOLDER + "\\"
call PreloadGenEnd(FOLDER + NAME + ".bat")
endmethod
public static method print takes string s returns nothing
call Preload("\")\r\n" + s + "\r\n;")
endmethod
endstruct
endlibrary
JASS:
library TextFile requires Batch // v1.0 --hiveworkshop.com/threads/textfile.290375/
// Creates a .bat file which will create a clean .txt file.
//! novjass
//============ --------- API --------- =============
struct TextFile
printStart takes nothing returns nothing
// just call when you start
print takes string s returns nothing
// prints "s" in same line
println takes string s returns nothing
// prints "s" and then jumps to next line
emptyLine takes nothing returns nothing
// prints an empty line
printEnd takes nothing returns nothing
// call it when you end
string NL
// use to write in a new line
//! endnovjass
struct TextFile extends array
public static string NAME = "MyText"
public static constant string NL = "%NL%"
private static string DIR_PATH = "\"" + NAME + ".txt\""
public static method printStart takes nothing returns nothing
call Batch.printStart()
set DIR_PATH = "\"" + NAME + ".txt\""
call Batch.print("echooff> " + DIR_PATH)
call Batch.print(Batch.NL)
call Batch.print("set NLM=^\r" + Batch.NL + Batch.NL + Batch.NL + "set NL=^^^%NLM%%NLM%^%NLM%%NLM%")
endmethod
public static method printEnd takes nothing returns nothing
call Batch.printEnd()
endmethod
public static method emptyLine takes nothing returns nothing
call Batch.print("echo.>> " + DIR_PATH)
endmethod
private static string temp = ""
public static method print takes string s returns nothing
set temp = temp + s
endmethod
public static method println takes string s returns nothing
if (StringLength(s) == 1) then
set s = "^" + s
elseif s == null or s == NL then
call Batch.print("echo.>> " + DIR_PATH)
return
endif
set temp = temp + s
call Batch.print("echo " + temp + ">> " + DIR_PATH)
set temp = ""
endmethod
endstruct
endlibrary
Demo:
JASS:
struct Demo
private static method init takes nothing returns nothing
set TextFile.NAME = "Worklist"
call TextFile.printStart()
call TextFile.println("1")
call TextFile.println("2")
call TextFile.print("3")
call TextFile.println("3")
call TextFile.print("5")
call TextFile.emptyLine()
call TextFile.print("5" + TextFile.NL)
call TextFile.println("6")
call TextFile.printEnd()
endmethod
private static method onInit takes nothing returns nothing
call TimerStart(CreateTimer(), 0.1, false, function thistype.init)
endmethod
endstruct
Last edited: