Latest Posts

Topic: wl.ui.show_messagebox

kaputtnik
Avatar
Topic Opener
Joined: 2013-02-18, 20:48
Posts: 2552
OS: Archlinux
Version: current master
Ranking
One Elder of Players
Location: Germany
Posted at: 2023-11-28, 16:35

Writing scripts for the editor may need to show the results of the script. Looking at the scripting API i found wl.ui.show_messagebox.

Does this message box support wl.richtext?

I have tried that but the result looks it doesn't support that... It would be nice if this box would also support richtext.


Attachment:
show_messagebox.png

Top Quote
Nordfriese
Avatar
Joined: 2017-01-17, 18:07
Posts: 2057
OS: Debian Testing
Version: Latest master
Ranking
One Elder of Players
Location: 0x55555d3a34c0
Posted at: 2023-11-28, 16:58

The text you seem to be using is not valid richtext… Richtext is always encapsulated in a toplevel <rt> tag. Try surrounding the text with <rt>...</rt>. Lua also has a function rt() for this.


Top Quote
kaputtnik
Avatar
Topic Opener
Joined: 2013-02-18, 20:48
Posts: 2552
OS: Archlinux
Version: current master
Ranking
One Elder of Players
Location: Germany
Posted at: 2023-11-28, 17:12

Arghhh, this richtext is really difficult for me.


   wl.ui.show_messagebox(
      "Statistic for area: ".. first_x .."/".. first_y .. " to " .. sec_x.."/"..sec_y,
      <rt>p("hello")</rt>,
      false)

Results in :

[/home/kaputtnik/Quellcode/widelands-repo/v1.2/src/scripting/lua_errors.cc:21] /home/kaputtnik/lua_Scripts/count_caps.lua:68: unexpected symbol near '<'

And:

   wl.ui.show_messagebox(
      "Statistic for area: ".. first_x .."/".. first_y .. " to " .. sec_x.."/"..sec_y,
      rt(p("hello")),
      false)

Results in a crash and the error:

[00:20:15.523 real] ERROR:   FATAL EXCEPTION in editor: Syntax error at 1:65: expected an allowed tag, got 'rt'. String continues with: '<rt><p><font face=sans size=12 color=ffff00>hello</font><vspace gap=6></p></rt></font></p></rt>'

Yes, richtext.lua is included.


Top Quote
kaputtnik
Avatar
Topic Opener
Joined: 2013-02-18, 20:48
Posts: 2552
OS: Archlinux
Version: current master
Ranking
One Elder of Players
Location: Germany
Posted at: 2023-11-28, 17:14

The image of the first post was created like this:

   wl.ui.show_messagebox(
      "Statistic for area: ".. first_x .."/".. first_y .. " to " .. sec_x.."/"..sec_y,
      p("hello"),
      false)

Top Quote
Nordfriese
Avatar
Joined: 2017-01-17, 18:07
Posts: 2057
OS: Debian Testing
Version: Latest master
Ranking
One Elder of Players
Location: 0x55555d3a34c0
Posted at: 2023-11-28, 17:29

This is actually a cornercase bug. The last example (rt(p("hello"))) is correct. One-liner bugfix PR: https://codeberg.org/wl/widelands/pulls/4587


Top Quote
kaputtnik
Avatar
Topic Opener
Joined: 2013-02-18, 20:48
Posts: 2552
OS: Archlinux
Version: current master
Ranking
One Elder of Players
Location: Germany
Posted at: 2023-11-28, 17:38

Maybe i misunderstand, but normal message boxes do not need an explicit rt-function call, see e.g. here: https://www.widelands.org/documentation/autogen_auxiliary_richtext/#lua-formatting-example

Btw.: nice to see you again face-smile.png


Top Quote