MV Sorry

JavaScript:
//=============================================================================
// RPG Maker MV - Plugin Transfer&Download Data GoogleSheets
//=============================================================================

/*:
 * @plugindesc Plugin untuk menghubungkan permainan dengan Google Sheets.
 * @author Say of Art, in Game FOD.
 *
 * @param SpreadsheetID
 * @desc ID Spreadsheet Google Sheets Anda.
 * @default SpreadsheetID
 *
 * @param APIKey
 * @desc API Key Google Sheets Anda.
 * @default your APIKey
 *
 * @help
 * Anda harus mengisi ID Spreadsheet dan API Key yang Anda dapatkan dari
 * Google Developer Console.
 */

// Variabel game dengan nilai yang akan dikirim ke Google Sheets
var gameVariable = $gameVariables.value(200);

// Fungsi untuk mengirim data ke Google Sheets
function sendDataToGoogleSheets(value) {
    // Kirim permintaan POST ke Google Sheets API untuk menulis ke sel A2 di lembar "Data"
    // Pastikan untuk menggunakan SpreadsheetID dan API Key Anda
    var url = 'https://sheets.googleapis.com/v4/spreadsheets/SPREADSHEET_ID/values/Data!A2:append?valueInputOption=RAW&key=YOUR_API_KEY';
    var data = {
        values: [[value]]
    };
    var xhr = new XMLHttpRequest();
    xhr.open('POST', url, true);
    xhr.setRequestHeader('Content-Type', 'application/json');
    xhr.onreadystatechange = function() {
        if (xhr.readyState === 4 && xhr.status === 200) {
            // Proses selesai, lanjutkan untuk mengambil data dari Google Sheets
            getDataFromGoogleSheets();
        }
    };
    xhr.send(JSON.stringify(data));
}

// Fungsi untuk mengambil data dari Google Sheets
function getDataFromGoogleSheets() {
    // Kirim permintaan GET ke Google Sheets API untuk membaca sel B2 di lembar "Data"
    // Pastikan untuk menggunakan SpreadsheetID dan API Key Anda
    var url = 'https://sheets.googleapis.com/v4/spreadsheets/SPREADSHEET_ID/values/Data!B2?key=YOUR_API_KEY';
    var xhr = new XMLHttpRequest();
    xhr.open('GET', url, true);
    xhr.onreadystatechange = function() {
        if (xhr.readyState === 4 && xhr.status === 200) {
            var response = JSON.parse(xhr.responseText);
            // Ambil data dari respons dan simpan dalam variabel game
            var dataFromGoogleSheets = response.values[0][0];
            $gameVariables.setValue(200, dataFromGoogleSheets);
        }
    };
    xhr.send();
}

// Panggil fungsi untuk mengirim data saat permainan dimulai
var _Scene_Boot_start = Scene_Boot.prototype.start;
Scene_Boot.prototype.start = function() {
    _Scene_Boot_start.call(this);
    sendDataToGoogleSheets(gameVariable);
};

That's Work

I've moved this thread to Plugin Support (from MV Support). Thank you.

None of the plugin parameters are used. I haven't checked if that's otherwise a correct usage of the Google Sheets API.

Is this code AI-generated?
Moved to: Plugin Support (from MV Support) None of the plugin parameters are used. I haven't checked if that's otherwise a correct usage of the Google Sheets API.

Is this code AI-generated?
Is this code AI-generated? Yes

Is this code AI-generated? Yes
Every time you want to open it you have to reload the game first.

so it's less efficient, I'm using pixi 4.8.8, using in web browser.
Most (all?) coders here will not help troubleshoot code generated by an AI. There's too much wrong to try to fix.

If you want help from people here, the best ways are to start from a plugin request or (more likely for this) commission a human to write it for you.
JS in RPG MAKER MV


JavaScript:
// Fungsi untuk mengirim permintaan HTTP POST
function editDataInGoogleSheet(newValue) {
  var xhr = new XMLHttpRequest();
  var url = 'XXXXXXXX'; // Ganti dengan URL skrip Google Apps Script Anda
 
// Fungsi untuk mengirim permintaan HTTP POST
function editDataInGoogleSheet() {
  var xhr = new XMLHttpRequest();
 
  // Mengambil nilai dari variabel 200
  var newValue = $gameVariables.value(200);
 
  // Menyiapkan data yang akan dikirimkan
  var data = {
    newValue: newValue
  };
 
  // Mengonfigurasi permintaan HTTP
  xhr.open('POST', url);
  xhr.setRequestHeader('Content-Type', 'application/json');
 
  // Mengirim data sebagai JSON string
  xhr.send(JSON.stringify(data));
}

// Fungsi untuk mengambil data dari Google Sheets
function getDataFromGoogleSheet() {
  var url = 'YOUR_SCRIPT_URL'; // Ganti dengan URL skrip Google Apps Script Anda

  // Mengirim permintaan GET ke skrip Google Apps Script
  var xhr = new XMLHttpRequest();
  xhr.open('GET', url);
  xhr.onload = function() {
    if (xhr.status === 200) {
      // Menguraikan data JSON yang diterima
      var data = JSON.parse(xhr.responseText);
     
      // Mengambil nilai kolom pertama dan kedua
      var col1Value = data.col1;
      var col2Value = data.col2;
     
      // Menyimpan nilai ke dalam variabel 200 dan 201
      $gameVariables.setValue(200, col1Value);
      $gameVariables.setValue(201, col2Value);
    }
  };
  xhr.send();
}

// Fungsi untuk mengedit data di Google Sheets
function editDataInGoogleSheet(newValue) {
  var url = 'YOUR_SCRIPT_URL'; // Ganti dengan URL skrip Google Apps Script Anda
 
  // Menyiapkan data yang akan dikirimkan
  var data = {
    newValue: newValue
  };
 
  // Mengirim permintaan POST ke skrip Google Apps Script
  var xhr = new XMLHttpRequest();
  xhr.open('POST', url);
  xhr.setRequestHeader('Content-Type', 'application/json');
  xhr.send(JSON.stringify(data));
}
Skrip in https://script.google.com/

JavaScript:
function doPost(e) {
  var sheetID = "ID GOOGLE SHEET";
  var range = "Data!A2"; // Sesuaikan dengan sel yang ingin Anda edit datanya
  // Ambil data yang dikirimkan dari permintaan POST
  var data = JSON.parse(e.postData.contents);
  // Edit nilai di sel A2 dengan data yang baru
  SpreadsheetApp.openById(sheetID).getRange(range).setValue(data.newValue);
  // Mengembalikan respons yang memberi tahu bahwa pengeditan berhasil
  return ContentService.createTextOutput("Data berhasil diubah.");
}
function doGet(e) {
  var sheetID = "ID GOOGLE SHEET";
  var range = "Data!B2"; // Sesuaikan dengan sel yang ingin Anda ambil datanya
  var values = SpreadsheetApp.openById(sheetID).getRange(range).getValues();
 
  var data = {
    col1: values[0][0], // Mengambil nilai dari kolom pertama
    col2: values[0][1]  // Mengambil nilai dari kolom kedua
  };
  // Mengembalikan data dalam format yang sesuai dengan RPG Maker MV
  return ContentService.createTextOutput(JSON.stringify(data)).setMimeType(ContentService.MimeType.JSON);
}
//Command Open Data From Googlesheet
getDataFromGoogleSheet();


//Command Send Data From Googlesheet
var newValue = $gameVariables.value(200);
editDataInGoogleSheet(newValue);
Thats Realy Work
I have reverted the thread back to a (mostly) readable state. The only items I’m not able to revert is the thread title or any images that may have been included.

Do not post disruptively. This includes but is not limited to: clearing your own posts (in a way that makes the thread/status unreadable or highly altered from its original meaning) and double posting (posting two or more times in row).


You may find the forum rules here.
do you even understand the code you generate?
as you stated you made it which is not, and like previous, to many issues.

you can use it as a helptool, not make it for you as AI doesn't know rpg maker as advanced coders does here.
it's better to explain what exactly you need and how to bound the parameter for safety reasons.

good luck on your plugin though.

Original thread: https://forums.rpgmakerweb.com/threads/sorry.167014/