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!

[Scripting] Plugin Command Arguments

Status
Not open for further replies.

LTN Games

Master Mind
Resource Team
Xy$
0.01
So after playing around with the plugin command method, I noticed a few strange issues with it. For starters what if someone else is using the same command name as me, for example: I use CutomPop in my script for a plugin call, but what if someone else used this in their scripts, would this not conflict with other plugins?. The next small thing I noticed was the arguments, and this is more of a question because I'm probably just lacking in JS knowledge to figure it out, how does the interpreter detect the arguments? is it with each space after the command word? so example "CUSTOMPOP 0 String 120" So after CUSTOMPOP is 0 which is the first argument, then String is second argument then 120 is third argument, the issue I see here is what if I go something like this "CUSTOMPOP 0 A longer string 120". So this time the second argument is actually argument 2-4 and 120 is now argument 5. How is it that I can make string more than 1 word at a time without taking up other arguments.
 

eivl

Local Hero
Xy$
0.00
would this not conflict with other plugins?
Yes it would.
how does the interpreter detect the arguments?
args is an array split by default with white-space.
Code:
CUSTOMPOP 0 String 120
command       args

args[0] = 0
args[1] = string
args[2] 120
How is it that I can make string more than 1 word at a time without taking up other arguments
you should not, you need to separate it with something, you could of course rewrite the game_interpreter to use something else then white-space as a separator, but then you sill would have to separate it.

If you had Command + Argument + Argument + String
you should then use args.length to get the number of arguments and the have a for/while loop to go through the arguments and generate the string.

hope i made any sense ;)
 

LTN Games

Master Mind
Resource Team
Xy$
0.01
Excellent so I'm a step further, I was able to get the length of the string and put it into a variable, now I have a new issue. The full string won't display in my window as a full string, I'm only getting the last word in the string. I have the console give me what is in the variable and I'm getting the full string, but it's not all as 1 full string it's 4 separate strings, how would I make it into one full string from the array. Here is what I scripted. Thanks for the push in the right direction @eivl, you seem to be doing alot of that for me lately lol.
I removed my directory path from the text.
LTN_WindowPop.js:435 A
LTN_WindowPop.js:435 longer
LTN_WindowPop.js:435 pop
LTN_WindowPop.js:435 up
JavaScript:
// =============================================================================
// Old Method: Game_Interpreter.. Create Plugin Command
// =============================================================================
LTN.WPOP_oldGPpluginCommand = Game_Interpreter.prototype.pluginCommand;
//-------=====---------
Game_Interpreter.prototype.pluginCommand = function(command, args) {
LTN.WPOP_oldGPpluginCommand.call(this, command, args);
  if (command === 'WPOP') {
    WPOP._popIcon    = args[0];
    WPOP._popTimer   = args[1];
    for (var i = 2; i < args.length; i++) { //Start at 2 because I don't need first 2 args
      WPOP._popString  = args[i];
      console.log(WPOP._popString);
    }
    WPOP._currentPop = 'Custom';
    WPOP._autoSE     = 'ON';
  }
};
 

eivl

Local Hero
Xy$
0.00
There is nothing wrong with your code.
you might be calling the plugin in a wrong way.

give me your variable and object declaration and then your plugin command event.
[doublepost=1448740889,1448740673][/doublepost]
 

LTN Games

Master Mind
Resource Team
Xy$
0.01
give me your variable and object declaration and then your plugin command event.
JavaScript:
var WPOP = WPOP || {};
// Initialize Custom Pop Up Variables
WPOP._popIcon      = 0;
WPOP._popString    = '';
WPOP._popTimer     = 0;
I use these for storing the plugin arguments.
The code above in previous post is for plugin command it's where I set the variables.
Then I display them once the timer is active it fades in window and draws text with the variables above.
This is the function that draws the text and is called once timer is active.
JavaScript:
Window_Pop.prototype.drawCustomContents = function() {
  var popString = WPOP._popString;
  var popIcon = WPOP._popIcon;
  var cx = 40;
  if (!popIcon) {
    cx = 5;
  }
  this.drawTextEx(popString, cx, 0);
  this.drawIcon(popIcon, 5, 2);
};

The command in my event is as followed.
WPOP 5 120 A longer pop up
I hope this is what you were looking for.

Okay, I figured something out about the for loop code. What I had was setting the variable each time it went through the arguments, so instead of adding each argument to the variable it was just setting it to the argument, which is why I always got the last argument to show up. At least that's what I see happening, so I decided to do this instead.
JavaScript:
  WPOP._popString  += args[i];
this works, it adds each string side by side but it looks like this "alongerpopup" instead of "A longer pop up" Is there any way to space it out?
 

eivl

Local Hero
Xy$
0.00
Yeah you are right. if the idea was to rebuild the string then that makes sense. but you need to add a space as well, since it most likely has been removed.
[doublepost=1448753794,1448753452][/doublepost]But why do you want to rebuild the string? should not the plugin command handle that or do you need to save the string for further use?
 

LTN Games

Master Mind
Resource Team
Xy$
0.01
The plugin command will have the string I need to display in my window, so I need to save it to the WPOP._popString, then use that variable for the string in my window. So yes rebuilding I believe is my best option, but then I need to figure out the spaces.
 

eivl

Local Hero
Xy$
0.00
JavaScript:
var LTN = {};
var WPOP = {};
WPOP._popString = "";
// =============================================================================
// Old Method: Game_Interpreter.. Create Plugin Command
// =============================================================================
LTN.WPOP_oldGPpluginCommand = Game_Interpreter.prototype.pluginCommand;
//-------=====---------
Game_Interpreter.prototype.pluginCommand = function(command, args) {
LTN.WPOP_oldGPpluginCommand.call(this, command, args);
  if (command === 'WPOP') {
    WPOP._popIcon    = args[0];
    WPOP._popTimer   = args[1];
    for (var i = 2; i < args.length; i++) { //Start at 2 because I don't need first 2 args
      WPOP._popString  += args[i];  // WPOP._popString  += args[i] + " "; this would add an extra space to the last args 
      if(i<args.length){
        WPOP._popString += " ";
      }
    }
    console.log(WPOP._popString);
    WPOP._currentPop = 'Custom';
    WPOP._autoSE     = 'ON';
  }
};
make an if statement that ads the space, since you do not want to add a space after the last arg
remember to define your string variable since you are not overwriting it but adding with +=
with out these two changes your string would look like this

"undefinedThis is my string "
 

LTN Games

Master Mind
Resource Team
Xy$
0.01
That did it for me, perfectly. I learned quite a few new things here since I started this post mainly, exactly how for loops work and how plugin arguments work, I should not have many problems with these anymore lol. Thank you so much @eivl you're a great help.
 
Status
Not open for further replies.
Top