FloatingText. Default parameters.

Information and discussion for custom maps and mods.
Post Reply
Adrian
Posts: 39
Joined: Wed Feb 12, 2020 5:44 pm

FloatingText. Default parameters.

Post 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)

User avatar
hamb
Posts: 112
Joined: Mon Oct 18, 2010 4:57 pm

Re: FloatingText. Default parameters.

Post 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)`

Adrian
Posts: 39
Joined: Wed Feb 12, 2020 5:44 pm

Re: FloatingText. Default parameters.

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

Post Reply