So, from what I've read so far, I think what you're trying to do is very easy. Let's say you have a fully-featured Tetris game (code and all), that works as intended as a standalone app. The easiest solution would be to put it in an iframe to embed it. That's how sites embed YouTube videos and so on.
Now, getting data out of that iframe is a bit more tricky due to security concerns. After all, you wouldn't want some shady webpage to embed your e-banking site in an invisible iframe, then retrieve your session token from the iframe (assuming you're still logged in), which it could then use to impersonate you and steal money directly from your bank account. Fortunately, from what little research I've done, it seems that you can circumvent this security mechanism using
window.postMessage().
In your example, you'd have to edit your Tetris app to make use of
window.postMessage() to post the appropriate data (the last Tetris score) to the appropriate target (your RPG Maker game). Once your RPG Maker game receives that message, it could then hide or remove it.
For example, if your game is hosted on
https://www.my-game.com and the Tetris app is hosted on
https://www.my-game.com/tetris, then the Tetris app would have to send the score like this:
JavaScript:
window.postMessage(score, "https://www.my-game.com");
As for your RPG Maker project, in order to receive that data, you'll need to add an event listener, like this:
JavaScript:
let score = null;
window.addEventListener("message", event => {
if (event.origin !== "https://www.my-game.com/tetris")
return; // We're only interested in messages from the Tetris app.
score = event.data;
});
Note that event listeners are asynchronous. This means that RPG Maker will continue to run without waiting for Tetris to respond. If you wish to suspend the RPG Maker application while you wait for the Tetris score, you can either
- add a busy-wait:
JavaScript:
while (score === null) await new Promise(r => setTimeout(r, 100));
will check every 100 milliseconds if the score has been set.
- make use of the async-await pattern (I don't recommend it when you're a beginner, as it is very likely to confuse you). If you're curious, you'd have to define an async function:
JavaScript:
async function getTetrisScore() {
return new Promise(resolve => {
window.addEventListener("message", event => {
if (event.origin !== "https://www.my-game.com/tetris")
return;
resolve(event.data);
});
});
}
and call it like this:
JavaScript:
let score = await getTetrisScore();
Note that my JavaScript (and especially async-await skills) has become a bit rusty and I make no guarantee that the above code works.
- or come up with some other creative solution.