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

Asked by Samuel Rheinmetall on 2020-05-24

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.

  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
    PlayMusic("music/NerzhulRescue" .. wargus.music_extension)

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

English Edit question
Wargus Edit question
No assignee Edit question
Last query:
Last reply:
Launchpad Janitor (janitor) said : #1

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

Hi Samuel,

sorry, no one is looking at this launchpad page anymore, we are over on github: 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:

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