[1.1.53] LuaGuiElement::caption doesn't accept LuaProfiler

Bugs that are actually features.
Post Reply
User avatar
jan1i3
Long Handed Inserter
Long Handed Inserter
Posts: 59
Joined: Sun Dec 09, 2018 1:36 pm
Contact:

[1.1.53] LuaGuiElement::caption doesn't accept LuaProfiler

Post by jan1i3 »

What
When trying to assign a LocalisedString to LuaGuiElement::caption that contains or is a LuaProfiler it errors:

Value must be a string in property tree at ROOT.caption[...]
Expected
I would expect it to accept the LuaProfiler and show its elapsed time/duration. On save load I would expect it to show `N/A` in place of the profiler's string similar to how it works in the console.
Reproduction

Code: Select all

/c
game.player.gui.center.add{type = "frame", caption = game.create_profiler()}
Full Context
I was making a happy little GUI for a test runner, so the elapsed time for each test would be a nice to have. It also prints to the log file though (with the times of course), so it truly is just nice to have.

I tested with labels and frames, and used this command for comparison, then save loaded:

Code: Select all

/c
game.print{"", "hi: ", game.create_profiler()}
Attachments
factorio-current.log
(4.44 KiB) Downloaded 73 times
Also known as JanSharp. jan1i3 was/is my old name ;)

User avatar
boskid
Factorio Staff
Factorio Staff
Posts: 2241
Joined: Thu Dec 14, 2017 6:56 pm
Contact:

Re: [1.1.53] LuaGuiElement::caption doesn't accept LuaProfiler

Post by boskid »

I am going to call this a "not a bug" or "modding interface request". One of those...

LuaProfiler is kind of usable in some places where a LocalisedString is expected but this is implemented through a parser of data obtained from lua (parseLocalisedString checks if provided object is a LuaProfiler). Due to amount of various parameters for LuaGuiElement, all parameters here are not going through parsers but all parameters are converted into a PropertyTree. LocalisedStrings can be represented by the PropertyTree, while LuaProfiler cannot be represented and thats why you get `Value must be a string in property tree at ROOT.caption[...]` error.

Another issue is that a LuaProfiler in a context where it is passed to a LocalisedString is decaying into a literal-translation LocalisedString. That means it no longer holds any references to the profiler they were created from, so they would not update anymore making it kind of useless.

Given 2 above issues it is not simply a bug, it was never intended to work in that use case so i am going to call this... not a bug.

User avatar
jan1i3
Long Handed Inserter
Long Handed Inserter
Posts: 59
Joined: Sun Dec 09, 2018 1:36 pm
Contact:

Re: [1.1.53] LuaGuiElement::caption doesn't accept LuaProfiler

Post by jan1i3 »

I see, that makes a lot of sense. I will simply ask for a note about that on the LuaProfiler page, since the reason why I thought it was a bug was because LuaProfiler says "They can be used anywhere a LocalisedString is used."

I'll make a post in viewtopic.php?f=28&t=97880 right now so it's properly tracked.

And thank you for the comprehensive explanation :)
Also known as JanSharp. jan1i3 was/is my old name ;)

User avatar
jan1i3
Long Handed Inserter
Long Handed Inserter
Posts: 59
Joined: Sun Dec 09, 2018 1:36 pm
Contact:

Re: [1.1.53] LuaGuiElement::caption doesn't accept LuaProfiler

Post by jan1i3 »

Now knowing that it's property tree related I've done more investigating and this behavior applies in 3 cases (see viewtopic.php?p=560285#p560285 ).

And for anyone finding this through search, you can actually set LuaGuiElement::caption to a LocalisedString containing LuaProfilers, you just can't set it directly in LuaGuiElement::add. And it then behaves exactly like I described in the "expected" section. Intended or not, it works :D
Also known as JanSharp. jan1i3 was/is my old name ;)

Post Reply

Return to “Not a bug”