Page 1 of 1

[0.17.23][lua] Incorrect event data when rich text tags are included

Posted: Sun Mar 31, 2019 9:09 am
by eduran
Under very specific circumstances, event data is not transferred properly between mods (see this bug report for LTN Tracker and follow-up discussion in case you are interested in where this came from).

If rich text is included into event data, that data is sometimes not properly transferred to event listeners. Two mods are attached to reproduce the issue. This is what serpent.block output looks like for sender and receiver:

Code: Select all

 639.717 Script @__sender__/control.lua:12: Data, before event raised:
{
  string1 = "[img=item/express-transport-belt] String A",
  string2 = "[img=item/express-transport-belt] String B" --< this is fed into raise_event
}
 639.718 Script @__receiver__/control.lua:3: Event received:
{
  data = {
    string1 = "[img=item/express-transport-belt] String A",
    string2 = "[img=item/express-transport-belt] String A" --< this is what is received
  },
  mod_name = "sender",
  name = 145,
  tick = 300
}
 639.718 Script @__sender__/control.lua:19: Data, before event raised:
{
  string1 = "[img=item/express-transport-belt] A",
  string2 = "[img=item/express-transport-belt] B"
}
 639.718 Script @__receiver__/control.lua:3: Event received:
{
  data = {
    string1 = "[img=item/express-transport-belt] A",
    string2 = "[img=item/express-transport-belt] B"
  },
  mod_name = "sender",
  name = 145,
  tick = 300
}
In the first example, string2 is overwritten with the value of string1. The second example works as intended. If sender itself subscribes to the custom event, event data is correct in both cases.

The example mods should work in any game. Sender raises an event twice (with slightly different data) every 60 ticks to which receiver is subscribed.

Re: [0.17.23][lua] Incorrect event data when rich text tags are included

Posted: Mon Apr 01, 2019 9:30 am
by Rseding91
Thanks for the report however there's nothing special about passing "rich text tags" between mods with remote calls. The remote call system doesn't even know what rich text is - it's just passing the literal string.

So, I'm going to say not a bug and something on your mod side is broken unless you can show it happening with just 1 tiny example mod and doing it through remote call in the console.

Moving to modding help.

Re: [0.17.23][lua] Incorrect event data when rich text tags are included

Posted: Mon Apr 01, 2019 9:41 am
by eduran
Event data is the issue. It has nothing to do with remote.call. The attached mods are the smallest possible example I can think of (~40 lines of Lua code). I don't see how I could reproduce this via console commands.

One mod raises an event, the other receives it. The event data on the receiving end is incorrect. It might not be related to rich text, it could also be something else about the transferred strings.

Re: [0.17.23][lua] Incorrect event data when rich text tags are included

Posted: Mon Apr 01, 2019 10:15 am
by Bilka
Rseding91 wrote: Mon Apr 01, 2019 9:30 am just 1 tiny example mod and doing it through remote call in the console.
Okay, attached is a mod that contains only the following code:

Code: Select all

local custom_event = script.generate_event_name()
script.on_event(custom_event, function(e) game.print(serpent.block(e)) end)
To reproduce the issue, start a game without mods and run this console command:

Code: Select all

/c script.raise_event(145, {["string1"] = "[img=item/express-transport-belt] String A", ["string2"] = "[img=item/express-transport-belt] String B"})
You will observe this:

Image

Re: [0.17.23][lua] Incorrect event data when rich text tags are included

Posted: Mon Apr 01, 2019 10:24 am
by eduran
Thanks Bilka for providing a simpler example. I did not know you could hard-code the event ID like that.

Re: [0.17.23][lua] Incorrect event data when rich text tags are included

Posted: Mon Apr 01, 2019 10:43 am
by Rseding91
Ok, I was able to reproduce it with that 1 mod and it's now fixed for the next version of 0.17. It had nothing to do with rich text and instead was related to the 2 identical sized strings used for keys.

Re: [0.17.23][lua] Incorrect event data when rich text tags are included

Posted: Mon Apr 01, 2019 11:50 am
by eduran
Rseding91 wrote: Mon Apr 01, 2019 10:43 am It had nothing to do with rich text and instead was related to the 2 identical sized strings used for keys.
I agree it is not related to rich text, but disagree on it being caused by table keys. You can use integer keys and get the same result. Instead, it seems to be caused by long strings (above 40 characters):

Code: Select all

/c script.raise_event(145, {[1] = "this is a string with more than 40 characters", [2] = "another string with more than 40 characters"})

Code: Select all

/c script.raise_event(145, {[1] = "this is a string with exactly 40 chars!!", [2] = "another string with more than 40 characters"})
bug.jpg
bug.jpg (290.78 KiB) Viewed 3240 times