• file:Read ... () returns nil values
    9 replies, posted
I found several problems with file:Read...() functions. Sometimes they'll return NIL value instead of wanted value in some locations of given file (yes, file is binary format). I tried it with other programs and they reading all values just fine, but noooo only gmod returns nil. Possible fix or I need make some special magic?
Try to check file if it exists. Just think why file.Read() returns nil. Why you don't think it's because file what you are reading is not exists. For example: [LUA] local text if file.Exists("AssGay.txt", "DATA") then text = file.Read("AssGay.txt", "DATA") else text = "AssGay.txt isn't exists" end [/LUA]
[QUOTE=AirBlack;44694217]Try to check file if it exists. Just think why file.Read() returns nil. Why you don't think it's because file what you are reading is not exists. [/QUOTE] Its not file.Read(), I never used this function. It's theese funcs : [URL="http://wiki.garrysmod.com/page/Category:File"]http://wiki.garrysmod.com/page/Category:File[/URL] like ReadBool, ReadLong etc.. File is BINARY format NOT TEXT. Please read correctly main post next time.
If they return nil, it probably means they can't read next bytes as the type you are trying to read them as.
[QUOTE=Robotboy655;44695610]If they return nil, it probably means they can't read next bytes as the type you are trying to read them as.[/QUOTE] But they are exactly in defined order, they ARE correct bytes, I've read file(s) with my quickbms script and all values from file are correctly readed. But it's weird its' happening only in some possitions of file. And I could add its happening in " for i = n,n do" loop becouse I'm reading blocks of one Short and one Float, several times to get values.
post code
Can you send us the file?
I can only post a chunk of my code: [CODE] local as = F:Tell() for n = 0, bone_frames -1 do F:Seek(as+(6*n)) // This pretend reading fake nils after error local frame = F:ReadShort() local value = F:ReadFloat() if frame && value then majortable.BoneDefTable[bonename][frame] = value end [/CODE] Btw its not happening only in my file, I tried read mdl files and some my own created.
I can't help without at least an example of a file that can't be read. These functions all work for me.
[QUOTE=Willox;44695924]I can't help without at least an example of a file that can't be read. These functions all work for me.[/QUOTE] I can write this over and over time, many times, but at last. File can be read succesfully but not in gmod at all I'ts happening with all my reading scripts, I tried read mdl files (models), textures (vtf files), even simple rar files or sounds. In some cases reader read nothing, but only in loop (not loop at all, just x times do). But its happening only in some possitions of file. I can execute script several times but nil error will be in exactly same file possition as before. Maybye its caused highspeed function calling in loop?
Sorry, you need to Log In to post a reply to this thread.