Welcome Guest ( Log In | Register )

[ Big| Medium| Small] -



Post new topic Reply to topic  [ 3 posts ] 
    Xilef
  Tue Jan 05, 2016 12:29 am
User avatar
Staff

Big Dumb Guy

Location: UK
Not a full Plugin, but a utility for Plugin developers that want to use JSON with MV plugin commands.

Plugin Commands are separated by spaces and do not take quotes into account, which means data structures aren't very compatible.

This snippet parses that array of space-separated command arguments and gives you something that's been sanitised to support JSON.

The way a JSON structure starts is a white-space followed by an open-brace character {
"abc{" will not work, but {{ will
There is no error detection or JSON validation, so if there is a missing closing brace the entire string will be appended on.

I have tried to cover every weird case to avoid bugs, but if you find a weird-case bug please say so.

Usage: var args = ParseCommandArgs( ["plugin", "command", "array"] );
Expand to see the code.


An example command could be:
MyPlugin character { 'name' : 'xilef', 'level' : 0, 'stats' : { 'hp' : 123 } }
Everything in that JSON structure will be sanitised into a single string and all the arguments around it will be strings as usual.

Result : ["MyPlugin", "character", "{ 'name' : 'xilef', 'level' : 0, 'stats' : { 'hp' : 123 } }"]
Without this snippet : ["MyPlugin", "character", "{", "'name'", ":", "'xilef',", "'level'", ":", "0,", "'stats'", ":", "{", "'hp'", ":", "123", "}", "}"]

Here's an optimised version of the snippet:
Expand to see the code.


Top Top
Profile      
 

    Amy
  Tue Jan 05, 2016 12:32 am
User avatar
Staff

Big Dumb Guy
Nice, it's always bugged me how limited plugin commands are.


Top Top
Profile      
 

    Xilef
  Tue Jan 05, 2016 12:50 am
User avatar
Staff

Big Dumb Guy

Location: UK
Forgot to mention; this only sanitises the string. To get a Javascript object out of the JSON you need to do something like this;

Expand to see the code.


Princess Amy wrote:
Nice, it's always bugged me how limited plugin commands are.

This is part of an attempt to make them more useful.

On one hand it solves the problem of lack of API space in previous RPG Maker versions, on the other hand it's very difficult to get a sane usage scenario figured out for it - especially when the script option is just above and can do the same + more than the plugin command system.

Adding data structure support is a small way to alleviate that, at the expense of JSON's complexity being dragged into it (ugh).


Top Top
Profile      
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 


Who is online

Users browsing this forum: No users and 7 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

We are an independent, not-for-profit game making community.
Homepage
Board Index
About Us
Downloadable Games
Free Browser Games
Games in Development
RPG Maker Support
Game Maker Support
Construct 2 Support
HBGames the eZine
Advanced RPG Maker
Site Announcements
Powered by phpBB © phpBB Group