MSG Box (Full Version)

All Forums >> [New Releases from Matrix Games] >> Command: Modern Operations series >> Mods and Scenarios >> Lua Legion



Message


vettim89 -> MSG Box (3/13/2021 8:40:36 PM)

Is there a way to embed game data into a msg box message? For example a message pops up when a ship has approached within a mile of it and the message reads: "Merchant ship (ship.name) reports that enemy naval forces are ordering them to stop?" The ship.name would be the ship being asked to stop




michaelm75au -> RE: MSG Box (3/13/2021 11:48:03 PM)

In a Lua script:
local ship = SE_GetUnit({name='SS Minow'})
local msg = 'Merchant ship (' .. ship.name .. ') reports that enemy naval forces are ordering them to stop'
ScenEdit_MsgBox (msg,0)




butch4343 -> RE: MSG Box (5/9/2021 11:40:32 AM)

Michael,

I wonder if you might be able to help me with something similar, I know am always asking for help, I have been learning , watched a couple of videos on you tube about scripting functions and am taking baby steps lol but huge leaps for me lol

I have discovered how to create a special action msg for a player and it works fine for fixed responses, ie XXX now added to airfield YYY

I want to be able to get a special action that will return a score, so I can use the following to print the score in the console

>> local y= ScenEdit_GetScore('Loop')
print(y)
53


And I can use ScenEdit_SpecialMessage('Loop','The Score Is') to get a pop up special action box that says The Score Is

What I cant see is how to combine the result of the score with the message , I tried :


local a= ScenEdit_GetScore('Loop')

ScenEdit_SpecialMessage('Loop','The Score Is ..(a)')


I bet this will be a real easy thing as well [8|]


That treats the whole lot as a string so I get 'The Score Is ..(a)'

So I guess what am asking is how do I add a string and a variable in a message?

I have tried
ScenEdit_SpecialMessage('Loop','The Score Is' and a) that got me a
ERROR: [string "Console"]:4: Invalid arguments to method call

Ive checked the Github page and the LUA documentation page and even tried a google search to no avail.I bet this will be a real easy thing as well [8|]


Regards

Butch







KnightHawk75 -> RE: MSG Box (5/9/2021 11:17:51 PM)

quote:

ORIGINAL: butch4343

...
What I cant see is how to combine the result of the score with the message , I tried :

local a= ScenEdit_GetScore('Loop')
ScenEdit_SpecialMessage('Loop','The Score Is ..(a)')

I bet this will be a real easy thing as well [8|]

That treats the whole lot as a string so I get 'The Score Is ..(a)'

So I guess what am asking is how do I add a string and a variable in a message?
....

When you want to append
Var .. ThingYouWantToAppend
examples:
-- print "Sometext " 1 through 10 
for i=1,10 do
  print("SomeText " .. i);
end
-- your example:
local a= ScenEdit_GetScore('Loop');
ScenEdit_SpecialMessage('Loop','The Score is '  .. a)

-- your example no intermediate var: 
ScenEdit_SpecialMessage('Loop','The Score is '  .. tostring(ScenEdit_GetScore('Loop') );

-- your example no intermediate var with old school html mark up to color Score text as Green: 
ScenEdit_SpecialMessage("Loop",'<P>The Score is <FONT color="#00FF00">'  .. tostring(ScenEdit_GetScore('Loop') .. '</FONT></P>'));


This is pretty dated (written for 5.0) but all the basic language concepts are mostly still the same in 5.3.x
Programming in Lua 5.0: https://www.lua.org/pil/contents.html#P1 (can find later versions on web or buy them.)
Concatenation: https://www.lua.org/pil/3.4.html

Lua 5.3.x manual (for the things that are different in 5.3): https://www.lua.org/manual/5.3/




KnightHawk75 -> RE: MSG Box (5/9/2021 11:48:51 PM)

BTW for those wanting to know what the options are for the numeric option values for MsgBox, and the exact return values when different things are pressed here they.
-- 6+ will result to 0 \ ie OkOnly.
--[[
gKH.Constants.MsgBoxType={}
gKH.Constants.MsgBoxType.OKOnly=0;
gKH.Constants.MsgBoxType.OKCancel=1;
gKH.Constants.MsgBoxType.AbortRetryIgnore=2;
gKH.Constants.MsgBoxType.YesNoCancel=3;
gKH.Constants.MsgBoxType.YesNoOnly=4;
gKH.Constants.MsgBoxType.RetryCancel=5;
gKH.Constants.MsgBoxResult={}
gKH.Constants.MsgBoxResult.OK = "OK";
gKH.Constants.MsgBoxResult.No = "No";
gKH.Constants.MsgBoxResult.Yes = "Yes";
gKH.Constants.MsgBoxResult.Cancel = "Cancel";
gKH.Constants.MsgBoxResult.Retry = "Retry";
gKH.Constants.MsgBoxResult.Ignore = "Ignore";
--]]
Example of getting input from user, and checking which button was pressed after you repeat their entry back to them.
local msgboxresult = ScenEdit_MsgBox("You entered the text: \n\r" .. tostring(ScenEdit_InputBox("Please enter some text:")),
4);
if msgboxresult == "Yes" then 
  ScenEdit_MsgBox('You pressed Yes.',0);
elseif msgboxresult == "No" then 
  ScenEdit_MsgBox('You pressed No.',0);
elseif msgboxresult == "Cancel" then 
  ScenEdit_MsgBox('Hey, you close the window before answering!',0);
else 
  ScenEdit_MsgBox('Um, we should never get here.',0);
end




butch4343 -> RE: MSG Box (5/12/2021 11:11:37 AM)

Knighthawk,

Thanks for this, I could'nt figure out the link between the two. As always your help has been invaluable mate.

Regards

Butch




Page: [1]

Valid CSS!




Forum Software © ASPPlayground.NET Advanced Edition 2.4.5 ANSI
0.75