It looks like you're new here. If you want to get involved, click one of these buttons!
// Places the given text into the translation display field.
macros['displayTranslation'] =
{
handler: function(translationText) {
elem = document.getElementByID("translationDisplayField");
elem.innerHTML = translationText;
}
}
And here is the passage contents:
<p id="translationDisplayField"></p>
<<if $translation.isEnabled>>\
<<displayTranslation $translation.sourceText>>\
<<endif>>
My kids don't know this [[word|Beginning][$translation.isEnabled = true]].
The error I get is:
Error executing macro displayTranslation: TypeError: Object #<HTMLDocument> has no method 'getElementByID'
The $translation object is set with default/placeholder values in the Start passage. EDIT: I know I could have a separate frame with a text glossary, but that discourages the kids from trying to remember the words on subsequent playthroughs. Keeping the dictionary hidden also allows me to amass one giant dictionary for any and all Twine games I make for them without overwhelming them with too many words.
Comments
In this case, the error means exactly what it says on the tin, there is no getElementByID() method. JavaScript is case sensitive, the correct spelling is getElementById() (note the lowercase 'd').
That issue solved, it's still not going to work. Since you're calling the macro within the same passage as the element you want it to update, the contents of the passage won't be in the DOM when the macro executesthey'll still be in the output buffer, so you'll have to look for the element there, which means you'll also have to use querySelector(). Additionally, the handler has a predefined set of formal parameters, you don't simply add parameters to it like you would a normal function.
Try this:
Regardless, your solution worked. Thank you! Now to implement actual translation happening.