Page 1 of 1

Music Switcher Widget

Posted: 05 Aug 2007, 19:27
by url_00
Well, I don't know how to program in Lua, so this is probley all worng.
That's why im posting it here! :P
So, this should copy one file, and put it in another, right?

Code: Select all

-------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------

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
	    print("Error loading music.tdf! Check your paths!")
	else
		local music = assert(io.open("../music/music.tdf", "w"))
	end
	if io.open("../music/gutar/music.tdf", "r") == nil
	    print("Error loading gutar's music.tdf! Check your paths!")
	else
		local gutar = assert(io.open("../music/gutar/music.tdf", "r"))
	end
	if io.open("../music/def/music.tdf", "r") == nil
	    print("Error loading default music! Check your paths!")
	else
	    local def = assert(io.open("../music/def/music.tdf", "r")
	end
end

-------------------------------

function Say(msg)
	Spring.SendCommands({'say ' .. msg})
end

function echo(msg)
	Spring.SendCommands({"echo " .. msg})
end

-------------------------------
local choice = ''

function widget:TextCommand(cmd)
	if cmd == 'gutar' then
	    choice = cmd
		Refresh(choice)
		echo("Gutar music loaded.")
	else
	    choice = def
	    Refesh(choice)
	    echo("Error loading music! Check your paths!")
	end
end
	
function Refresh(file)
	local count = 1         -- reads the file, line by line
	while true do
		local line = file:io.read()
		if line == nil then break end
		music:io.write(line,"\n")       -- writes the file, line by line
		count = count + 1
	end
end

-------------------------------------------------------------------------------------
Basicly, I'm trying to make playlists for AF's Music AI thingy.
Will it work?

Posted: 06 Aug 2007, 00:00
by AF
due to the fail that is the lua <-> AI interface, or rather the lack of one, I dont see how your going to change the playlist of my groupAI.

Posted: 06 Aug 2007, 03:58
by url_00
Im going to edit the music.tdf text file (a.k.a. replace it with another one)
Then restart the Music Ai.
It should work, but I don't know how to copy files in LUA,
so right now, I'm more or less reading only. :cry:

Anyways, I just need to know how to copy a file (like "gutar.tdf") into "music.tdf".

Posted: 06 Aug 2007, 04:09
by jK
@url_00: you search the io and os standard lua libraries.

@AF: groupAIs can add special buttons to the unit commandlist or not? (see moho upgrader etc.), so the groupAI can recieve cmds you give them with lua (with giveordertounit). so there is a lua->groupAI interface ... (that's enough for a "next title" button for example)

Posted: 06 Aug 2007, 04:52
by url_00
Argh! My Commands are not working! :evil:
Were text commands disabled?

Posted: 06 Aug 2007, 04:53
by AF
If you send a comamnd to a unti udner a grouPAI, the unit recieves it, not the groupAI. You need to send the group a command, not the unit.

The command only shows when the group is selected, not individual units.

Posted: 06 Aug 2007, 05:02
by trepan
-- LuaUI: select a group, and give the group an order
local selUnits = Spring.GetSelectedUnits()
Spring.SendCommands({'group ' .. groupNum .. ' select'})
Spring.GiveOrder(customID, {param1, param2, etc...}, options)
Spring.SelectUnitArray(selUnits)

P.S. A Spring.GiveOrderToGroup(groupID, cmdID, params, options) would be
nice to have, but the current LuaUI calls can pass custom commands to GroupAIs ;-)

Posted: 06 Aug 2007, 15:59
by url_00
AF wrote:If you send a comamnd to a unti udner a grouPAI, the unit recieves it, not the groupAI. You need to send the group a command, not the unit.

The command only shows when the group is selected, not individual units.
I ment like the "/luaui gutar" commands, but thanks for the info. :wink: