How can you make the function File:Read() to return only one line
6 replies, posted
Well you know ... [url]https://wiki.garrysmod.com/page/File/Read[/url]
If the file contents are:
aaaaaaaaaaaaaaaa
bbbbbbbbbbbbbbbb
ccccccccccccccccccc
On the first iteration to "aaaaaaaaaaaaaaaa", second "bbbbbbbbbbbbbbbb" and so on ...
Is it maybe ( I do not have access to Gmod right now .. ):
[code]
local Line = "X" -- Just to be something
while(Line) do
print(F:Read())
end
[/code]
.. to print the lines sequentially ?
just split it up, lines:Split("\n") after reading everything
-snip-
Guys, reading the whole file is one big bad idea... Imagine when the database grows like hell ( which it is :D )
Now I'm reading it symbol by symbol, bit it's slow ...
[url]https://raw.githubusercontent.com/dvdvideo1234/TrackAssemblyTool/master/data/trackassembly/dsv/sv_TRACKASSEMBLY_PIECES.txt[/url]
glua doesn't have file handle support
and you should probably consider a better storage method
[QUOTE=Giraffen93;49664234]Glua doesn't have file handle support[/QUOTE]
Are you talking about handle ( which is a number), file pointer or a file object.
I do recall that glua supports the last two. How can I then easily call File:Read(1) ??
File handle as it is I think it's not applicable for glua ( as you cannot call 42:Read(1) ),
but this does not show how it is connected to the functionality reading one line at a time ??
[QUOTE=Giraffen93;49664234]You should probably consider a better storage method[/QUOTE]
Yes maybe, CSV ( comma separated values ) seems the better way so far. If you got any Ideas,
I am listening. :D
[QUOTE=dvd_video;49664278]Are you talking about handle ( which is a number), file pointer or a file object.
I do recall that glua supports the last two. How can I then easily call File:Read(1) ??
File handle as it is I think it's not applicable for glua ( as you cannot call 42:Read(1) ),
but this does not show how it is connected to the functionality reading one line at a time ??
Yes maybe, CSV ( comma separated values ) seems the better way so far. If you got any Ideas,
I am listening. :D[/QUOTE]
file handles, as in other languages where you can manually read x amount of bytes or whatever, does not exist in glua, only in "pure" lua
use an sql database, if you're going to distribute it, it can load once from the file to insert into the db on startup to reduce load
Sorry, you need to Log In to post a reply to this thread.