[SOLVED]Need help with love.data.unpack

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
abyssol
Prole
Posts: 25
Joined: Wed Nov 03, 2021 6:20 am

[SOLVED]Need help with love.data.unpack

Post 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
Last edited by abyssol on Wed Jan 31, 2024 10:40 pm, edited 2 times in total.
abyssol
Prole
Posts: 25
Joined: Wed Nov 03, 2021 6:20 am

Re: Need help with love.data.unpack

Post 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
abyssol
Prole
Posts: 25
Joined: Wed Nov 03, 2021 6:20 am

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

Post by abyssol »

and I was stupid
I didn't notice that file:read() returns two values :P
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 6 guests