Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Add-on onInit fails if it requires data from e.g. a table #5178

Open
Tdue21 opened this issue Feb 5, 2025 · 3 comments · May be fixed by #5231
Open

[Bug]: Add-on onInit fails if it requires data from e.g. a table #5178

Tdue21 opened this issue Feb 5, 2025 · 3 comments · May be fixed by #5231
Assignees
Labels

Comments

@Tdue21
Copy link
Contributor

Tdue21 commented Feb 5, 2025

Describe the Bug

A campaign with an add-on embedded will generate an error on the add-on's onInit, if the event requires campaign resources, like switching to a lobby map, reading images from a table etc.

According to Skullman3194 (on the Discord), it appears that MT attempts to execute the add-on code before it has actually load the campaign resources.

If I defer the onInit code that requires these resources, i.e. use the execLink(link, 1, "self") function, my initialization code works.

To Reproduce

  1. Create a campaign.
  2. Create a second map.
  3. Create an add-on which attempts to switch to second map in onInit.
  4. Save campaign.
  5. Restart MapTool and load campaign.
  6. Observe failure.

Expected Behaviour

I expect the add-on to be able to load campaign resources in the initialization code, just like a library token.
Without having to resort to deferring code.

Screenshots

No response

MapTool Info

1.15.2 - clean install

Desktop

Windows 11

Additional Context

I will ASAP construct an example campaign to demonstrate the issue.

@fishface60
Copy link
Contributor

Discussion in https://discord.com/channels/296230822262865920/915297924605423636/1336380348925350039

This is because the last message in the handshake includes the addons, and the message handler fetches and initializes the addons, and onInit is run during initialization, but the Campaign is sent to the player as the first message of the session so the onInit is run before the campaign is loaded.

@Tdue21
Copy link
Contributor Author

Tdue21 commented Feb 6, 2025

I have created a very simple campaign with two maps. The default "Grasslands" and new one "Desert".
The add-on, already added to the campaign attempts to switch to the "Desert" map in onInit.js.
But fails, as per the description above.

campaign.zip
add-on.zip

I have attached two files. The campaign file itself, and a zip file with the source code of the add-on.

@fishface60
Copy link
Contributor

Interesting! It's not just on connect that it doesn't work, but also on file load.

Your test campaign having two add-ons, one that changed to desert and one that changed to grasslands, so I was left confused by why it didn't appear to change.

Fixing the addons led me to discover #5229

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants