Music Switch Widget not working...
Posted: 26 Aug 2007, 01:43
Could sombody help me with this?
I'm new to Lua.
It loads 'music.tdf' fine, but it can't load 'gutar.tdf' for some reason.
Any ideas?
I'm new to Lua.
Code: Select all
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--
-- file: cmd_switchmusic.lua
-- brief: switches the music.tdf to another file
-- author: URL_00
--
-- Copyright (C) 2007.
-- Licensed under the terms of the GNU GPL, v2 or later.
--
-------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------
function widget:GetInfo()
return {
name = "Music Switcher",
desc = "Switches the music playlist of AF's Music AI",
author = "url_00",
date = "04 Aug 2007",
license = "GNU GPL, v2 or later",
layer = 1,
enabled = false -- loaded by default?
}
end
-------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------
function widget:Initialize()
if io.open ("\music\music.tdf", "w") == nil
then
echo("Error loading music.tdf! Check your paths!")
else
local music = io.open ("\music\music.tdf", "w")
end
if io.open ("\music\gutar.tdf", "r") == nil
then
echo("Error loading gutar's music.tdf! Check your paths!")
else
local gutar = io.open ("\music\gutar.tdf", "r")
end
end
-------------------------------
function Say(msg)
Spring.SendCommands({'say ' .. msg})
end
function echo(msg)
Spring.SendCommands({"echo " .. msg})
end
-------------------------------
function widget:TextCommand(cmd)
local choice = ''
if cmd == 'gutar' then
choice = gutar
Refresh(choice, music)
echo("Gutar music loaded.")
else
choice = music
Refesh(choice, music)
echo("Error loading music! Check your paths!")
end
end
function Refresh(file, music)
for line in file:lines() do
music:write(line)
end
file:close()
end
-------------------------------------------------------------------------------------
Any ideas?