MasterZelgadis Posted April 13, 2017 Share Posted April 13, 2017 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 More sharing options...
Grimes Posted April 14, 2017 Share Posted April 14, 2017 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 Server, Scripting 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 More sharing options...
MasterZelgadis Posted April 18, 2017 Author Share Posted April 18, 2017 (edited) 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 April 18, 2017 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 More sharing options...
Grimes Posted April 20, 2017 Share Posted April 20, 2017 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 Server, Scripting 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 More sharing options...
Recommended Posts