Thread Rating:
  • 2 Vote(s) - 4.5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
File Loader v1.0
#1
Implementation:

Code:
<module src="GO_wFileLoader.nud" type="server" /> // For windows
<module src="GO_lFileLoader.nud" type="server" /> // For linux

Squirrel function:
userpointer handler = fileOpen(string file, string fileMode)
bool fileExists(string filename)
bool fileClose(userpointer handler)
bool fileWrite(userpointer handler, string text)
string fileRead(userpointer handler)
bool fileRename(string oldname, string newname)
bool fileRemove(string filename)
int fileLength(userpointer handler)
Short example:

Code:
local file = fileOpen("test.txt", "r+")
if(file)
{
    print("File opened succesfully.");
    fileWrite(file, "Lorem ipsum...");
    fileClose(file);

    file = fileOpen("test.txt", "r+");
    local readString = fileRead(file); // fileRead functions now return line as string, there is no second parameter "buffer"
    print(readString);
    fileClose(file);
}
Download version 1.0:
Windows: https://mega.nz/#!CYYGiRSb!wthbuogO5kseP...yg4hvXRQcA
Linux: https://mega.nz/#!KIQEQawK!uEKve1P1wTWSQ...EPZ2Y-MTkc

Creditsy:
Sative - wersja 0.3
Reply
#2
Well actually i have a problem with this module. For example when i use this 'fileWrite(file, "Lorem ipsum...");' of course before i added 'local file = fileOpen("test.txt", "r+")' then it saves only 4 words i mean when i open test.txt file there is only 'lore' inside, can somebody tell me what i am doing wrong?
Reply
#3
http://squirrel-lang.org/doc/sqstdlib2.html#d0e159
Try this.
Reply
#4
Shocked 
(07.12.2015, 09:53)Sative Wrote: http://squirrel-lang.org/doc/sqstdlib2.html#d0e159
Try this.
Not really sure what you mean.   I mean I asked if my code is bad or is this module broken?
Reply
#5
Probably module, but you would use w+ as parameter.
Reply
#6
It doesnt matter if there is w+, r+ or whatever else, it always cut text after 4 letters.
Reply
#7
Use the downloadlink in this thread. The fileloader that comes with GO does that for some reason. Had that problem too initially, before downloading it manually.
Reply
#8
(07.12.2015, 14:04)HammelGammel Wrote: Use the downloadlink in this thread. The fileloader that comes with GO does that for some reason. Had that problem too initially, before downloading it manually.

oh dude, awesome, it works. Thank you so much. ++++++
Reply
#9
You're welcome Smile
I'm getting more and more confused with this. This is my code:

Code:
local file = fileOpen("saveFiles/Players/" + name + ".txt", "r+");
local buffer = "";

while(fileRead(file, buffer))
{
   buffer = format("%s", buffer);
}

The formatting seems to crash the server most of the time (Not always) when one of the lines in the file contains a very long string.

"test"

 doesn't crash, but

"ITSC_LIGHTHEAL{equipped{0}amount{1}}ITMI_RAKE{equipped{0}amount{1}}ITFO_APPLE{equipped{0}amount{199}}ITPL_TEMP_HERB{equipped{0}amount{1}}" does.

When I don't format, it doesn't crash and when I print out the buffer-variable, it works fine, concatenation doesn't work properly though. When concatenating it will only use a few letters and cut the rest off for some reason. I need to concatenate though, since there seems to be a maximum length when using fileRead and I am saving the inventory of the players as a big string.

I'm running out of ideas how to work around this, so: What am I doing wrong? O.o I just don't get it.
Reply
#10
Only way to fix it is probably recompile it, and fix bugs.
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)