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]Errors and their meanings, A tutorial from the script builders
understandability
You cannot see the results of the poll until you have voted. Please login and cast your vote to see the results of this poll.
Total Votes: 11
Guests cannot vote 
Night5h4d3
post Dec 18 2009, 10:28 AM
Post #1


The past tense
Group Icon

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




The Script Builders' Tutorials:
----Lesson 5: Errors and Their Meanings----


I. Introduction
II. Standard Errors
III. Undefinition Errors
IV. Conclusion & EXTRAS
V. Homework


I. Introduction
Welcome back, if your reading this, you probably lived through my first tutorial. Unfortunately, this tutorial should probably have come before the first, and I will attempt not to make such mistakes again. I also want to make this as simple as possible without sounding so easy that you skip parts. You know what errors are, and you know how to find them. What this tutorial will teach you is how to decipher the error messages and make fixes (without my help, and without other people's help). When helping decipher errors, they will be explained in this format:
CODE
[b]Name[/b]
[b]Format: {"blah blah blah"}[/b]
[b]English[/b]
[b]Best Way to Fix[/b]



II. Standard Errors
Standard Errors, these are the errors are quite common (okay, sarcasm aside..). They consist of 80% to 90% of the errors you'll encounter. For the most part, they're easy to resolve. let's start from the top..

Argument error
Format: {wrong number of arguments(n for n)}
English: basically, for this one, you've given too many/few 'arguments.' In simpler terms, supposing that when I tell you to draw a rectangle, I tell you how HIGH I want it, and then tell you how WIDE I want it.. What would you do If I said, draw a rectangle with the dimensions of 3 inches, 2 inches, 1 inch. Well, if you were a computer, you'd tell me this: wrong number of arguments(3 for 2). You're asking for 2 arguments (width and height) and I'm giving you three (normal people like you would probably write me off as a crazy person..)
Best Way to Fix: Read the format, (n for n) the first number is how many your giving, the second, how many it wants. remove the extra numbers and double check that only the numbers you want to keep are there.
(IE: when calling: "draw_actor_graphic(actor, x, y)" provide those three arguments and no more/less. If you've provided (actor, x, y, height), don't remove 'actor/x/y.' Rather, remove 'height')

SystemStackError
Format: {stack level too deep}
English: this mostly occurs with aliasing. I actually haven't seen it occur otherwise, it just means that a def is being 'alias'ed too many times, the problem occurs when 1) using two scripts that alias the same class/def (IE: mixing two different custom message systems) 2) when you press F12 and you have a script that has an alias (for this there are F12 fix script snippets) or 3) when you alias a def within itself:
CODE
class Scene_Menu
   def initialize(menu_index = 0)
    alias initialize_new_scene_menu initialize
    initialize_new_scene_menu
    @menu_index += 1
  end
end

Best Way to Fix: There's several ways to fix this, for 1) either remove one script or have them merged (NOTE: sometimes merging scripts is impossible) 2) use a F12 fix snippet, or just don't alias, write directly into the original class or write a new class (actually, 90% of the time I do not alias methods, they're less prone to stack errors this way, although, some(and even maybe you) might consider this unwieldy, and 'roundabout') 3) either don't alias, or alias BEFORE the def.

Type Error
Format: {String can't be coerced into Bignum/Fixnum/Float | cannot convert Bignum/Fixnum/Float into String}
English: In simpler terms, your trying to work with both numbers and text at the same time.. of course. if I gave you the numbers: 123456789123456786789 and told you to add "some numbers" to that, you'd say "123456789123456786789 some numbers." However, this is not the same when working with a script, you cant add a string to the end of some numbers, or vice versa. thus, if you wish to add string to numbers, or numbers to string, you must first convert the numbers into a string.
Best Way to Fix: if you meant to have numbers in a string, then convert them. (if you didn't mean to have them a string, correct that problem)
CODE
$BIGNUM_HERE = 12345678902345678901234567890
$STRING_HERE = "< some numbers"
$NEW_STRING = $BIGNUM_HERE.to_s + $STRING_HERE
print($NEW_STRING)

SEE 'Conclusion & EXTRAS' for help on understanding fixnum/bignum

Runtime Error
Format: {Runtime Error occured}
English: this happens when some of you get a little too ambitious and decide to setup exception raising. (which, don't get me wrong, doing such is a great thing) supposing I decide I want to start debugging, I add a raise to my script:
CODE
if @raise_me != nil
  print("i give you life")
else
  raise
end

and so you get the runtime error, you could try fixing it by adding ("message here") but even though it displays the message, you still get a runtime error. This is because your forgetting to create an 'exception' first. Runtime errors aren't harmful, and usually require less coding than creating an exception, but for newbie or novice scripters who don't know, they'll easily get confused.
Best Way to Fix: first create an exception, you can do it prior, or during the error. this way is how to do it prior:
CODE
$nil_var_E = Exception.new("the variable referenced here is nil!")

and
CODE
raise($nil_var_E)

during:
CODE
if @raise_me == nil
  raise(Exception.new("the variable referenced here is nil!"))  
else
  print("I give you life")
end


ZeroDivisionError
Format: {Divided by 0}
English: really? do you need any more description on this? this problem occurs when you divide by zero.
(by the way, every time you divide by zero you create a black hole somewhere in the universe.. so don't.. (just kidding, but to be safe, don't divide by zero..))
Best Way to Fix: make sure you don't divide by zero, simple as that, and if you have a number that for some reason ranges from 0~3 or something like that, increment it prior to division.
CODE
$var_that_has_zero += 1



III. Un-definition Errors
There's not many of these errors, but I'll still try to cover them as simply as possible. These are the errors that occur when you fail to define something, whether it be a variable, or a class, a module, a def, anything. Basically put, it's like me asking you to tell me how many apples there are right now. You could never know right now, because I haven't defined how many there are. If I say the number of apples is the same as the number of oranges plus the number of pears minus two, you still don't know, and you don't know the number of oranges or pears. But if I said there were ten oranges, and three pears it'd be easy to tell me that the number of apples is eleven.

Name Error
Format: {Name error Uninitialized constant <>}
English: This usually only happens when your trying to work with nil constants. (variables usually with no @ or $ and in all caps LIKE_THIS) such as "UBER_NIL += TOTALY_UNDEF" will result in an a Name Error. It basically means you haven't defined the variable, or in better words, the program is saying this: 'this constant is still nil, how the heck do you expect me to add it to, what the? another nil constant?! nil + nil = undefined, bleargh, error!'
Best Way to Fix: make sure all constants are defined (non-nil), or that you don't try adding/subtracting/doing anything with them (other than comparing them like == or !=). And make sure the names are the same. (ABS::BAR_COLOR can go mistyped and unnoticed as ABS::BAR_COLLOR)

NoMethodError
Format: {NoMethodError occured. undefined method '<method>' for <module/class/nil>:<class/def/NilClass>}
English: remember the problem with apples? well, if I told you "function 'add'" to the 'variable' apples, you'd assume the amount of apples were 0, and count up/down by how many i told you to add/subtract. However, such is not the logic with RGSS, it would assume the number of apples were nil (nil is hard to 'contemplate' because we live in a non-nil world.). it would give you an error, probably "undefined method '+' for nil:NilClass" and you'll be wondering why. not any more, you now know that it's either because your trying to run a method on a nil variable. OR your trying to call a nil(non-existent) method. (IE: $scene.gimme_pie doesn't work, UNLESS you happened to create a 'def' in that scene named gimme_pie)
Best Way to Fix: make sure whatever your trying to operate on isn't nil, and make sure that the method your trying to call exists. By calling 'draw_atcor_name' instead of 'draw_actor_name' (a simple typo) you can cause this error.


IV. Conclusion & EXTRAS
There's one more kind of error you'll most likely encounter. It's the most annoying one ever, the 'syntax error' unfortunately, I could write a book explaining the ways you can encounter this. but I'm not going to. some things are best learned by trial and error. writing en instead of end, Class instead of class, not closing quotation marks, putting one too many 'end's or one too few end's, writing sel. instead of self. hitting 0 without pressing shift to write ), these are just a few of the many ways to encounter a syntax error. But with time, and knowledge how to decipher these error messages, you can find and fix the problems.
I hope you managed to survive through this, it came out a little more difficult than I wanted it to be. for those of you who survived this tutorial, great! if you didn't manage to get it all, that's okay too, all of these errors can be explained logically in 'human' terms. If you have any questions, I'd like to hear them, and I'll try to help as soon as possible.
About bignum/fixnum. you generally don't need to worry about these, but in case your curious, a fixnum should be any number between -2,147,483,648 to 4,294,967,295 and when it goes out of those bounds, it becomes a bignum, so 1 billion is a fixum, but 7 billion is a bignum. if that helps. generally, all numbers you'll work with should be fixnums, unless your doing some serious crunching in your game.

V. Homework
Is that a grin I see? Or are you frowning while doing a hand-stand? I was going to give you a whole class to fix.. but I decided on an alternative.
This def I'm about to give you contains several errors, I don't want you to fix it. I don't want you to even plug it into your script editor. in fact, if you do so your considered cheating, and while I'm not there to watch if you cheat or not, your the one who'll suffer with not being able to recognize errors as well. I want you to tell me which TYPE of errors occur where and why. (if you cant get them all, then just submit what you think are the ones.) for example,
CODE
alias main_new main
main_new

Will result in a stack error, why? because I've aliased a def while inside the def I'm aliasing. see? wasn't that easy? You don't even need to tell me how to fix it. (here's the script, and don't go off cheating/comparing how it looks to the original.)

Your Homework
def main
@my_var = 4
alias main_new main
main_new
s1 = $data_system.words.item
s2 = $data_system.words.skill
s3 = $data_system.words.equip
s4 = "Status
s5 = "Save"
s6 = "End Game"
@command_window = Window_Command.new(160)
@command_window.index = @menu_index
if $game_party.actors.size == 0
@command_window.disable_item(0)
@command_window.disable_item(1)
@command_window.disable_item(2)
@command_window.disable_item(3)
end
if $game_system.save_disabled
@command_window.disable_item(4
end
end
@playtime_window = Window_PlayTime.new(0,244)
@playtime_window.x = 0
@playtime_window.y = 224
@playtime_window.y += "y pos"
@steps_window = Window_Steps.new
@steps_window.x = 0
@steps_window.y = 320
@gold_window = Window_Gold.new
@gold_window.x = 0
@gold_window.y = 416
@status_window = Window_MenuStatus.new
@status_window.x = 160
@status_window.y = 0
@my_var /= @playtime_window.x
Graphics.transition
loop do
Graphics.update
Input.update
Update
if $scene != self
break
end
end
Graphics.freeze
@command_window.dispose
@playtime_window.dispose
@steps_window.dispose
@gold_window.dispose
@status_window.dispose
@player_status.dispose
end


(try putting your answers in spoilers, so you don't spoil them for other people)


__________________________
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
   
MentalSickness
post Dec 20 2009, 03:16 AM
Post #2


Level 2
Group Icon

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




Okay, I found some problems, and I'm pretty sure I missed some O:
But, worths a shot biggrin.gif

[Show/Hide] Error #1
CODE
alias main_new main
main_new--- You already said what's the problem with this in the tut

[Show/Hide] Error #2
CODE
@command_window = Window_Command.new(160)--- Supposed to be (160, [s1, s2, s3, s4, s5, s6])
Argument Error

[Show/Hide] Error #3
CODE
s4 = "Status--- Needs another " in the end
NoMethod Error

[Show/Hide] Error #4
CODE
@command_window.disable_item(4--- Needs ")" in the end
NoMethod Error

[Show/Hide] Error #5
CODE
@playtime_window = Window_PlayTime.new(0,244)--- Doesn't need the (0,244)
Argument Error

[Show/Hide] Error #6
CODE
Update--- Supposed to be "update", not sure if it causes an error though ><
NoMethod Error

[Show/Hide] Error #7
CODE
@player_status.dispose--- There isn't a @player_status window
Un-definition Error


Did I get it right? biggrin.gif

This post has been edited by MentalSickness: Dec 21 2009, 10:45 AM
Go to the top of the page
 
+Quote Post
   
Night5h4d3
post Dec 20 2009, 03:48 PM
Post #3


The past tense
Group Icon

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




#5 is incorrect, it doesnt 'need' a space.
you missed these:

@my_var /= @playtime_window.x
zero division error
--------
@playtime_window = Window_PlayTime.new(0,244)
argument error (2 for 0)
-------
@playtime_window.y += "y pos"
cannot coerce fixnum to string


You did a great job on FINDING/FIXING the errors, however.. I asked you to name what errors occurred. no worries though XD.
IE:
CODE
alias main_new main
main_new

results in a 'stack error'


__________________________
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
   
MentalSickness
post Dec 21 2009, 10:38 AM
Post #4


Level 2
Group Icon

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




Yay ^^
And about
@my_var /= @playtime_window.x
zero division error

I thought it was an error, but I wasn"t sure "^^
And about naming the errors.. I forgot about that XD
I'll edit my previous post with the naming :]

EDIT:
I edited my previous comment with the errors, feel free to tell me if I'm right biggrin.gif

This post has been edited by MentalSickness: Dec 21 2009, 10:46 AM
Go to the top of the page
 
+Quote Post
   
Night5h4d3
post Dec 21 2009, 11:21 AM
Post #5


The past tense
Group Icon

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




nice job!

[Show/Hide] you only missed these
3) syntax error
4) syntax error
7) NoMethodError
a word future reference, if it isnt an obvious error, like forgetting ' or ) then it's a syntax error


__________________________
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
   
MentalSickness
post Dec 22 2009, 02:07 AM
Post #6


Level 2
Group Icon

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




Thank you :]
And about syntax, I forgot about that, so I searched in the errors that you mentioned "^^
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: 19th June 2013 - 04:54 AM
RPG RPG Revolution is an Privacy Policy and Legal
eXTReMe Tracker