How do I play a music file using a trigger on a campaign map?

Asked by Samuel Rheinmetall

Hello everyone. Firstly, let me congratulate and thank you for all your hard work on Wargus/Stratagus, I'm spending many hours on this, learning how to make my own campaign with my own very units (which I only succeeded on Wargus and please dont tell my gf)... But there's something holding me back... How to play a music file using a trigger... When I trigger it, the music plays repeteadly, don't know really how to explain it.. (it wants to play but there's something that doesn't let it and instead loops the first second of the song, but when I pause the game, the song plays just fine)

Some background: " It's a rescue mission (my team is Number 5, black), the ones I have to rescue are red (or team 0)

Here is what I have: This goes on the "_c.sms" campaign file.

-- When I rescue them, the song should play but instead I get a loop of the first second of the song and it plays normally only if I pause the game.

AddTrigger(
  function() return GetPlayerData(0, "TotalNumUnits") == 0 end,
  function() return PlayMusic("music/NerzhulRescue" .. wargus.music_extension) end)

And if I use a variable, like this, the game crashes before loading the mission intro:

function GetPlayerData(0, TotalNumUnits)
 if (TotalNumUnits == 0) then
    StopMusic()
    PlayMusic("music/NerzhulRescue" .. wargus.music_extension)
 end

I'm not a programmer or anything, but I'm kinda understaning this .lua stuff.
Any help will be appreciated, I don't know where else to ask, I'm still waiting for my Stratagus forum account to be activated.

Question information

Language:
English Edit question
Status:
Expired
For:
Wargus Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Launchpad Janitor (janitor) said :
#1

This question was expired because it remained in the 'Open' state without activity for the last 15 days.

Revision history for this message
timfelgentreff (timfelgentreff) said :
#2

Hi Samuel,

sorry, no one is looking at this launchpad page anymore, we are over on github: https://github.com/Wargus/wargus/. It's better to ask question in an issue there.

Regarding your question, the problem is that the trigger is repeatedly executed and should return false if it should be removed. So I think your trigger should look something like:

AddTrigger(
  function() return GetPlayerData(0, "TotalNumUnits") == 0 end,
  function()
    PlayMusic("music/NerzhulRescue" .. wargus.music_extension)
    return false
  end)