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] Script Call Function

Status
Not open for further replies.

LTN Games

Master Mind
Resource Team
Xy$
0.01
I'm not sure the best way to explain this but I'm trying to create a function that can be called through a script call in an event. I'm trying to allow the contents of my window be changed via a script call, basically allowing me to set the icon and the text through a function I create. Here is the function I made with the best of my knowledge on how they work.

JavaScript:
Window_Pop.prototype.setWindowPop = function(icon, text) {
  this._icon = icon;
  this._text = text;
  var x = this.textPadding();
  var width = this.contents.width - this.textPadding() * 2;
  this.fontSize = 18;
  this.drawTextEx(this._text, 0, 0);
  this.drawIcon(this._icon, 0, 0);
}
So what I'm trying to do here is create a function called setWindowPop with the parameters being icon and text.
I then put the parameters in variables ( if that's allowed I still have ruby in my brain when scripting) and then I call the drawText and draw Icon methods to output the variables . The next thing I do is I go to an event and do a script call for ( I've tried a few different ways)

Code:
this.Window_Pop.setWindowPop(5, 'Hello');  //One way I tried
this.setWindowPop(5, 'Hello'); // Another way
Window_Pop.setWindowPop(5, 'Hello'); // and another way lol
I would keep getting errors though and the console log won't point to my script only to game_interperter but it would throw undefined not a function, and I don't quite remember the other ones.

Here is the full script without the parameters at the top.
JavaScript:
// =============================================================================
// Alias Nethod: Scene_Map Start
// =============================================================================
LTN.WindowPop_oldMapSceneStart = Scene_Map.prototype.start
// =============================================================================
Scene_Map.prototype.start = function() {
    this.createWindowPop();
    LTN.WindowPop_oldMapSceneStart.call(this);
};
// =============================================================================
// New Method:Scene Map Create Window Pop
// =============================================================================
Scene_Map.prototype.createWindowPop = function() {
    this._WindowPop = new Window_Pop();
    this.addChild(this._WindowPop);
};

//=============================================================================
// New Window* Window Pop
//=============================================================================
function Window_Pop() {
    this.initialize.apply(this, arguments);
}

Window_Pop.prototype = Object.create(Window_Base.prototype);
Window_Pop.prototype.constructor = Window_Pop;
//-------=====---------
//Initialize
//-------=====---------
Window_Pop.prototype.initialize = function(x, y) {
    var width   = 350;
    var height  = this.fittingHeight(1);
    var x       = LTN.Param.windowX;
    var y       = LTN.Param.windowY;
    Window_Base.prototype.initialize.call(this, x, y, width, height);
    this.refresh();
};
//-------=====---------
// hide
//-------=====---------
Window_Pop.prototype.hide = function(){
  this.visible = false;
}
//-------=====---------
//Width
//-------=====---------
Window_Pop.prototype.windowWidth = function() {
  return 350;
}
//-------=====---------
//Refresh
//-------=====---------
Window_Pop.prototype.refresh = function() {
    this.contents.clear();
    this.setWindowPop(this.popIcon, this.popString);
};
//-------=====---------
// Draw contents
//-------=====---------
Window_Pop.prototype.setWindowPop = function(popIcon, popString) {
  var _icon = this.popIcon;
  var _text = this.popString;
  var x = this.textPadding();
  var width = this.contents.width - this.textPadding() * 2;
  this.drawTextEx(this._text, 0, 0);
  this.drawIcon(this._icon, 0, 0);
}
P.S this is just some code that I am having fun with, I been testing different methods and trying to get the hang of the whole window and scene cores, so if this current script looks a bit off, it's because I been testing a lot.
Thanks
 

Boy Who Codes

Praised Adventurer
Xy$
0.00
Here's what I can recommend. Create a function in Game_System that holds a variable for the string. Then, make sure that the ones that is displayed is the ones in Game_System variable, not the ones you instantiated from your window.
 

LTN Games

Master Mind
Resource Team
Xy$
0.01
@eivl - Yea I know how to create a scene now but my idea in mind is to only have a window pop up when I script call a function to do so, and this idea does not require it's own scene, it needs to be on the Scene_Map for instant and unobtrusive messages that will pop up on the left of the screen. I'm doing this so I can learn how things are interacting with each other and the structure and hirearchy of the code structure. I will PM my complete script so you can take a look.

@Soul - I understand what your saying but I'm not 100% on how to implement this, I'm still fairly new to scripting in RM. So I create the same kind of function in Game_System but how would I get the window which draws the string and icon to read the variables in Game_System.
[doublepost=1447954447,1447776025][/doublepost]
Create a function in Game_System that holds a variable for the string. Then, make sure that the ones that is displayed is the ones in Game_System variable
I have created variables in Game System as you have mentioned and I have been able to store information in them from in game as well. Though I am suck at trying to understand how to call a method from in game. See I want the window to pop up on demand when the method is called from a script call command. So I figured making the method with arguments icon & text would have done the trick, then I can proceed with opening the window and allowing it to show the new information I inputed with the script call. My current issue is that no matter the method I create I cannot call from a script call in game because it throws a Game_Interperter Eval error or an undefined object error. I figured maybe I had to create the script call in the Game_Interperter class but even this has failed me. So I guess my main concern right now before I proceed with the rest of my plugin is getting a method to run while in game which allows me to set the icon & text arguments.

Thanks :D
 

Boy Who Codes

Praised Adventurer
Xy$
0.00
Are you using the 'this' as well on Game_Interpreter? This sounds like a good topic for my tutorial, I'll include it soon as I finished all my other requested tutorials :D
 

LTN Games

Master Mind
Resource Team
Xy$
0.01
In the script call I have tried many things and this.windowPopSet(); was the one I rememebr using the most because I remember @eivl said it's the correct way when calling within the same class. I would really appreciate a tutorial on this and can patiently wait for it, thank you very much, and I also look forward to your other requested tutorials, I hope to see some new ones soon they've all been a big help.
 

Boy Who Codes

Praised Adventurer
Xy$
0.00
Can you add a list or number of tutorials you want to see after the other tutorials on my bucket list? I will give my best to answer them soon.
 

LTN Games

Master Mind
Resource Team
Xy$
0.01
I will put together a list over the next few hours, this is a good opportunity for me to get some good questions answered. I will PM the list to keep this thread clean.
Thanks :D
 

Boy Who Codes

Praised Adventurer
Xy$
0.00
Alright, that's great. The 6 requested tutorials are to be done this weekend, and I am sure I'd be able to do them in one sitting. Most of them are about graphics though, I rarely get requests about Window and anything that has to do with Game Objects.
 

LTN Games

Master Mind
Resource Team
Xy$
0.01
I managed to finally do a script call which puts the arguments "icon" and "text" into $gamesystem variables. I am at least 5 steps further than I was when I started this thread. So thank you for your help. I'm really starting to get the hang of the hierarchy of the structure of the scripts and how to interact with classes and what not. I am curious though do I have to use Game_System to create my global variables? Is this a normal way of doing this kind of thing?.
 
Status
Not open for further replies.
Top