Page 1 of 1

FloatingText. Default parameters.

Posted: Thu Aug 20, 2020 12:31 pm
by Adrian
Introduction. Slightly long. :-)
About "FloatingText" in general.

(If you know "FloatingText" well, then read next part)

I read about function "FloatingText" now.

This function, as Lua-API says,
"Display a text message at the specified location".

Function "FloatingText" has four parameters. First and second parameter are required. (or parameter 0 and 1 ?)

Code: Select all

FloatingText(string text, WPos position, int duration = 30, Nullable`1 color = nil)
"Duration" and "color" have default values.

Duration (time, when text disappear).
Default value = 30 ticks. For example, 25 ticks = 1 second.

Default color is white.
It defined here:
OpenRA.Mods.Common/Scripting/Global/MediaGlobal.cs

- - -

My code with different parameters.
It works.
(in lua file; for example, atreides03a.lua)

Code: Select all

mesto = WPos.New(10*1024, 15*1024, 0)
cvet = HSLColor.Purple

Media.FloatingText("qwerty", mesto)
Media.FloatingText("A B C D", mesto, 125)
Media.FloatingText("A B C D", mesto, 30, cvet)
- - -

Question:

Can I use parameter 1, 2 and 4 ?
Does exist correct scripting? When duration by default.

Something like this. But it does not work.

Code: Select all

Media.FloatingText("A B C D", mesto, cvet)

Re: FloatingText. Default parameters.

Posted: Thu Aug 20, 2020 5:04 pm
by hamb
No -- although that parameter has a default value, if you provide a subsequent parameter you have to provide preceding parameters. Otherwise the engine will think you're trying to pass a color as an integer, which won't work.

Your third test is correct: `Media.FloatingText("A B C D", mesto, 30, cvet)`

Re: FloatingText. Default parameters.

Posted: Thu Aug 20, 2020 6:13 pm
by Adrian
Otherwise the engine will think you're trying to pass a color as an integer, which won't work.
Really. In that case, Lua returns error:
"Unable to convert parameter 2 to Int32".

Thank you for explanation.