Text file strings to array

Dreadshadow

Lv 38 Tech Magician
Moderator
Joined
Mar 2, 2014
Messages
3,879
Reaction score
2,518
First Language
Greek
Primarily Uses
RMMV
Hello again community.
It happens that I want a plugin to be able to do two things (same plugin can do both).
1] Take text from file and add it on Array Variable of our choice. Then call it like \v[1][2] (third entry on variable 1)
2] ... if we leave a containing method intact. Otherwise decrypt the text accordingly (a coder can add utility to a method altering the code)

If it is a LOT of work for you, please don't bother. If you can find a solution easily I would appreciate the effort.
I always give credit on the original creators, I am looking for a solution I can use on a commercial product without any problem.

More details:

I want all the textboxes to include no text but variable calls, that will draw text from an Array Variable to begin with.
The text will be displayed by commands like \v[1][2] and will be no longer than a line.
Let's say we reserve Variable 1 to be that array full of strings.
But we should be able to define what variable we should use through parameter of plugin command.


Thus we shall populate variable 1 as an array, to include let's say 50 entries from a text file.

Textfile would be like:

First
Second
...
Fourty Ninth
Fiftieth Entry
============================

\v[1][0] shall contain "First"
\v[1][1] shall contain "Second"
...
\v[1][49] shall contain "Fiftieth Entry"


Most important part:


Reads text line and gets the string --> Pass it through a method that just echo it --> Put it into an array variable.

I wanna use this to apply encryption per device, thorough a decryption method.
In fact the strings will be encrypted from before in the textfile, and the method, will decrypt them before putting them into the array. You can leave this part to me, or anyone else using the plugin, just echo it as it is for now, (what goes in comes out) but I need a method to pass the text before loading stuff into the variable.

Now the plugin command should:
Choose variable number to load data into
Choose file path
Choose file name to open

It should locate the file we give through its path, take the data, pass them one by one through a method that does nothing to them (I will make the decryption code and everyone can use custom methods) and then put all rows of the file into the variable array until it reaches EOF.

This plugin can actually be used to use different languages (different text files) to the game so yeah... just some ideas, it can actually be used for localization purposes and easier text proofing and stuff.

Thanks in advance.
 
Last edited:

Eliaquim

Raze: The Rakuen Zero's Guardian!
Veteran
Joined
May 22, 2018
Messages
951
Reaction score
385
First Language
Portuguese - Br
Primarily Uses
RMMV
wow!!
I can't do this. But maybe I have a way for you!
But, not exactly with variables. See if helps:

https://forums.rpgmakerweb.com/index.php?threads/iavra-localization.53699/

In short, this plugin is originally to translate a game. With him, you can make a .JSON file, and add text to your game.
This is how your JSON file will be.

And this is how your message text boxes(but not only message box, I think you can use it to everything in your game. If I'm not wrong, any text that be written inside a window, this will work) will be in the game:

So, in this text box, it will show the text that corresponds to this tag:
"Oh no. \\.They're already here... <br>Soldiers, hurry!"

Check out the link at the beginning of this comment. You also can use arrays to store the text data in the tags.

Hope this can help you!! ^^
 

Dreadshadow

Lv 38 Tech Magician
Moderator
Joined
Mar 2, 2014
Messages
3,879
Reaction score
2,518
First Language
Greek
Primarily Uses
RMMV
This is actually brilliant, but it does not implement a method to pass it through a decryption.
If someone can add a method in it, in order for me to tangle it later with the decryption method, then case solved really, since json are really better.
Thanks for sharing this with me!!!

If anyone can make
https://forums.rpgmakerweb.com/index.php?threads/iavra-localization.53699/
to pass the the json text through a method as I requested, then we are too close to the final solution.
 

caethyril

^_^
Veteran
Joined
Feb 21, 2018
Messages
1,455
Reaction score
940
First Language
EN
Primarily Uses
RMMV
In case it helps: I made a little plugin, Cae_ExtraJSONs, that loads specified JSONs into specified global variables. It uses the default DataManager.loadDataFile method, which means it should pass the file through the decrypter (via DataManager.onLoad) where necessary...haven't tested it personally, though. :kaoswt:

You'd also need something like this on new game (e.g. an autorun event) if you want to reference the global data via a game variable, Control Variables > Script:
Code:
$customData
If you want the data to change during the game then you'll be best off cloning it instead. If it's just a simple array of numbers, this ought to work:
Code:
$customData.slice()
Explanation: Array.slice on MDN. :kaopride:
 

Dreadshadow

Lv 38 Tech Magician
Moderator
Joined
Mar 2, 2014
Messages
3,879
Reaction score
2,518
First Language
Greek
Primarily Uses
RMMV
All right! Seems nice. And the slice example was great, I got it all right! It can be tricky to keep track on what to slice out, but I will manage no problem. The thing is, I don't know how to syntax a json file to add let's say two strings into $customData.
@caethyril can you help me out by showing me a JSON containing two strings that will work with your plugin?
Also, how am I gonna call it on Show Text?
Check @Eliaquim's spoiler buttons on their post to see what I mean. :)
Thank you very much for your help though! It seems like your solution can do the trick as long as I understand how to handle it.
 
Last edited:

caethyril

^_^
Veteran
Joined
Feb 21, 2018
Messages
1,455
Reaction score
940
First Language
EN
Primarily Uses
RMMV
Something like this should do the trick, just make sure to save it as a .json file in your project's data folder:
Code:
[
"entry zero",
"one",
"two!",
"no comma after this"
]
This is basically just an array of text (strings), with each entry on its own line for readability. :kaophew:

My ExtraJSONs plugin uses the v1.5.0+ editor's "list" parameter type, a list of pairs: file name and variable name. The default new entry is "File name: Custom" and "Variable name: $customData", which will cause it to read data from Custom.json into a global "script" variable named $customData. Kinda like the game does with Actors.json and $dataActors, for example. :)

As mentioned, to assign the value to a game variable, just use Control Variables > Script:
Code:
$customData.slice()
The only thing left then is the Show Text thing...a potential problem. I'll illustrate with an example event:
Code:
◆Control Variables:#0001 v1 = $customData.slice()
◆Control Variables:#0002 v2 = $gameVariables.value(1)[0]
◆Text:Actor3(5), Window, Bottom
:    :\v[1]
:    :\v[1][0]
:    :\v[2]
When tested in-game, this shows:
Code:
entry zero,one,two!,no comma after this
entry zero,one,two!,no comma after this[0]
entry zero
To get the \v[x][y] thing to work, I came up with this little standalone plugin. It's just plug & play and seems to work after a little testing, hopefully won't break anything. :kaoswt: I suggest loading it after any other message plugins you may be using.

After adding this plugin to my test project, the in-game test message output was like this:
Code:
[entry zero,one,two!,no comma after this]
entry zero
entry zero
It's still a less comprehensive solution than Iavra's Localisation, though. Not sure how easy it'd be to extend Iavra's plugin(s) to use the decrypter, but I imagine the end result would be much neater. :kaoswt2:
 

Dreadshadow

Lv 38 Tech Magician
Moderator
Joined
Mar 2, 2014
Messages
3,879
Reaction score
2,518
First Language
Greek
Primarily Uses
RMMV
What you did there is excellent. I will try it as fast as I can I have to go AFK unfortunately. I will come back with feedback after gluing things together. Don't worry though, I will probably not use much stuff, so nothing will break really. I start from scratch in a brand new project.
 

Dreadshadow

Lv 38 Tech Magician
Moderator
Joined
Mar 2, 2014
Messages
3,879
Reaction score
2,518
First Language
Greek
Primarily Uses
RMMV
In a blank file I added this:
[
"First Line",
"Second Line",
"Third Line!",
"Final line is fourth"
]

Then I saved it as Custom.json in the data folder.


Added the plugin, opened the Prameters, had set {"File name":"Custom","Variable name":"$customData"}
In a Parallel Event I entered these:


◆Control Variables:#0001 = $customData
◆Control Variables:#0002 = v2 = $gameVariables.value(1)[2]
◆Text:None, Window, Bottom
:Text:Test.
:Text:\v[1]
:Text:\v[2]

PROBLEM:
Reference error, $customData is not defined.

What did I do wrong here?
 

caethyril

^_^
Veteran
Joined
Feb 21, 2018
Messages
1,455
Reaction score
940
First Language
EN
Primarily Uses
RMMV
@Dreadshadow: oh that's strange, I think that should work. :kaoswt2:

If you press F8 during playtest to view the console, are any errors displayed there? Maybe something went wrong with the download and the plugin isn't loading correctly? Not sure. :kaoswt:

By the way, probably unrelated to the error, but v2 was just what I called my variable, it's not part of the script call, i.e. use this for variable 2 in your test message:
Code:
◆Control Variables:#0002 = $gameVariables.value(1)[2]
 

Dreadshadow

Lv 38 Tech Magician
Moderator
Joined
Mar 2, 2014
Messages
3,879
Reaction score
2,518
First Language
Greek
Primarily Uses
RMMV
Found the problem. I copy - pasted the script into a js file with your name and what it is, as a filename. That is different from your original naming of the plugin and the plugin probably use this specific name as self reference or something.
Renaming as Cae_ExtraJSONs.js solved the case. I will check what I can do with that now! :) :3

Also....
Terms of use for the
/*:
* @plugindesc Array-variable parsing for Show Text: \v[x][y]
* @Author Caethyril
*/

I wanna know because respecting the original author is the least you can do for them.:kaoswt:

If it's all right to use for anything, then case closed.
 
Last edited:

caethyril

^_^
Veteran
Joined
Feb 21, 2018
Messages
1,455
Reaction score
940
First Language
EN
Primarily Uses
RMMV
Strange, I thought I had a failsafe in there to throw a big error if the parameters aren't found, i.e. if the plugin is named differently. Guess that didn't work out. xP

Oh, yes, all my plugins so far, including both I've linked in this thread, are OK to use, edit, etc for anything you like, commercial or non-commercial! :kaojoy:
 

Dreadshadow

Lv 38 Tech Magician
Moderator
Joined
Mar 2, 2014
Messages
3,879
Reaction score
2,518
First Language
Greek
Primarily Uses
RMMV
The only problem now, is that I wanted to access the Serial Number of the HDD or Motherboard, or at least the MAC address of a device running the game. The problem is that within a browser, JS can not reach the hardware for security reasons. Thus my plan seems like a fail, but still I really can use well this JSON to text direct assignment, no matter what. :kaoluv:
 

caethyril

^_^
Veteran
Joined
Feb 21, 2018
Messages
1,455
Reaction score
940
First Language
EN
Primarily Uses
RMMV
You're welcome! :kaothx:

Yes, I don't think getting the MAC address is possible from a HTML deployment due to security constraints. However, platform-specific RMMV deployments (Windows/Mac/Linux, mobile also?) are based on NW/Node.js, granting more access; e.g. local deployments can write to external save files. :)

It seems there are packages available for getting the system's MAC from a Node app, though I wouldn't know where to start with getting that working: https://stackoverflow.com/questions/16386371/get-the-mac-address-of-the-current-machine-with-node-js-using-getmac :kaoswt2:
 

Dreadshadow

Lv 38 Tech Magician
Moderator
Joined
Mar 2, 2014
Messages
3,879
Reaction score
2,518
First Language
Greek
Primarily Uses
RMMV
Yes I have found that one. Well... no. I won't dive that deep just for copy protection when you can deploy the game through a server with restricted access locally if you want to. I wanna make a very specific tutorial game series in my native language and either sell it or provide it along with my services. So I ended up wondering, why not implement it as an online project and deploy it after a login screen passing by a server to grant access to anyone who has credentials?
No matter what, this is gonna be helpful, especially if someone wants to do neat tricks with it. I mean, inserting values from a custom JSON file directly into the Show Text interface? Wow!
 

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

Latest Threads

Latest Profile Posts

I picked up For The King in a Humble Bundle sale, and one mechanic that stuck out to me was a physical change to the world map when finishing a side quest. That got me thinking about special map-effect rewards for certain side quests in my game.
Stream will be live shortly with some Witcher 3! Feel free to drop by!
This forum is a great source of procrastination for me.
Today I read "The mouth speaks what the heart is full of." Simple, and reminds me I have a ton of work to do.
Why are cats so darn cute when their tongues are sticking out? If I did that, it wouldn't have the same effect.

Forum statistics

Threads
94,399
Messages
920,665
Members
124,188
Latest member
Meiji
Top