Files

> > CS2D > Lua Scripts > EasyIO [Pro]
Files overviewCS2D overviewLua Scripts overview

English EasyIO [Pro] >

20 comments2 kb, 477 Downloads

old EasyIO [Pro]

sixpack
User Off Offline

Hello Unreal Software scripters.
This is a developer release so if you're a server owner and not a scripter, you won't need this file.
This is a script all about making File IO easier. Nowadays reading and writing to files is too complicated making newbies (noobs) avoid it in their scripts. With this patch, they all become clearer. You have 6 'commands' (functions) you can use:
> readfile(filepath)
> savefile(text, filepath)
> readlinefile(file, line)
> copyfile(original, clone)
> writefile(text, file, mode)
> logdata(text, file)

Too complicated for you? Get the Lite version for starters by clicking here

These are making the entire IO System much easier. Let me give you an example.

File Reading
Before:
1
2
3
4
5
6
7
8
if(io.open("test.txt")~=nil) then
for p in io.lines("test.txt") do
l = p
if(l~=nil)then
--You got it
end
end
end
After:
1
l = readfile("test.txt") --You got it!

File Writting:
Before:
1
2
3
io.output(io.open("test.txt", "w+"))
io.write("HELLO WORLD")
io.close()
After:
1
savefile("HELLO WORLD", "test.lua")

Explanation of commands:
-readlinefile(file, line)
This command will return the text of the file of a specific file you need, example is line 2 of test.txt
-copyfile(original, clone)
This command will make a copy of a file (for backup?), example is copying moneysaves.txt to another folder an naming them moneysaves_backup.txt
-writefile(text, file, mode)
Same as savefile but you can write in a specific mode (w+, a etc), example is writing hi on file test.txt in the end of the file.
-logdata(text, file)
Logs some data to a file so you can keep logs of everything happened. Example is logging all bomb defuses to bombs.txt. Please note that this command adds in front of text full date + time of the server.

To use these functions, place easyio.lua to your scripts folder and use the following code to the TOP of the script that runs FIRST!
1
dofile("sys/lua/easyio.lua")--ByDaKnOb :P

I will add more as you suggest, keep the good ratings and the comments
Approved by Yates

Download Download

2 kb, 477 Downloads

Comments

20 comments
To the start Previous 1 Next To the start

Log in!

You need to log in to be able to write comments!Log in

old Don't use this!

Torque
User Off Offline

I would strongly advice any scripter not to try and use this script. It doesn't work 'out of the box' as promised, it is badly written and there is no error handling.
readfile only returns the first line, readlinefiles doesn't work, logdata starts the file with an unwanted newline and I haven't even bothered testing the rest of the functions.
A missed opportunity because a script like this would be very useful to beginners and lazy people like me if it was done properly. Instead I've wasted half an hour figuring out what was wrong and ended up using the standard lua io functions anyway.

old Reply

sixpack
User Off Offline

@user maPmaKer: Thanks
@user Flacko: ReadFile is from Lite version and reads only first line since it's made for newbies.
Fix for linereader already made. I just corrected it a few hrs. ago.

old

Flacko
User Off Offline

Then you should test again (I guess?)

readfile() only reads the first line of a file.
Stop using io.lines that way, that's not how it works.
Try it yourself:
1
print(readfile('Readme.txt'))
Output: Thank you for downloading Counter-Strike 2D!
(yes, there more than 20 lines missing)

readlinefile() Doesn't work. Again you're using io.lines the wrong way.
Try it yourself:
1
print(readlinefile('Readme.txt',2))
Output: LUA ERROR: blah blah blah

Not just that, but in both functions you open file handles to test if the file exists and you never close these handles.

It's inherent that all functions that call readfile() and readlinefile() are also working like crap.

Consider fixing them for all the users that said they'd use this in their scripts...
edited 1×, last 25.10.11 04:05:26 am

old

maPmaKer
User Off Offline

user HeroBurak 's rating should be removed for real. About DaKnOb's file is really nice.
I like it!

old

Infinite Rain
Reviewer Off Offline

Quote
@user HeadHunter_Tn: Always here to help.

Actually he is banned
I like it!

old Code Optimization

sixpack
User Off Offline

@user DannyDeth: Then it could be about a similar language I know.. Or PHP. Anyways, I will optimize it in the next update, feel free to PM me any code you want to be added to this.
@user Zins: Always here to help.

old

Zins
User Off Offline

this is awesome good job daknob
I like it!

old

DannyDeth
User Off Offline

@DaKnOb:
Then you read something from a very dodgy source. 'and' in lua:
1
not(statement1 [XOR] statement2)
is something like that. Btw there is no XOR in Lua itself, that is just pseudo code.

old Reply

sixpack
User Off Offline

@user HeroBurak: Do *NOT* rate files without briefly exploring them.
@user DannyDeth: This is just a file upload and you are not forced to use this. BTW I read somewhere that if(statement1 and statement2) uses more CPU power than the other one so I prefer the other one.
@user Flacko: I tested every single function in this script...

old

DannyDeth
User Off Offline

Really, your functions are superfluous and also rather crude.

And, really?
1
local unix = os.time()
I'm totally amped for UNIX timestamps, but do you have to define the greatness that is UNIX as a local variable that contains a time and date? That is plain derogatory!

Yeah, once again, no rating.

EDIT:
1
2
if(text~=nil)then
	if(file~=nil) then
Here's what I mean by crude. You could really shorten that:
1
if( text~=nil and file~=nil ) then

EDIT2:
Here's what I mean by superfluous ( and a slight example of crudeness) ::
1
o.write(""..gettime().." - "..text)
Why do you have the "".. there?
1
o.write(gettime().." - "..text)
Would have done fine.

old

Kel9290
User Off Offline

nice, but it easy to make, make writeline or somethin, that writes text in line X of file
I like it!

old

Flacko
User Off Offline

@user HeroBurak: If the file doesn't exist, the functions seem to return false (both in reading and writing)

Anyways, I don't like this. The functions are too long for doing "trivial shit" and some of them aren't working correctly (did somebody even test the readfile(), readlinefile() functions?)

old

Bowlinghead
User Off Offline

Nice idea!
I will use it for next script when I use I/O.
I like it!

old

Apache uwu
User Off Offline

It returns nil or an error? I don't think his file is bad :c

old

palomino
User Off Offline

@user HeroBurak: The lua makes a file, idiot. And reads an existing one.
I like it!

old

HeroBurak
BANNED Off Offline

Yeah..

So what if the file doesn't exist?
Trivial shit..
edited 1×, last 23.10.11 11:17:49 pm

old

Apache uwu
User Off Offline

I like it custom functions well made

old

Infinite Rain
Reviewer Off Offline

Hmm you give me some idea...
I like it!

old Reply

sixpack
User Off Offline

My pleasure to make things easier.

old

Infinite Rain
Reviewer Off Offline

Very awesome!
Thanks
I like it!
To the start Previous 1 Next To the start