Jump to content

Assign a function to a radio command


MasterZelgadis

Recommended Posts

I have a function that is called by:

sqs.AddSoundToCoalition(2, "soundfile.ogg", 14)

Basically adds a soundfile to a cache table, which will then be played one after another. Works if I call it via Do Script.

 

But now I want to have a sound added when I use a radio command. I have:

mStat = missionCommands.addSubMenu("Mission Tasks")

Works, gives me F10 -> Mission Tasks

 

But now I want to add a command to it:

mMain = missionCommands.addCommand("Take control of Tskhinvali", mStat, sqs.AddSoundToCoalition, { 2,"soundfile.ogg",14 })

 

It adds the radio command, but the function does not work. How can I attach the function to the radio command?

"Sieh nur, wie majestätisch du durch die Luft segelst. Wie ein Adler. Ein fetter Adler."

http://www.space-view.net

Link to comment
Share on other sites

It is passing a table to sqs.addSoundToCoalition() instead of 3 separate values. So you can either make sqs.AddSoundToCoalition() accept a table, or perhaps replacing {} with () in that function call might work. I've never actually tried using () to group the arguments together, so I don't know for sure if it will work. Any function I call with mission commands I've always had it accept a table of values.

The right man in the wrong place makes all the difference in the world.

Current Projects:  Grayflag ServerScripting Wiki

Useful Links: Mission Scripting Tools MIST-(GitHub) MIST-(Thread)

 SLMOD, Wiki wishlist, Mission Editing Wiki!, Mission Building Forum

Link to comment
Share on other sites

Can I overload that function in lua, like in c#?

like this:

 

function addSoundToCoalition(int side, string file, int duration)
  // do some magic
end

function addSoundToCoalition(table)
  addSoundToCoalition(table[0], table[1], table[2])
end

 

edit: hm, doesn't work. even a seperate function does not work..

 

another edit: ah, overloading does not work, but the second function. But the table index starts with 1, not 0


Edited by MasterZelgadis

"Sieh nur, wie majestätisch du durch die Luft segelst. Wie ein Adler. Ein fetter Adler."

http://www.space-view.net

Link to comment
Share on other sites

You'd have to make your own function that accepts overloading to convert it to the correct format. What you've done above would just redefine the function. So you could do something like:

function addSoundToCoalition(val, file, duration)
local s, f, d = val, file, duration
if type(val) == 'table' then
	s = val.side
	f = val.file
	d = val.duration
end
-- Whatever
end

So the function will work either if the first value is a table or a side id. May be a good idea to add further error checking to make sure the table is complete. But I think it is a better idea to have the table with a relevant key/value format rather than indexed numerically. At least for this specific functionality.

The right man in the wrong place makes all the difference in the world.

Current Projects:  Grayflag ServerScripting Wiki

Useful Links: Mission Scripting Tools MIST-(GitHub) MIST-(Thread)

 SLMOD, Wiki wishlist, Mission Editing Wiki!, Mission Building Forum

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...