How to load numbers from EXTERNAL TXT into a variable in rpgmv?

yongilcool

Veteran
Veteran
Joined
Nov 7, 2014
Messages
60
Reaction score
10
First Language
English
i want to get a number from an external text file and put it into a variable in the game.

for example,   I'll put a text file "1.txt" in my project folder and it contains only number '10' and no other content at all and load this in the game and save this 10 into variable[1]?

i have,'t got a clue to do this.

EXTERNAL TXT plugin only shows text messeges and

It was rather too complicated for me to fix and customize and I'd like to put a number into variable not messeges.

if you have answers and could make a simple plugin or suggestions pls share thank you so much!  ;_;
 

Iavra

Veteran
Veteran
Joined
Apr 9, 2015
Messages
1,797
Reaction score
863
First Language
German
Primarily Uses
For what exactly do you need that number? Loading a file requires an asynchronous request, which might be too complicated for such a simple task. Wouldn't is be easier to use a plugin parameter for this?
 

yongilcool

Veteran
Veteran
Joined
Nov 7, 2014
Messages
60
Reaction score
10
First Language
English
I was wondering if RPGMV could read a certain number(like in txt file) from the NFC card through the android or PC reader and save it into variables and be used in the game you know.

so I could make a TCG game where player could play with certain NFC cards and apply it in the game to play you know?

route would be like: NCF card-> android / pc -> a text file or any other information file gets put into the project folder->read it from rpgmv and put it in a variable-> verify it and get an item/ character

doesn't necessarily have to be a txt file.

just wanted to load certain numbers from the NFC card.

Getting text file/ number from NFC card won't be a problem but

what I don't know is to load numbers from external text file and get it into variables in rpgmv..

wanted to know if this was possible to make as a plugin or script.
 
Last edited by a moderator:

Iavra

Veteran
Veteran
Joined
Apr 9, 2015
Messages
1,797
Reaction score
863
First Language
German
Primarily Uses
I don't know anything about how Android handles NFC cards, but assuming their contents can be accessed on the file system, you have 2 options to do this:

- Read the data at the beginning of the game (or any scene):

Code:
var data;var loadData = function(url) {    var request = new XMLHttpRequest();    request.open('GET', url);    request.onload = function() { data = Number(request.responseText); };    request.onerror = function() { throw new Error("There was an error loading the file '" + url + "'."); };    request.send();};var alias_create = Scene_Boot.prototype.create;Scene_Boot.prototype.create = function() {    alias_create.call(this);    loadData();};var alias_isReady = Scene_Boot.prototype.isReady;Scene_Boot.prototype.isReady = function() {    return (data !== undefined) && alias_isReady.call(this);};// Afterwards, the data is available.
- Read the data during a scene, by using a callback:
Code:
var loadData = function(url, callback) {    var request = new XMLHttpRequest();    request.open('GET', url);    request.onload = function() { callback(Number(request.responseText)); };    request.onerror = function() { throw new Error("There was an error loading the file '" + url + "'."); };    request.send();};// You don't know exactly, when the data will be available, so you should handle it completely inside the callback.
 

yongilcool

Veteran
Veteran
Joined
Nov 7, 2014
Messages
60
Reaction score
10
First Language
English
I don't know anything about how Android handles NFC cards, but assuming their contents can be accessed on the file system, you have 2 options to do this:

- Read the data at the beginning of the game (or any scene):

var data;var loadData = function(url) { var request = new XMLHttpRequest(); request.open('GET', url); request.onload = function() { data = Number(request.responseText); }; request.onerror = function() { throw new Error("There was an error loading the file '" + url + "'."); }; request.send();};var alias_create = Scene_Boot.prototype.create;Scene_Boot.prototype.create = function() { alias_create.call(this); loadData();};var alias_isReady = Scene_Boot.prototype.isReady;Scene_Boot.prototype.isReady = function() { return (data !== undefined) && alias_isReady.call(this);};// Afterwards, the data is available.- Read the data during a scene, by using a callback:
Code:
var loadData = function(url, callback) {    var request = new XMLHttpRequest();    request.open('GET', url);    request.onload = function() { callback(Number(request.responseText)); };    request.onerror = function() { throw new Error("There was an error loading the file '" + url + "'."); };    request.send();};// You don't know exactly, when the data will be available, so you should handle it completely inside the callback.
thnx for the specific information!! only.. what parts of this code do I fill in to test this?

like... for url.. what exactly do I write in it? and like variables numbers or any other parts do I change to appy this for me? 

could you maybe like an example?  after everything, I'd have to put this in a script call? sorry I asked too much.. I'm such an amateur at this... :(
 
Last edited by a moderator:

Iavra

Veteran
Veteran
Joined
Apr 9, 2015
Messages
1,797
Reaction score
863
First Language
German
Primarily Uses
Assuming you have a file named "1.txt" containing the number 10 in your project folder, you would write the first example like this:

Code:
var data;var loadData = function(url) {    var request = new XMLHttpRequest();    request.open('GET', url);    request.onload = function() { data = Number(request.responseText); };    request.onerror = function() { throw new Error("There was an error loading the file '" + url + "'."); };    request.send();};var alias_create = Scene_Boot.prototype.create;Scene_Boot.prototype.create = function() {    alias_create.call(this);    loadData('1.txt');};var alias_isReady = Scene_Boot.prototype.isReady;Scene_Boot.prototype.isReady = function() {    return (data !== undefined) && alias_isReady.call(this);};var alias_start = Scene_Boot.prototype.start;Scene_Boot.prototype.start = function() {    alert(data);    // 10    alias_start.call(this);};
 

yongilcool

Veteran
Veteran
Joined
Nov 7, 2014
Messages
60
Reaction score
10
First Language
English
Assuming you have a file named "1.txt" containing the number 10 in your project folder, you would write the first example like this:

var data;var loadData = function(url) { var request = new XMLHttpRequest(); request.open('GET', url); request.onload = function() { data = Number(request.responseText); }; request.onerror = function() { throw new Error("There was an error loading the file '" + url + "'."); }; request.send();};var alias_create = Scene_Boot.prototype.create;Scene_Boot.prototype.create = function() { alias_create.call(this); loadData('1.txt');};var alias_isReady = Scene_Boot.prototype.isReady;Scene_Boot.prototype.isReady = function() { return (data !== undefined) && alias_isReady.call(this);};var alias_start = Scene_Boot.prototype.start;Scene_Boot.prototype.start = function() { alert(data); // 10 alias_start.call(this);};
wow thnx for this! just sent you a personal messege :)
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Profile Posts

Day 9 of giveaways! 8 prizes today :D
He mad, but he cute :kaopride:

Our latest feature is an interview with... me?!

People4_2 (Capelet off and on) added!

Just beat the last of us 2 last night and starting jedi: fallen order right now, both use unreal engine & when I say i knew 80% of jedi's buttons right away because they were the same buttons as TLOU2 its ridiculous, even the same narrow hallway crawl and barely-made-it jump they do. Unreal Engine is just big budget RPG Maker the way they make games nearly identical at its core lol.

Forum statistics

Threads
106,037
Messages
1,018,464
Members
137,821
Latest member
Capterson
Top