Jump to content




[SOLVED] Cannot serialize file's contents


2 replies to this topic

Poll: Off-topic Poll :D

Does MC music satisfy you?

You cannot see the results of the poll until you have voted. Please login and cast your vote to see the results of this poll.
Vote Guests cannot vote

#1 Windows10User

  • Members
  • 62 posts
  • LocationC:\Minecraft\saves\stuff\computer

Posted 25 May 2018 - 05:46 PM

As the development of my OS went further (also plz tell me what the hell do coroutines even do in them), I decided to rewrite the bootloader and make a sound & logging API. Now, the part of the bootloader I wrote so far and the logging API work better than great, when I go ahead to play the boot sound, it throws this:

Posted Image

I seriously don't know what's wrong here. I'm sure my sound is formatted correctly, I even did a print on type(fs handle here) and it said table, so it indeed should have read the file and formatted it into a table.

Enough of my walls of text and time to see the code for yourself! :D

Bootloader:
os.loadAPI("DoorOS/apis/logging")
os.loadAPI("DoorOS/apis/wavesound")

term.clear()
term.setCursorPos(1, 1)
version = 0.1

cosversion = os.version()

if cosversion ~= "CraftOS 1.8" then
  logging.warn("Not running on COS 1.8, continue?")
  logging.warn("To continue, press Enter.")
  logging.warn("To exit, press any other key.")
  logging.warn("(NOTE: May be very unstable!)")
  local event, k, held = os.pullEvent("key")
  if k ~= keys.enter then
	error()
  end
end


logging.info("Running DoorOS v0.1a on "..cosversion)

local fcfg = fs.open("Boot/cfg.lua", "r")
local cfg = fcfg.readAll()
fcfg.close()

logging.info("Performing main files check...")

local files = {
  cfg.loader,
  "DoorOS/desktop.lua",
  "DoorOS/apis/graphics",
  "DoorOS/apis/compact",
  "DoorOS/apis/pastebin",
  "DoorOS/apis/updcheck",
  "DoorOS/apis/wavesound",
}

local missing = nil

for i, f in pairs(files) do
  if not fs.exists(f) then
	missing = {}
	table.insert(missing, f)
  end
end

if missing then
  logging.error("Boot-time fail.")
  logging.error("Missing file(s):")
  for i, f in pairs(missing) do
	logging.error(f)
  end
  logging.error("DoorOS cannot boot.")
  error()
end

logging.info("Files OK.")
logging.info("Scanning peripherals...")

peripherals = {}

for i, s in pairs(rs.getSides()) do
  if peripheral.getType(s) then
	if peripheral.getType(s) == "modem" then
	  if peripheral.wrap(s).isWireless() then
		peripherals["wifi_modem"] = s
	  else
		peripherals["eth_modem"] = s
	  end
	else
	  peripherals[peripheral.getType(s)] = s
	end
  end
end

logging.info("Found peripherals:")
for i, p in pairs(peripherals) do
  logging.info(i.." on side "..p)
end

if peripheral.find("speaker") then
  local sf = fs.open("DoorOS/sounds/boot.wave", "r")
  local s = textutils.unserialize(sf.readAll())
  sf.close()
  print(type(s))
  local ok, err = wavesound.play(s)
  if not ok then
	logging.warn("Could not play bootsound")
	logging.warn("Error: "..err)
  end
end

Wavesound API:
function play(snd)
  if type(snd) ~= "table" then
	return false, "snd is not a table"
  end

  local spkr = peripheral.find("speaker")
  if not spkr then
	return false, "no speaker found"
  end

  for i, s in pairs(snd) do
	spkr.playNote(s.note, tonumber(s.vol), tonumber(s.pitch))
  end

  return true
end

Sound file:
{
  {
	note = "snare",
	vol = "10",
	pitch = "1",
  }

  {
	note = "snare",
	vol = "10",
	pitch = "1",
  }

  {
	note = "snare",
	vol = "10",
	pitch = "1",
  }

  {
	note = "snare",
	vol = "10",
	pitch = "1",
  }

  {
	note = "snare",
	vol = "10",
	pitch = "1",
  }

  {
	note = "snare",
	vol = "10",
	pitch = "1",
  }

  {
	note = "snare",
	vol = "10",
	pitch = "1",
  }

  {
	note = "snare",
	vol = "10",
	pitch = "1",
  }

  {
	note = "snare",
	vol = "10",
	pitch = "1",
  }

  {
	note = "snare",
	vol = "10",
	pitch = "1",
  }
}

Any help is appreciated!

Edited by Windows10User, 25 May 2018 - 05:57 PM.


#2 SquidDev

    Frickin' laser beams

  • Members
  • 1,404 posts
  • LocationDoes anyone put something serious here?

Posted 25 May 2018 - 05:55 PM

You sound file isn't valid Lua, meaning textutils.unserialise returns nil. You need to add commas between each of the notes.

#3 Windows10User

  • Members
  • 62 posts
  • LocationC:\Minecraft\saves\stuff\computer

Posted 25 May 2018 - 05:57 PM

View PostSquidDev, on 25 May 2018 - 05:55 PM, said:

You sound file isn't valid Lua, meaning textutils.unserialise returns nil. You need to add commas between each of the notes.

Oh yeah, what a dumbo I am. Thanks!





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users