Page 1 of 1

[SOLVED]Need help with love.data.unpack

Posted: Wed Jan 31, 2024 9:43 pm
by abyssol

Code: Select all

local file = love.filesystem.read("a.bin")
local s = love.data.unpack("I4", file, 5)

-- is any difference between above and below?

local file = love.filesystem.newFile("a.bin")
file:open("r")
file:seek(4)
local s = love.data.unpack("I4", file:read(4))
-- err: data string too short
local s = love.data.unpack("I4", file:read())
-- err: data string too short

Re: Need help with love.data.unpack

Posted: Wed Jan 31, 2024 10:07 pm
by abyssol
SOLVED: I found that I must write down argument #3 'pos' which default is 1. (start of string

Code: Select all

love.data.unpack("I4", file:read(4), 1)
It is no 1 by default as said in wiki

Re: [SOLVED]Need help with love.data.unpack

Posted: Wed Jan 31, 2024 10:41 pm
by abyssol
and I was stupid
I didn't notice that file:read() returns two values :P