Submit Your Article


 
RPG Maker

Welcome Guest ( Log In | Register )


  Games Resources RPG Maker VX RPG Maker XP Scripts Tutorials Downloads

> [Scripting]Advanced Windows, A tutorial from the Script Builders
The Law G14
post Nov 14 2009, 04:41 PM
Post #1


Scripter FTW
Group Icon

Group: Local Mod
Posts: 1,346
Type: Scripter
RM Skill: Skilled
Rev Points: 5




The Script Builders' Tutorials:
----Lesson 3: Advanced Windows----


I. Introduction
II. Using the Draw methods
III. Showing Pictures
IV. Window Opacity
V. Conclusion
VI. Homework


I. Introduction

Hey R3! Welcome to the third lesson by the Script Builders. So far, we know how to make Basic Windows and Selectable Windows. In this tutorial we’re going to be learning how to display useful information, not just text. Also, in this tutorial, I’m going to be teaching you guys in a different fashion. There will be three mini lessons inside of this lesson which are ‘Using the Draw methods’, ‘Showing Pictures’, and ‘Window Opacity’. Why am I doing it like this? Two reasons. One, it’s a more effective way to teach you, rather than just me making a script and showing you what everything means, I’ll be showing you guys how to manipulate each part so that you have a better understanding of everything. And two, I’ll feel better when you give in your homework as I’ll know you didn’t just copy the script I made at the end and just change around the values, since there will be none; rather you will actually be thinking about how you can put the pieces together from the three mini-lessons into a script. Without further ado, let’s begin the tutorial smile.gif


II. Using the Draw Methods

The draw methods are very useful tools when making your windows. Remember from The Basic Windows tutorial that methods are blocks of code you can reuse throughout your script. Examples of these draw methods include:

CODE
draw_actor_hp(actor, 0, 0)


CODE
draw_actor_state(actor, 0, 0)


The preceding codes are used to draw the hp of an actor and their state. The parameters, the values inside the parenthesis, of the two methods are from left to right: the actor being passed through the method, the x coordinate of the text, and the y coordinate. You can find all the draw methods from lines 102 to 321 of Window_Base.

Now, without further ado, let’s utilize these draw methods!

First of all, take out that Window Base Outline from Notepad and open it up. Copy it into the script editor of a new rmxp project and put it right above the Main script. Name the script “Advanced Window” in the space provided below the Main script.

Now, on line two of the script, type in the name of our class after the comment symbol, which is going to be ‘Window_Advanced’. On line four of the script, type in a simple description like “This class uses the draw methods”. Now, on line seven of the script, which starts with ‘class’, change the line to this since we are inheriting from Window_Base:

CODE
class Window_Advanced < Window_Base


Now, before we continue our script, we have to have a clear idea on what we are going to make. Since we plan on showing actor values using our draw methods, let’s make a basic hud that shows the HP, SP, Exp, and name of the first character in your party (We’ll get to showing huds that go for all four party members in later tutorials). So, our window shouldn’t be that big. For our x coordinate and y coordinate (first two values in the parenthesis next to the super keyword) let’s leave them at 0 so that we can have our window in the upper left corner of the screen. Our width (third value) should be about 200 and our height (last value), should be about 150.

Now, let’s move on to our refresh method. To start out, let’s write out our actor’s name on the first line of our window. The code to draw an actor’s name is this:

CODE
draw_actor_name(actor, x, y)


Put this line of code after this line

CODE
self.contents.clear


But wait, why is ‘actor’ left as the first value in the parenthesis of the draw_actor_name method? We haven’t assigned a value to it so what’s it doing like that? Well, why don’t we assign a value to ‘actor’ so that we know what actor we are drawing the name of? Before the draw_actor_name line, put this line of code in:

CODE
actor = $game_party.actors[000]


This line of code allows us to go through the actors in your $game_party and in the brackets, we’ve chosen the first actor in our list of actors in the database. If you’re in a new rmxp project, that means we just chose Aluxes, which means that our draw_actor_name method will draw Aluxes’ name which is Aluxes.
Next, change the x value to 0 and the y value to 0 in the draw draw_actor_name parameters so that our text is at the upper left corner of the screen.

Now, all we have to do is space out the rest of our text by about 30 pixels. So, basically, we would just copy the rest of the draw methods we need under our draw_actor_name method to essentially have three more lines of code under our draw_actor_name method. These three lines would look like this:

CODE
draw_actor_hp(actor, 0, 30)
draw_actor_sp(actor, 0, 60)
draw_actor_exp(actor, 0, 90)


As you may notice, the only change we have done inside the parameters is increase the y value by 30 pixels by each line of text. By now, your script editor should look like this:

Big Image


If it does, move on to showing the window using events like explained in the past two tutorials (so I shouldn’t have to explain it again). Your ending result should look like this:



If it does, congratulations, you’re one step closer to making complex windows smile.gif


III. Showing Pictures

This mini-tutorial is fairly hard to grasp, but hopefully, you’ll be able to follow along my explanations.
First of all, open up your script editor in a new rmxp project and go to the Window_Gold script. To make a picture, you need to define a method which I’ve learned as the draw_picture method (yes, this is technically a draw_method, so you can put it in the Window_Base script if you’d like so that you don’t have to define it all the time). After line 15 of the Window_Gold script, make a space to put this line of code in:

CODE
def draw_picture(x, y)


As you can see, we’ve just defined a method called draw_picture and we set its parameters to x and y which will come to use later in our code.
Next, add this line in:

CODE
bitmap = RPG::Cache.picture("")


This line assigns a value to the bitmap variable. The value assigned is a picture in the pictures section of our recourse manager. The way the system knows what picture we are talking about is by placing the name of the picture inside the quotes of that line. So, save this picture (I know random):

In the pictures section of your recourse manager and then inside the quotes of that line we just added, put the name of what you saved this picture as. I called mine ‘picture’, thus the line we just added, I would change it to this:

CODE
bitmap = RPG::Cache.picture("picture")


After that line, add this line:

CODE
src_rect = Rect.new(0, 0, bitmap.width, bitmap.height)


What does this line do? Well, we just assigned yet another value to another variable. This value assigned is a rectangle. Yup, you heard me. When you say Rect.new, that means you’re drawing a rectangle which is where we will show our picture. When you make a new object of the Rectangle class, you have to define its x and y coordinates, its width and height. Well, for the width and height, all you have to do is make it the same of the width and height of our picture. So, it would be bitmap.width and bitamp.height since we assigned our picture to the bitmap variable. Just leave your x and y values as zero since they are just dummy values, our real x and y values will be defined later.

The last line of our method is this:

CODE
self.contents.blt(x, y, bitmap, src_rect)


Add this line after that last line we just added. What this line of code does is put everything together. It makes the image set at its x and y values (which will be defined later), the image to draw, and the rectangle to draw on.

After that line, put the ‘end’ keyword to show that we closed our method. The last thing we need to do define our x and y values which will happen in our refresh method like any other draw_method.

Add a space after the self.contents.clear line and put this line of code in:

CODE
draw_picture(x, y)


Change the x and y values to whatever you like (I did something simple and put them both at zero). So, our script editor should look similar to this:

Big Image


Go to your menu to see if there is a picture in the gold window. If there is, then congrats, you know how to show pictures now!


IV. Window Opacity

This mini tutorial should be very easy for you to grasp. First of all, go the script editor in an rmxp project and go to the Window_Item script. In this mini-tutorial, we’ll be basically talking about how to change the opacity of windows. Go to line 15 of the script and make a new line after it to paste in this line of code:

CODE
self.back_opacity = 0


What this does is make the window (self) change its back opacity (which dis-includes the white border around it) to zero (which means it is completely transparent). Test run your game and go to the item screen and you’ll notice that the bottom window is completely black with a white border around it. Try playing around with the opacity to see the effect.

Go back to the Window_Item script and change the line we just added to this:

CODE
self.opacity = 0


This code includes the white border on the window so that the bottom window in the item screen is completely black. Just check it yourself, test run your game and go back to the item screen and you’ll notice that the bottom window is completely black. Play around with the opacity to see what happens.


V. Conclusion

Hopefully, you’ve guys grasped everything I’ve said, and if not, don’t worry at all. Just reread the tutorial as this tutorial is a very hard and complex one. If you have any questions, please post. Now for a summary of what you have learned:

  • The draw methods are useful methods that you can use to show a bunch of information on your window such as hp, sp, exp, etc.

  • You can create your own draw methods, just be sure they are useful enough to belong in that category.

  • You can show pictures using the draw_picture method and change its x and y values in the refresh method of your window.

  • You can change the opacity of your windows in two ways. One way is by using the self.back_opacity code that affects the opacity of a window except for the border around it. The other way is the self.opacity code that changes the opacity of everything on the window.

  • You can edit pre-existing scripts to show pictures, change opacity, edit values, etc.



VI. Homework

Combine everything you’ve learned in this tutorial to make some great windows. Good techniques you can use is making your window completely opaque and then putting a picture on it so that the background would be a picture instead of a window. You can also use the draw methods to show actor stats and then putting icons as pictures in front of them. Try your best to amaze me and just do what you can to show that you have mastery over windows.


__________________________

To put in sig, copy this link:
CODE
[url="http://www.rpgrevolution.com/forums/index.php?showtopic=51540"][img]http://img40.imageshack.us/img40/6504/conceptthelawbanner.png[/img][/url]


Sig Stuff


"When you first come, no one knows you. When help them out, they all know you. When you leave, they all love you. When you come back, they've already forgotten you." -- copy into your sig if you think this quote speaks true!

If you are one of the very few teenagers that know what real rap is and don't blindly listen to the hate statements (rap is crap), then put this in your sig. I say this in the name of Common, Mos Def, Lupe Fiasco, 2Pac, Nas, Talib Kweli, Eminem, and many others. -Exiled One

My Project Thread: Gai's Hunters


Go to the top of the page
 
+Quote Post
   
 
Start new topic
Replies
BigEd781
post Nov 16 2009, 10:13 PM
Post #2


No method: 'stupid_title' found for `nil:NilClass'
Group Icon

Group: Revolutionary
Posts: 1,829
Type: Scripter
RM Skill: Undisclosed




The example shows the method as $game_party.actors, plural, not "actor", singular.


__________________________
`
Give me teh codez!!!


I am the master debator!
Go to the top of the page
 
+Quote Post
   
MetalnosX
post Nov 16 2009, 10:58 PM
Post #3


Level 2
Group Icon

Group: Member
Posts: 27
Type: Developer
RM Skill: Intermediate




QUOTE (BigEd781 @ Nov 17 2009, 05:13 PM) *
The example shows the method as $game_party.actors, plural, not "actor", singular

Woops sorry i know it was "actors" but it still have the same problem? Have at the image now.

This post has been edited by MetalnosX: Nov 16 2009, 11:00 PM


__________________________
[/size][/color]Ahhhhhh!...AHH!....AHHHH! Madman hitting me with oranges!! ....... Oh?... Is that my brother?[size="6"][color="#FF0000"] Man i cant do this lol
Go to the top of the page
 
+Quote Post
   
BigEd781
post Nov 17 2009, 09:39 AM
Post #4


No method: 'stupid_title' found for `nil:NilClass'
Group Icon

Group: Revolutionary
Posts: 1,829
Type: Scripter
RM Skill: Undisclosed




QUOTE (MetalnosX @ Nov 16 2009, 10:58 PM) *
QUOTE (BigEd781 @ Nov 17 2009, 05:13 PM) *
The example shows the method as $game_party.actors, plural, not "actor", singular

Woops sorry i know it was "actors" but it still have the same problem? Have at the image now.


Hmmm, not sure then, we will have to wait until someone who knows XP comes around. I have never written scripts for XP, and in VX there is a global collection named $game_actors from which you get actor objects.


__________________________
`
Give me teh codez!!!


I am the master debator!
Go to the top of the page
 
+Quote Post
   
MetalnosX
post Nov 17 2009, 10:19 PM
Post #5


Level 2
Group Icon

Group: Member
Posts: 27
Type: Developer
RM Skill: Intermediate




QUOTE (BigEd781 @ Nov 18 2009, 04:39 AM) *
QUOTE (MetalnosX @ Nov 16 2009, 10:58 PM) *
QUOTE (BigEd781 @ Nov 17 2009, 05:13 PM) *
The example shows the method as $game_party.actors, plural, not "actor", singular

Woops sorry i know it was "actors" but it still have the same problem? Have at the image now.


Hmmm, not sure then, we will have to wait until someone who knows XP comes around. I have never written scripts for XP, and in VX there is a global collection named $game_actors from which you get actor objects.

Well im using VX and the problem is in VX not XP so yeah.


__________________________
[/size][/color]Ahhhhhh!...AHH!....AHHHH! Madman hitting me with oranges!! ....... Oh?... Is that my brother?[size="6"][color="#FF0000"] Man i cant do this lol
Go to the top of the page
 
+Quote Post
   
BigEd781
post Nov 17 2009, 11:58 PM
Post #6


No method: 'stupid_title' found for `nil:NilClass'
Group Icon

Group: Revolutionary
Posts: 1,829
Type: Scripter
RM Skill: Undisclosed




QUOTE (MetalnosX @ Nov 17 2009, 10:19 PM) *
Well im using VX and the problem is in VX not XP so yeah.


This tutorial is for XP, so using $game_actors[id] will solve your current problem, but in general XP scripts are not compatible with VX.


__________________________
`
Give me teh codez!!!


I am the master debator!
Go to the top of the page
 
+Quote Post
   
MetalnosX
post Nov 18 2009, 10:13 PM
Post #7


Level 2
Group Icon

Group: Member
Posts: 27
Type: Developer
RM Skill: Intermediate




QUOTE (BigEd781 @ Nov 18 2009, 06:58 PM) *
QUOTE (MetalnosX @ Nov 17 2009, 10:19 PM) *
Well im using VX and the problem is in VX not XP so yeah.


This tutorial is for XP, so using $game_actors[id] will solve your current problem, but in general XP scripts are not compatible with VX.

Yeah i think your right. I have alot of problems right now with this XP script. So should i wait until there is a RGSS2 Script tutorial like this or should i try to change to my script to be able to work on VX?


__________________________
[/size][/color]Ahhhhhh!...AHH!....AHHHH! Madman hitting me with oranges!! ....... Oh?... Is that my brother?[size="6"][color="#FF0000"] Man i cant do this lol
Go to the top of the page
 
+Quote Post
   

Posts in this topic
- The Law G14   [Scripting]Advanced Windows   Nov 14 2009, 04:41 PM
- - The Law G14   Updated the tutorial a bit. And also....over 30 vi...   Nov 15 2009, 02:14 PM
- - Holder   I've got quite a bit of catching up to do, Pre...   Nov 15 2009, 02:19 PM
- - The Law G14   Ah, thanks Holder Yeah, it's probably becaus...   Nov 15 2009, 02:47 PM
- - crimson_plague101   well here is my homework law i done the best i cou...   Nov 15 2009, 07:49 PM
- - lato22   Hmm very interesting, its always good to get more ...   Nov 15 2009, 09:59 PM
- - MetalnosX   Hello! Anyway can this tutorial work on RPG Ma...   Nov 15 2009, 10:13 PM
- - MentalSickness   This tut really helped me ^^ But, a problem O: I t...   Nov 16 2009, 09:02 AM
- - The Law G14   @Crimson: The first screen is very exellent, glad ...   Nov 16 2009, 01:29 PM
- - BigEd781   Very nice tutorial, you obviously put a lot of tho...   Nov 16 2009, 01:38 PM
- - The Law G14   Hey, BigEd, your that great scripter, nice to meet...   Nov 16 2009, 01:52 PM
|- - BigEd781   QUOTE (The Law G14 @ Nov 16 2009, 01:52 P...   Nov 16 2009, 02:03 PM
- - The Law G14   Thanks for all the help BigEd, I think I fully und...   Nov 16 2009, 02:49 PM
- - MetalnosX   Okay here is one of my problems: Look at my Attac...   Nov 16 2009, 09:11 PM
- - MentalSickness   QUOTE @MentalSickness: What version of rmxp do you...   Nov 17 2009, 10:14 AM
- - The Law G14   @MtealnosX: After the line of your script that say...   Nov 17 2009, 01:28 PM
- - MentalSickness   QUOTE (The Law G14 @ Nov 17 2009, 02:28 P...   Nov 18 2009, 04:51 AM
- - The Law G14   @MetalnosX: Did you look at my last post because I...   Nov 18 2009, 01:20 PM
- - MentalSickness   QUOTE (The Law G14 @ Nov 18 2009, 01:20 P...   Nov 19 2009, 04:13 AM
- - The Law G14   @MetalnosX: I'll say it again since you keep l...   Nov 19 2009, 01:38 PM
|- - MetalnosX   QUOTE (The Law G14 @ Nov 20 2009, 08:38 A...   Nov 20 2009, 08:05 PM
- - MentalSickness   QUOTE (The Law G14 @ Nov 19 2009, 02:38 P...   Nov 20 2009, 06:56 AM
- - The Law G14   Well you did great I love the fact that you put ...   Nov 20 2009, 01:55 PM
|- - MentalSickness   QUOTE (The Law G14 @ Nov 20 2009, 01:55 P...   Nov 21 2009, 08:26 AM
- - The Law G14   Yeah, you would have to edit the preexisting code ...   Nov 21 2009, 08:38 AM
- - MentalSickness   Ooo, that's nice Thanks ^^ EDIT: Umm.. I gue...   Nov 21 2009, 09:29 AM
- - The Law G14   lol, try this: CODE def draw_actor_class(acto...   Nov 21 2009, 11:26 AM
- - Rukiri   I thought about switching back to XP for my RPG(si...   Nov 27 2009, 03:19 PM
- - Bio Wolfz   Going to try out this tutorial tomorrow it looks i...   Nov 28 2009, 05:43 AM
- - Red Knight   ... Finished.. I was one slow guy with this one...   Dec 5 2009, 07:55 PM
- - The Law G14   @Rukiri and BioWolfz: Thanks guys, I'm glad yo...   Dec 7 2009, 01:57 PM
- - Red Knight   Thanks for the suggestion, I forgot all about the ...   Dec 8 2009, 07:01 PM
- - The Law G14   Much better, looks great Red Knight   Dec 9 2009, 02:46 PM
- - runefreak   This is really nice, I'll try it out now. Tha...   Dec 9 2009, 07:36 PM
- - Redd   Um i'm having a bit of an issue here. Whenever...   Dec 10 2009, 12:14 PM
- - The Law G14   Are you sure that you made your event also dispose...   Dec 10 2009, 01:45 PM
- - Redd   I didn't make it dispose of anything. I didn...   Dec 10 2009, 04:10 PM
- - The Law G14   Hey, sorry for the late response, kept forgetting ...   Dec 13 2009, 06:17 PM
- - Redd   That's what the common event looks like. It tu...   Dec 13 2009, 06:23 PM
- - The Law G14   Ah, I see the problem. You're event should loo...   Dec 14 2009, 01:36 PM
- - Redd   But I don't want them to dispose. I added that...   Dec 14 2009, 04:16 PM
- - The Law G14   Then it should look like this: CODE$window1 ...   Dec 14 2009, 04:34 PM
- - Redd   Even though I do have it like that, it still takes...   Dec 16 2009, 02:58 PM
- - The Law G14   Do you want the first and second windows to go awa...   Dec 16 2009, 06:46 PM
- - Redd   Exactly!   Dec 18 2009, 08:10 AM
- - Night5h4d3   Who say a scripter cant post homework? XD I alway...   Dec 18 2009, 11:35 AM
- - The Law G14   @Redd: Alright, I think I get it now, can you show...   Dec 18 2009, 03:57 PM
- - Redd   What it does is you click on the dude which turns ...   Dec 19 2009, 06:05 PM
- - The Law G14   Alright, I think I figured it all out. First of al...   Dec 19 2009, 07:43 PM


Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 

Lo-Fi Version Time is now: 19th May 2013 - 12:21 AM
RPG RPG Revolution is an Privacy Policy and Legal
eXTReMe Tracker