Submit Your Article


 
RPG Maker

Welcome Guest ( Log In | Register )


  Games Resources RPG Maker VX RPG Maker XP Scripts Tutorials Downloads

> [Series][Scripting]Basic Windows - Error, A tutorial from the Script Builders
Night5h4d3
post Oct 27 2009, 09:14 AM
Post #1


The past tense
Group Icon

Group: +Gold Member
Posts: 1,199
Type: Scripter
RM Skill: Undisclosed




The Script Builders' Tutorials:
----Lesson 1-1: ERROR: Basic Windows----


I. Introduction
II. The Birth of Error
III. ERROR is Seen
IV. Homework review
V. SCOPE
VI. Back to homework review
VII. Conclusion
IIX. Homework


I. Introduction

Hey everyone, This is another tutorial from the Script Builders. So far you know basically how to create a window with text, but as we all know, you cant turn back to law's first tutorial every time you want to create a custom window. And when you don't do things EXACTLY like your told (which if you did would result in very cheesy script outputs), you allow room for error. And that's where I come in, I will dive into the process of finding/tracking/resolving errors.

II. The Birth of Error

Stories are great, right? Well laws story on Window is very good, and I'll tell errors in a story nutshell too. Y'see, Mrs. Syntax wasn't Completely faithful to her husband Window. In fact, Syntax was married to several husbands, most of which I will not mention. Syntax also had a nasty secret(I don't mean that you perv. XP), She had cancer. It only showed up sometimes, but it was there none-the-less. and her cancer was contagious, in fact, even her husbands got the cancer. A doctor diagnosed this new-found cancer and called it Error. And it is error that haunts every aspect of Syntax. But do you know what else the doctor found out? It was found out that Error was treatable, even though it would never disappear. Don't believe me? I have proof.

III. ERROR is Seen

Open up an empty rmxp project and press F11 to open up the script editor. Create a new script below Scene_Debug and above Main. Type this:

CODE
class ERROR
  def error

  end
en



woah, woah, SyntaxError occurred? I told you Syntax had a sickness, and when it's prominent, only you can fix it. THANKFULLY the doctor built this device to detect exactly where Error is, and that's your ticket to curing syntax. Let's disect this picture.

Script 'ERROR' <- that means that the script at fault is named ERROR
line 5: <- okay, so it's talking about line 5, what's up with it?
SyntaxError occured <- woah, wait, does that mean that the error is on line 5 of the script 'ERROR?' yes it does.

let's check out line 5:
CODE
en

oops, looks like we forgot the 'd' to make the line 'end'

IV. Homework Review

Yeah, you remember it right? Your homework from law's first tutorial? We're going to check it out.
So I wanted to do this, but it's not working for me

CODE

#==============================================================================
# ** Window_Word
#------------------------------------------------------------------------------
#  This class displays text in a window.
#==============================================================================

class Window_Word
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize
    super(x, y, width, height
    self.contents = Bitmap.new(width - 32, height - 32)
    refresh
  end
  #--------------------------------------------------------------------------
  # * Refresh
  #--------------------------------------------------------------------------
  def refresh
    self.contentsclear
    self.contents.draw_text(0 0, 100, 100, "Hello World")
    self.contents.font.color = system_color
    self.contents.draw_text(150, 0, 100, 100, "I Feel")
    self.contents.font.color = knockout_color
    self.contents.draw_text(300, 0, 100, 100, So Great")
    self.contents.font.color = crisis_color
    self.contents.draw_text(450, 0, 100, 100, "Error Free?")
end


You try it, put that in your script editor where our first error was and try it out. Don't forget to use an event to call it. you've seen how in law's topic, but I'll show you again.
CODE
@>Script: $window = Window_Word.new
@>Wait: 40 frame(s)
@>Script: $window.dispose
@>


now load the project! What?! Not working? What's that? another error?



Okay, line 13, do-de-do, what?! line 13 is perfectly fine! I bet your stumped now, right? What now? This is where I teach you one great rule: "when you get an error on line N check the line(s) before line N" OKAY, let's start checking line 12!
CODE
super                <- yeah, that's spelled right,
(                                  <- yes, there's a parenthesis
x, y, width, height       <- separated by commas, yes
                                   <- woah, we forgot the closing parenthesis!

looks like we've found the error, let's fix that by adding ) and test again. WAAAAAH! another error!



line 21, let's check that out!
CODE
self.contents.draw_text(0 0, 100, 100, "Hello World")

looks fine...
DON'T READ UNTIL I SAY
it is not fine, but we supposed you over-looked it.

But wait, do you remember the great rule? check the line(s) before!
CODE
self.contentsclear


self.contents, oh! we forgot the . to separate 'contents' from 'clear' FIX! Maybe it'll work this time?
Still bugging, same line...WHAT NOW?! I'd like to say I am sorry, you are just not fit to script.
Nah, anyone can learn this, It's time for the second great rule "When you get an error on line N check the line(s) after line N" Haha, that's easy.
CODE
self.contents.font.color = system_color

clean
CODE
self.contents.draw_text(150, 0, 100, 100, "I Feel")

SAFE!
CODE
self.contents.font.color = knockout_color

clear!
CODE
self.contents.draw_text(300, 0, 100, 100, So Great")

something feels wrong here, it has the . it has ( and ) and is separated by commas. Wait wait wait! Only one " that's unbalanced. every other text has " and " (this is the law of balance, in syntax, most special characters have to be paired, ex: "" '' () [] {} thus, an opening should always be paired with a closing.) let's add the opening " right before the text So Great.
Okay, this is all great, I'm fixing lots of errors, but I'm still getting the error! let's look at the big picture. the big picture is something called SCOPE I'm going to take out some time to talk about Scope

V. SCOPE

scope, it's simple, and the law of balance is part of it. (the scope of these words is within the parenthesis) "the scope of this spoken word is within these quotes" sometimes you'll encounter multiple scope, think of this as climbing steps to go into scope, and going down steps to exit scope.
QUOTE
"I'm telling you now that he said 'I will not say 'blah blah blah.''"

the scope of this goes:
I open with spoken word " "
I quote someone's words ' '
the person i quote is quoting another phrase ' '

simple, right? if I go into 3 scopes, i need to exit 3 scopes. No more no less.

how does this relate to syntax? other than " " and ( )? In syntax, there are more than those scope 'increments.' 'class' and 'def' for example, are openings, and end is a closing. let's think this through:

class syntax phrase1 def syntax phrase2 end def syntax phrase3 end end

I have 3 openers (1 class and 2 def's)
so I need 3 closers (3 end's)

VI. Back to homework review

did you understand scope? good if you did, because a majority of errors are based on scope problems. (in fact, 2 out of the 3 errors we fixed on my homework were scope related)
so, let's now apply the law of balance while searching after the error line. the best way to do this is to gut out any contents that are within the scope like so:

CODE
class Window_Word
  def initialize
  end
  def refresh
end


NOTE: THIS DON'T FORGET TO USE SCOPE SPACING, IT DOESN'T CHANGE THE SCRIPT, BUT IT MAKES IT EASIER TO FIND/FIX ERRORS

as you can see, there's
1class + 1def = 2scope
2scope - 1end = 1scope
1scope + 1def = 2scope
2scope - 1end = 1scope

unfortunately we still are in one scope, how do we fix that? we add the end to where it is needed!
currently, the program thinks we're working like this: [ () ( ] we're missing a closing, so we need to add it to where it's needed, in this case, the end of the script. Time to test again! Okay, this is getting tiring, same error, same line, even after we've found all these bugs and learned all this stuff. You're probably thinking 'this guy's a quack' or 'you are bad at scripting' problems like these occur often. I guess we need to look at that line again. you may now read that spoiler!
yup, that's right, often people over look mistakes that are hidden in plain sight.

CODE
self.contents.draw_text(0 0, 100, 100, "Hello World")

what's missing? you already know right? it's that comma!
CODE
self.contents.draw_text(0, 0, 100, 100, "Hello World")

there, that looks much better, now we test again. okay! we've gotten to the title screen, let's check if the window displays!



uh oh! now that's one confusing error! oh yeah! we need to specify what x, y, width and height's values are! of course, there's two ways to do that, but for now, we'll use the way that law taught you. replace the 4 variables with 0, 320, 640, 160
(by the way: a name error is when something is called that hasn't been created. Such as, I cannot call a phone number that isn't activated.)

now let's test again. (getting redundant? you'll get faster the longer you do it)



ArguementError that's not something easy to fix. there are many possible reasons, but only one answer.
what is the command that's producing the error? 'super' you know what 'super' does right? it calls the def that it inherits, wait a minute!
CODE
class Window_Word

this class doesn't inherit! now that wont work, you cant call the inheritor if it doesn't inherit! remember in law's tutorial how his script inherited Window_Base? my script is supposed to be the same structure as his, so it needs to inherit Window_Base also! How do we make it do that? by adding:
< Window_Base
to make it
CODE
class Window_Word < Window_Base

now we test again, and..



woo! it worked!

VII. Conclusion

I hope I haven't completely confuzzled you, troubleshooting is a hard thing. But I do believe that you can learn to master it. There is absolutely nothing more satisfying in the world of RGSS(2) than to see a script you put effort into work. I thank you for taking the time to read my tutorial. and If you want to prove your new-found talent, try out the homework biggrin.gif

IIX. Homework

Fix this script and show me a screenshot of the output (in spoilers please, don't worry, the errors wont occur in situations different than the ones encountered today):

fix me!

#==============================================================================
# ** Err
#------------------------------------------------------------------------------
# Your homework is to fix this script and show the output.
#==============================================================================
NUMBER_ARRAY = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]

class Window_Word Window_Base
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize
super(0 0 640 160)
push_output
self.contents = Bitmap.new(width - 32, height - 32)
refresh
end
#--------------------------------------------------------------------------
# * Number output
#--------------------------------------------------------------------------
def push_output
$output_array = []
$output_array.push(NUMBER_ARRAY[2], ".", NUMBER_ARRAY[0], NUMBER_ARRAY[3],
NUMBER_ARRAY[0], NUMBER_ARRAY[4], NUMBER_ARRAY[8], NUMBER_ARRAY[1])
#--------------------------------------------------------------------------
# * Refresh
#--------------------------------------------------------------------------
def refresh
self.contents.clear
self.contents.draw_text(0, 0 100, 100, $output_array.to_s)
self.contents draw_text(150, 0, 200, 100, "Congrats, Now")
self.contents draw_text(300, 0, 100, 100, "Show Me A")
self.contents.draw_text 450, 0, 200, 100, "Screenshot of this!"")
end
end
end


__________________________
Got 30 minutes? Then you've enough time to play this awesome game:

- potentially promising project page
- thanks holder
My growing space of user-bars:

about me:







I made the following!





Go to the top of the page
 
+Quote Post
   
 
Start new topic
Replies
crimson_plague10...
post Nov 13 2009, 09:04 PM
Post #2


Level 2
Group Icon

Group: Member
Posts: 22
Type: Developer
RM Skill: Beginner




here is my homework



Attached File(s)
Attached File  homework.png ( 61.71K ) Number of downloads: 10
 
Go to the top of the page
 
+Quote Post
   



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: 18th May 2013 - 11:15 AM
RPG RPG Revolution is an Privacy Policy and Legal
eXTReMe Tracker