Indie Dev

Hello Guest!. Register a free account today to become a member! Once signed in, you'll be able to participate on this site by adding your own topics and posts, sell your games, upload content, as well as connect with other members through your own private inbox!

Help with variables

ceudoffice

Villager
Xy$
0.00
Hi!


I'm a newbie and I'm stuck with my project. Please someone could help me with this problem below:


I'm using ingame variables to count some of the players actions. And I want to write this ingame variable to a .txt file (using a script or a plugin or anything).

I can write any text in to a .txt file, but I can't seem to find a way to put variables in it.


Thank you for your help in advance!
 

CT_Bolt

Global Moderator
Staff member
Resource Team
Xy$
0.02
Hi! I'm a newbie and I'm stuck with my project. Please someone could help me with this problem below:
I'm using ingame variables to count some of the players actions. And I want to write this ingame variable to a .txt file (using a script or a plugin or anything).
I can write any text in to a .txt file, but I can't seem to find a way to put variables in it.
Thank you for your help in advance!
Here you go. I've also made a very small demo. (cool)

Write:
JavaScript:
var path = window.location.pathname.replace(/(\/www|)\/[^\/]*$/, '/data/');
if (path.match(/^\/([A-Z]\:)/)) {
    path = path.slice(1);
}
path = decodeURIComponent(path) + "variables.txt";
var fs = require('fs');
// Writes "#1: [Variable #1]" to variables.txt
fs.writeFile(path, "#1: " + $gameVariables.value(1), function(err) {
    if(err) {
        return console.log(err);
    }
});
Read:
JavaScript:
var xhr = new XMLHttpRequest();
xhr.open("GET","data/variables.txt",false);
xhr.send(null);

var fileContent = xhr.responseText;
$gameVariables.setValue(2, fileContent); // This will store the entire text file into variable 2
Read/Write Demo: Click Here to View


Sorry I'm just now seeing this (10 days later).(slanty) Let me know if this helps. (glad)(thumbsup)
 
Top