MZ Need help with my data dumping plugin

Hey all, long time lurker, first time poster here. So here's the thing:

I have a webpage that contains my game in an iframe. I want to be able to display variable data from the iframe itself onto the webpage in real time. The game is mostly developed and I just need something to extract the variable data from it. Im not very knowledgeable in web development and javascript as this is my first dive into these things. I have the slightest minimums for a plugin so far, but I have no idea where to go from here or whether or not I'm going in the right direction.

what I have so far (not much): /*: * @plugindesc just something to let a webpage read data from the game via iframe * @author Jayjay * */ (function() { "use strict"; function scoredump() { this.initialize.apply(this, arguments); } scoredump.prototype= $gameVariables.value(300); })();
Moderator note: Moving to Learning Javascript

as you're asking for help to write it, rather than someone to write it for you.
Hello welcome.

You can try sending the data from Rpg Maker to the "parent" page.

Main page (index.html):
JavaScript:
var mydata=[];

Iframe game page (Event Command -> Script):
JavaScript:
window.parent.mydata.push($gameVariables.value(300))
Or
JavaScript:
window.parent.mydata[0]=$gameVariables.value(300)

It could be that some browser considers a security hole, so it will block the action.
Another way to do this would be using localStorage or even cookies, which can be written and read:

@jayjay8158 Hope you remember to come back with feedback later.
Hello welcome.

You can try sending the data from Rpg Maker to the "parent" page.

Main page (index.html):
JavaScript:
var mydata=[];

Iframe game page (Event Command -> Script):
JavaScript:
window.parent.mydata.push($gameVariables.value(300))
Or
JavaScript:
window.parent.mydata[0]=$gameVariables.value(300)

It could be that some browser considers a security hole, so it will block the action.
Another way to do this would be using localStorage or even cookies, which can be written and read:

@jayjay8158 Hope you remember to come back with feedback later.
Thanks! Ill try and implementing your suggestion. For some reason I didnt get an email or notifaction about your reply to my thread. I have some questions:

1. Should I put var mydata=[]; into a script tag inside the main webpage (index.html) and
2. For window.parent.mydata[0]=$gameVariables.value(300) will a standard event with this as the only script work?

Thanks again for the help
1. Yes, the variable needs to be declared outside the IFRAME, otherwise the console will return an error.
2. Yes, as in the previous explanation:
Iframe game page (Event Command -> Script):

Don't worry, I tasted it before commenting here.

Good luck

Note:
I still advise you to test the other methods mentioned.
1. Yes, the variable needs to be declared outside the IFRAME, otherwise the console will return an error.
2. Yes, as in the previous explanation:


Don't worry, I tasted it before commenting here.

Good luck

Note:
I still advise you to test the other methods mentioned.
Okay, I was messing around with your initial suggestion and got a few errors. Might have been because of something I did wrong but when trying to view mydata after I tried sending the variable data to it, it wouldn't show any values.

Heres the in-game variable:
intended mistake.JPG

and the array that would store it on the main page:

result.JPG



heres the event page I used:
script.JPG


and the code:

htmlcodesnippet.JPG


I may have done something wrong but I'm not sure what it would be. It may be like you've mentioned in that the browser (I'm using chrome) is blocking the data from being sent. If so I'll try using the other method you mentioned.

Thanks.
Apparently you did something wrong in the game and not in the script.
When the page loads the variable mydata returns only:
[]

But in the image you showed there is an inserted value:
index.php


This zero came from somewhere.
That is, the game variable 300 is probably at zero when you tried to transfer the value.

It's simple, do a test, instead of the variable send a String:
Code:
window.parent.mydata[0]="Hello World!"

And if it doesn't work, use this solution:
Note:
I still advise you to test the other methods mentioned.

I did the test in Firefox and Chrome and it worked, if you want the HTML with CSS that centralizes the iframe:
Spoiler: index.html
HTML:
<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <meta name="apple-mobile-web-app-capable" content="yes">
        <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
        <meta name="viewport" content="user-scalable=no">
        <link rel="icon" href="icon/icon.png" type="image/png">
        <link rel="apple-touch-icon" href="icon/icon.png">
        <style>
            html, body{
                top:0;
                margin:0;
                width: 100%;
                height: 100%;
            }
            #gamescreen{
                margin: 0 auto;
                border: 10px;
                display: block;
                width: 100%;
                height: 100%;
            }
        </style>
        <title>Project 6</title>
        <script>
        var mydata=[0];
        </script>
    </head>
    <body style="background-color: black">
        <iframe id="gamescreen" src="game.html"></iframe>
    </body>
</html>

Good luck
Hey the testing worked so I don't think its a browser issue. I did remove an event that would turn the variable's value into 0 at the start of the game.
kindaworking.JPG


I did get rid of an event that would set the variable value to 0 upon the start of a new game. The problem however still persists. I didn't mention this prior, but the variable I'm trying to display is the mistakes the user makes when playing my game. It's a math puzzle type game and whenever the user answers incorrectly, the variable would go up by 1.
Probably your mini game is operating the same variable in two different places.

the "like" is courtesy of the house.

Check it when you operate it:
Code:
◆Control Variables:#0300 Defeat += 1
◆Text:None, Window, Bottom
:    :Times it was defeated: \v[300]

You don't need to use ARRAY if you're not going to log multiple data:
Code:
window.parent.mydata=$gameVariables.value(300)

And if you are going to register records for each move, you have to use PUSH.
Sorry for the question, but just to make sure I'm being useful, do you really know how to use or manipulate Arrays?
Probably your mini game is operating the same variable in two different places.

the "like" is courtesy of the house.

Check it when you operate it:
Code:
◆Control Variables:#0300 Defeat += 1
◆Text:None, Window, Bottom
:    :Times it was defeated: \v[300]

You don't need to use ARRAY if you're not going to log multiple data:
Code:
window.parent.mydata=$gameVariables.value(300)

And if you are going to register records for each move, you have to use PUSH.
Sorry for the question, but just to make sure I'm being useful, do you really know how to use or manipulate Arrays?
I did check and the variable does update properly in-game. The variable is being operated in multiple places, does it affect anything if it is?
1623087907400.png




As for arrays, I've used them a bit before but I'm fairly new to using javascript. Sorry if my lack of expertise is not helping.

I don't need to register every move, though, I only need to have the variable's value to be recorded onto the main page every time it changes.
Update: I managed to get it work. I had to put the script onto a common event and have it keep running via switch. Thanks for the help!
I don't believe this is the cause of the problem, I need to understand how your minigame works.

Take this "like" and good luck with your game.
Important detail, the keyboard does not seem to work when opening the game by an IFRAME.
This happens because it's like another window, put the "onload" attribute in the iframe tag and the following command:
Code:
this.focus()

Altogether the code will look like this:
Code:
<iframe id="gamescreen" src="game.html" onload="this.focus()"></iframe>

Original thread: https://forums.rpgmakerweb.com/threads/need-help-with-my-data-dumping-plugin.137105/