Jump to content

TransmitMessage Script


Colmillo
Go to solution Solved by cfrag,

Recommended Posts

Hi!!

I have this script (works perfectly):

FL = 1
local function redGroupFirstLine()
timer.scheduleFunction(redGroupFirstLine, {}, timer.getTime() + 5)  

if trigger.misc.getUserFlag('RArm2') > 0
and trigger.misc.getUserFlag('RArm3') > 0
and trigger.misc.getUserFlag('RArt1') > 0
and FL == 1
then
	trigger.action.outTextForGroup(187, "Blue Group is going to first stop",10)
	trigger.action.outText("Blue Group is going to first stop", 5)
	trigger.action.activateGroup(Group.getByName('RED_SA6'), 1)
	trigger.action.setUserFlag('FirstLineOut', true)
	FL = 0
end
end
redGroupFirstLine()

But, I want to insert a 'TransmitMessage' when the flag 'FirstLineOut' is true, and I can't...

This is the message script:

   local msg = { 
     id = 'TransmitMessage', 
     params = {
       duration = 5,
       subtitle = "The first red line is accessible, \narmor 1 and 3 are proceeding to the first stop.",
       loop = false,
       file ="l10n/DEFAULT/KOH_firstline.ogg",
     } 
   }
Group.getByName('BLUE_ARMOR-2'):getController():setCommand(msg)

Thanks in advance

[sIGPIC][/sIGPIC]

Intel(R) Core(TM) i9-10900KF CPU @ 3.70GHz   3.70 GHz ROG STRIX Z490-E GAMING
RAM 128 M.2*2 2T total SSD*3 2.5T total
GeForce RTX 3090   Orion2 HOTAS F-16EX  Saitek Pro Rudder

Link to comment
Share on other sites

While I'm looking for a solution, I created a trigger that when the flag is true --> do script (and there I write what generates the message)

The main reason is that I use scripts in several missions, so the less I have to configure in the Mission Editor, the better.

[sIGPIC][/sIGPIC]

Intel(R) Core(TM) i9-10900KF CPU @ 3.70GHz   3.70 GHz ROG STRIX Z490-E GAMING
RAM 128 M.2*2 2T total SSD*3 2.5T total
GeForce RTX 3090   Orion2 HOTAS F-16EX  Saitek Pro Rudder

Link to comment
Share on other sites

I found out!!!
I forgot to insert "do" after "then", here's how it works:

MS = 1
local function message()
timer.scheduleFunction(message, {}, timer.getTime() + 5) 
if trigger.misc.getUserFlag('FirstLineOut') > 0 and MS == 1
then
do
local msg = { 
     id = 'TransmitMessage', 
     params = {
       duration = 15,
       subtitle = "The first red line is accessible, \narmor 1 and 3 are proceeding to the first stop.",
       loop = false,
       file ="l10n/DEFAULT/KOH_firstline.ogg",
     } 
   }
Group.getByName('BLUE_ARMOR-2'):getController():setCommand(msg)
end
MS = 0
end
end
message()

Thanks for the comments.

Cheers


Edited by Colmillo

[sIGPIC][/sIGPIC]

Intel(R) Core(TM) i9-10900KF CPU @ 3.70GHz   3.70 GHz ROG STRIX Z490-E GAMING
RAM 128 M.2*2 2T total SSD*3 2.5T total
GeForce RTX 3090   Orion2 HOTAS F-16EX  Saitek Pro Rudder

Link to comment
Share on other sites

  • Solution
45 minutes ago, Colmillo said:

I forgot to insert "do" after "then", here's how it works:

I'm happy it works for you, but I doubt that that was the root cause. There is no need for a 'do' after a 'then'. It's more likely that you had an extra 'end' somewhere, but that is not visible from the code that you originally posted

You may want to balance your code with some indentation to better see what level you are on. Something like this:

S = 1
local function message()
	timer.scheduleFunction(message, {}, timer.getTime() + 5) 
	if trigger.misc.getUserFlag('FirstLineOut') > 0 and MS == 1 then
		do
			local msg = { 
				 id = 'TransmitMessage', 
				 params = {
				   duration = 15,
				   subtitle = "The first red line is accessible, \narmor 1 and 3 are proceeding to the first stop.",
				   loop = false,
				   file ="l10n/DEFAULT/KOH_firstline.ogg",
				 } 
			   }
			Group.getByName('BLUE_ARMOR-2'):getController():setCommand(msg)
		end
		MS = 0
	end
end
message()

In above code you can delete the 'do' and the 'end' before MS = 0 

  • Like 1
Link to comment
Share on other sites

you're right, I never thought the indent was the problem.
Thank you so much

[sIGPIC][/sIGPIC]

Intel(R) Core(TM) i9-10900KF CPU @ 3.70GHz   3.70 GHz ROG STRIX Z490-E GAMING
RAM 128 M.2*2 2T total SSD*3 2.5T total
GeForce RTX 3090   Orion2 HOTAS F-16EX  Saitek Pro Rudder

Link to comment
Share on other sites

8 hours ago, Colmillo said:

you're right, I never thought the indent was the problem.

As long as it's coded correctly you don't need any indentation at all.  Indentation just realllllyyyyy helps debug what's going on in a much more visual way than having to trace through the code and figure out what belongs with what (i.e. what END goes with what IF or what DO).

Link to comment
Share on other sites

Mmm, yep... looking again, I found something very curious:
I think the real problem was this:

if trigger.misc.getUserFlag('FirstLineOut') > 0 and MS == 1
then


"Then" in the next paragraph, and the correct thing is:

if trigger.misc.getUserFlag('FirstLineOut') > 0 and MS == 1 then


The curious thing is that the "then" error was corrected with the "do" afterwards in the next paragraph.
I think I will never finish knowing the scripts 100%
🙂

[sIGPIC][/sIGPIC]

Intel(R) Core(TM) i9-10900KF CPU @ 3.70GHz   3.70 GHz ROG STRIX Z490-E GAMING
RAM 128 M.2*2 2T total SSD*3 2.5T total
GeForce RTX 3090   Orion2 HOTAS F-16EX  Saitek Pro Rudder

Link to comment
Share on other sites

9 hours ago, Colmillo said:

The curious thing is that the "then" error was corrected with the "do" afterwards in the next paragraph.

most likely you had an invisible control character messing up the script. Both versions are perfectly legal lua code and should not produce an error.

  • Like 1
Link to comment
Share on other sites

  • Recently Browsing   0 members

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