Message Box Format

All discussions & material related to Command's Lua interface

Moderators: michaelm75au, angster, RoryAndersonCDT, MOD_Command

Post Reply
User avatar
vettim89
Posts: 3668
Joined: Fri Jul 13, 2007 11:38 pm
Location: Toledo, Ohio

Message Box Format

Post by vettim89 »

First here is the code

Code: Select all

local SUB1=ScenEdit_GetKeyValue('SUB1')
if SUB1==nil then 
SUB1='0'
end
local SUB2=ScenEdit_GetKeyValue('SUB2')
if SUB2==nil then 
SUB2='0'
end
local SUB3=ScenEdit_GetKeyValue('SUB3')
if SUB3==nil then 
SUB3='0'
end
local SUB4=ScenEdit_GetKeyValue('SUB4')
if SUB4==nil then 
SUB4='0'
end
local SUB5=ScenEdit_GetKeyValue('SUB5')
if SUB5==nil then 
SUB5='0'
end
local SUB6=ScenEdit_GetKeyValue('SUB6')
if SUB6==nil then 
SUB6='0'
end
local SUB7=ScenEdit_GetKeyValue('SUB7')
if SUB7==nil then 
SUB7='0'
end
local SUB8=ScenEdit_GetKeyValue('SUB8')
if SUB8==nil then 
SUB8='0'
end
local SUB9=ScenEdit_GetKeyValue('SUB9')
if SUB9==nil then 
SUB9='0'
end
local SUB10=ScenEdit_GetKeyValue('SUB10')
if SUB10==nil then 
SUB10='0'
end
local SURFACE1=ScenEdit_GetKeyValue('SURFACE1')
if SURFACE1==nil then 
SURFACE1='0'
end
local SURFACE2=ScenEdit_GetKeyValue('SURFACE2')
if SURFACE2==nil then 
SURFACE2='0'
end
local SURFACE3=ScenEdit_GetKeyValue('SURFACE3')
if SURFACE3==nil then 
SURFACE3='0'
end
local mess='The remaining telports are:\n\nSUB 1  ('..SUB1..')\n\nSUB 2  ('..SUB2..')\n\nSUB 3  ('..SUB3..')\n\nSUB 4  ('..SUB4..')\n\nSUB 5  ('..SUB5..')\n\nSUB 6  ('..SUB6..')\n\nSUB 7  ('..SUB7..')\n\nSUB 9  ('..SUB9..')\n\nSUB 10  ('..SUB10..')\n\nSURFACE 1  ('..SURFACE1..')\n\nSURFACE 2  ('..SURFACE2..')\n\nSURFACE 3  ('..SURFACE3..')'
ScenEdit_MsgBox(mess, 1)
Now I have a bunch of special actions that allow the player to teleport units in the first few hours of the scenario. I was trying to create a Special Action with the above code so the player could check on how many of each teleports that are remaining. The message box pops up but is tiny and all the text is smashed. Also the message is incorrect as it reads: SUB 1 ()
SUB 2 ()
etc

With the error check built in as all the Key Values are nil in this iteration, the values should all be converted to '0'.

So I have two questions: why am I not getting the proper data inserted into the message? I have used the ('..variable..') syntax before and it works. Secondly, why is my message box so small and more importantly is there a way to make it bigger?

Thanks as always. I have been coding a lot this weekend and my brain is a bit fried. Just hoping you nice people can detangle this for me
"We have met the enemy and they are ours" - Commodore O.H. Perry
musurca
Posts: 168
Joined: Wed Jul 15, 2020 10:06 pm
Contact:

Re: Message Box Format

Post by musurca »

1) SE_GetKeyValue(...) never returns nil. It returns an empty string if there's no entry -- check for that instead.

2) You can't adjust the size of SE_MsgBox(...), unfortunately -- there's a hard character limit beyond which your messages are just truncated. For longer messages with special formatting, use SE_SpecialMessage(...) instead (which uses HTML tags).
Last edited by musurca on Tue May 31, 2022 6:19 pm, edited 1 time in total.
User avatar
vettim89
Posts: 3668
Joined: Fri Jul 13, 2007 11:38 pm
Location: Toledo, Ohio

Re: Message Box Format

Post by vettim89 »

musurca wrote: Mon May 30, 2022 8:48 pm 1) SE_GetKeyValue(...) never returns nil. It returns an empty string if there's no entry -- check for that instead.

2) You can't adjust the size of SE_MsgBox(...), unfortunately -- there's a hard character limit beyond which your messages are just truncated. For longer messages with special formatting, use SE_SpecialMessage(...) instead (which also supports HTML tags).
I tried using special message but the text didn't accept the \n for a new line - it just appeared as one continuous line which is very hard to read
"We have met the enemy and they are ours" - Commodore O.H. Perry
musurca
Posts: 168
Joined: Wed Jul 15, 2020 10:06 pm
Contact:

Re: Message Box Format

Post by musurca »

That's right — a "\n" won't read as a newline to SE_SpecialMessage(...) because it uses HTML formatting. Use a "<br>" tag instead.
User avatar
vettim89
Posts: 3668
Joined: Fri Jul 13, 2007 11:38 pm
Location: Toledo, Ohio

Re: Message Box Format

Post by vettim89 »

musurca wrote: Tue May 31, 2022 6:18 pm That's right — a "\n" won't read as a newline to SE_SpecialMessage(...) because it uses HTML formatting. Use a "<br>" tag instead.
I am just posting this so others can see the HTML code. There are some minor variations from Java and the text in SE_MessageBox

Code: Select all

local SUB1=ScenEdit_GetKeyValue('SUB1')
if SUB1=='' then 
SUB1='0'
end
print(SUB1)
local SUB2=ScenEdit_GetKeyValue('SUB2')
if SUB2=='' then 
SUB2='0'
end
local SUB3=ScenEdit_GetKeyValue('SUB3')
if SUB3=='' then 
SUB3='0'
end
local SUB4=ScenEdit_GetKeyValue('SUB4')
if SUB4=='' then 
SUB4='0'
end
local SUB5=ScenEdit_GetKeyValue('SUB5')
if SUB5=='' then 
SUB5='0'
end
local SUB6=ScenEdit_GetKeyValue('SUB6')
if SUB6=='' then 
SUB6='0'
end
local SUB7=ScenEdit_GetKeyValue('SUB7')
if SUB7=='' then 
SUB7='0'
end
local SUB8=ScenEdit_GetKeyValue('SUB8')
if SUB8=='' then 
SUB8='0'
end
local SUB9=ScenEdit_GetKeyValue('SUB9')
if SUB9=='' then 
SUB9='0'
end
local SUB10=ScenEdit_GetKeyValue('SUB10')
if SUB10=='' then 
SUB10='0'
end
local SURFACE1=ScenEdit_GetKeyValue('SURFACE1')
if SURFACE1=='' then 
SURFACE1='0'
end
local SURFACE2=ScenEdit_GetKeyValue('SURFACE2')
if SURFACE2=='' then 
SURFACE2='0'
end
local SURFACE3=ScenEdit_GetKeyValue('SURFACE3')
if SURFACE3=='' then 
SURFACE3='0'
end

local mess2='The remaining telports are:<br><br>SUB1............'..(SUB1)..'<br>SUB2............'..(SUB2)..'<br>SUB3............'..(SUB3)..'<br>SUB4............'..(SUB4)..'<br>SUB5............'..(SUB5)..'<br>SUB6............'..(SUB6)..'<br>SUB7............'..(SUB7)..'<br>SUB8............'..(SUB8)..'<br>SUB9............'..(SUB9)..'<br>SUB10..........'..(SUB10)..'<br>SURFACE1....'..(SURFACE1)..'<br>SURFACE2....'..(SURFACE2)..'<br>SURFACE3....'..(SURFACE3)
ScenEdit_SpecialMessage('USSR', mess2)
It works as intended. I used the '...' because I couldn't figure out the tab character. I guess there is not <tab> in HTML. Or that is what I could figure out. I am not...repeat...not learning yet another coding language
"We have met the enemy and they are ours" - Commodore O.H. Perry
musurca
Posts: 168
Joined: Wed Jul 15, 2020 10:06 pm
Contact:

Re: Message Box Format

Post by musurca »

https://www.geeksforgeeks.org/how-to-in ... -html-css/

Code: Select all

Regular space = &nbsp;

Two spaces  gap = &ensp;

Four spaces    gap = &emsp;
Welcome to 1993!
Post Reply

Return to “Lua Legion”