Page 1 of 1

MSG Box

Posted: Sat Mar 13, 2021 6:40 pm
by vettim89
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

RE: MSG Box

Posted: Sat Mar 13, 2021 9:48 pm
by michaelm75au
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)

RE: MSG Box

Posted: Sun May 09, 2021 8:40 am
by butch4343
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




RE: MSG Box

Posted: Sun May 09, 2021 8:17 pm
by KnightHawk75
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:

Code: Select all

-- 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/

RE: MSG Box

Posted: Sun May 09, 2021 8:48 pm
by KnightHawk75
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.

Code: Select all

--[[
 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.

Code: Select all

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
 

RE: MSG Box

Posted: Wed May 12, 2021 8:11 am
by butch4343
Knighthawk,

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

Regards

Butch