I was dabbling into this too. In my case i simply needed an extra main menu button, doing
let grapejuice = {
"caption": translate("Grapejuice Info"),
"tooltip": translate("View the changes that this mod brings to the game."),
"onPress": () => {
Engine.OpenChildPage("page_grapejuice.xml");
}
};
mainMenuItems.unshift(grapejuice)
into `MainMenuItems~grapejuice.append` Seems to be clean and works well if i do the same in another mod. However if the variable name is the same in some other mod it will hardcrash on startup. Even if you let the variable out of it and just do
mainMenuItems.unshift
(
{
"caption": translate("Grapejuice Info"),
"tooltip": translate("View the changes that this mod brings to the game."),
"onPress": () => {
Engine.OpenChildPage("page_grapejuice.xml");
}
}
)
in 2 different mods it will hardcrash aswell. Not sure why and if this the recommended way of doing it anyway.
@phosit right, I was too quick. So, what works and what does not:
✔ gui/pregame/mainmenu~MyMod.append.js
✖ gui/pregame/mainmenu~MyMod.js
The second approach has worked in all versions prior 28 - and this was "the" established practice, as far as I could see. It looks like the "append" keyword has a special meaning for evaluation of files (I tried with other keywords). Then I have two questions:
Should modders be advised to rename all files of the form "module~MyMod.js" with "module~MyMod.append.js"?
If so, could this be explicited somewhere? Probably not so relevant here https://gitea.wildfiregames.com/0ad/0ad/wiki/PortA27ToR28, but it would have helped.
With "any content" do you mean "no content"? Then that's expected. An empty file shouldn't change the behaviour. eg: appending nothing to the mainmenu.js doesn't change anything.
When adding a `warn` call at global scope of the "append" file, it works for me.