Submit Your Article


 
RPG Maker

Welcome Guest ( Log In | Register )


  Games Resources RPG Maker VX RPG Maker XP Scripts Tutorials Downloads

 
Reply to this topicStart new topic
> [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
   
The Law G14
post Oct 27 2009, 12:36 PM
Post #2


Scripter FTW
Group Icon

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




Woah, this tutorial is great, nice work NightShade biggrin.gif Hopefully people will turn in their homework sometime. I'll try turning mine in soon if you don't mind lol


__________________________

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
   
Night_Runner
post Oct 27 2009, 02:56 PM
Post #3


Level 50
Group Icon

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




You're really good at this Night smile.gif


__________________________
K.I.S.S.
Want help with your scripting problems? Upload a demo! Or at the very least; provide links to the scripts in question.

Most important guide ever: Newbie's Guide to Switches
Go to the top of the page
 
+Quote Post
   
Night5h4d3
post Oct 28 2009, 04:39 AM
Post #4


The past tense
Group Icon

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




good at teaching to solve errors, or good at screwing up scripts for others to fix? XP nice job night-runner. (you might want to put it in a spoiler)

Anyone else up for the challenge?


__________________________
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
   
dummy1234
post Nov 1 2009, 05:20 AM
Post #5


Level 8
Group Icon

Group: Revolutionary
Posts: 128
Type: Developer
RM Skill: Skilled




Nice tutorial ^^
[Show/Hide] Homework screenshot


__________________________
Given the choice - whether to rule a corrupt and failing empire, or to challenge the Fates for another throw, a better throw against one's destiny - what was a king to do?
Go to the top of the page
 
+Quote Post
   
crimson_plague10...
post Nov 13 2009, 09:04 PM
Post #6


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
   
DarkKnight89
post Nov 20 2009, 10:57 AM
Post #7



Group Icon

Group: Member
Posts: 2
Type: None
RM Skill: Beginner




i had issues but they are now solved, just my own dim witted mistake while writing the event script

[Show/Hide] heres my hw




This post has been edited by DarkKnight89: Nov 21 2009, 02:58 PM
Go to the top of the page
 
+Quote Post
   
Red Knight
post Dec 1 2009, 05:59 PM
Post #8


Level 1
Group Icon

Group: Member
Posts: 12
Type: Scripter
RM Skill: Beginner





That was easy. Just like a jigsaw. Piecing it together was easy.


__________________________
...Rain...Washes...Away...All...The...Blood...
Go to the top of the page
 
+Quote Post
   
Legacy
post Dec 1 2009, 08:02 PM
Post #9


B★RS Coding Ninja
Group Icon

Group: Global Mod
Posts: 1,414
Type: Scripter
RM Skill: Advanced
Rev Points: 15




Nice work, althought it was fairly easy for me to begin with, im sure this is going to help allot of people out there. Keep up the great work you've been doing.

Cant wait to see your next tutorial biggrin.gif

This post has been edited by LegacyX: Dec 1 2009, 08:02 PM


__________________________
Freelance Programmer (C#, C++, Ruby)
#onegameamonth


Have you seen the new Unity3D sections?..
Unity 3D Discussion
Unity Script Development
Unity Projects
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: 22nd May 2013 - 05:50 PM
RPG RPG Revolution is an Privacy Policy and Legal
eXTReMe Tracker