Help: Error when trying to add a SceneControlButton

Hello, I ran into an error when trying to add a SceneControlButton. Code:
Hooks.on("getSceneControlButtons", getSceneControlButtons);

function getSceneControlButtons(controls) {
if (canvas == null) {
return;
}
controls.push({
name: "markers",
title: "Markers",
icon: "fa-solid fa-location-pin",
layer: "markers",
visible: true,
tools: [
{
name: "create-marker",
title: "Create Marker",
icon: "fa-solid fa-location-pin",
button: true,
},
],
activeTool: "marker",
});
}
Hooks.on("getSceneControlButtons", getSceneControlButtons);

function getSceneControlButtons(controls) {
if (canvas == null) {
return;
}
controls.push({
name: "markers",
title: "Markers",
icon: "fa-solid fa-location-pin",
layer: "markers",
visible: true,
tools: [
{
name: "create-marker",
title: "Create Marker",
icon: "fa-solid fa-location-pin",
button: true,
},
],
activeTool: "marker",
});
}
The button is added, but when clicked I get an error in the console:
Uncaught TypeError: Cannot read properties of undefined (reading 'activate')
at SceneControls._onClickLayer (foundry.js:81634:42)
at HTMLLIElement.dispatch (jquery.min.js:2:40035)
at v.handle (jquery.min.js:2:38006)
Uncaught TypeError: Cannot read properties of undefined (reading 'activate')
at SceneControls._onClickLayer (foundry.js:81634:42)
at HTMLLIElement.dispatch (jquery.min.js:2:40035)
at v.handle (jquery.min.js:2:38006)
I am at my wit's end. Any and all help would be appreciated.
Solution:
created the “markers” layer and added it to the canvas?
Jump to solution
3 Replies
Solution
joaquinp98
joaquinp983w ago
created the “markers” layer and added it to the canvas?
joaquinp98
joaquinp983w ago
also set as activeTool “marker” and your tool is called “create-marker”
Overclock
OverclockOP3w ago
Yeah. That did it. I am very much new to this, couldn't find any good ressources on this. Thank you very much!

Did you find this page helpful?