91
General Discussion / Re: making video games, where do you start?, how do you stay focus?
« on: August 02, 2008, 09:22:44 am »
Next short installment: Errors in your program
What's with errors? Evey high level programming language has some rules you have to follow for it to understand what you want it to do. Those rules are called the "syntax" of that program. If you don't stick to those rules, the programing language will not understand what you want it to do, or worse, in some cases, misunderstand what you want it to do. If the high level programming language really doesn't understand what you want it to do, it will stop running your program and give you an error message.
You can try it by making a program1.rb that contains just of this
a = 10 +
and run it (with F5 or Tools/go, remember) and this is what you'll get
program1.rb:1: syntax error, unexpected $end
a = 10 +
In other words, the programming language is complaining about the "syntax", that is, you are not following the rules. you want to store a sum into a but the sum of 10 and what? So the programming language just gives up and says: hey, you made an error there, on line 1 of your program. I'm outta here!
Let's correct our program and run it again: change it to
a = 10 + 10
puts a
And run it, and you will see "20" in the output window. No errors, since you're following the rules of the Ruby language, so Ruby understands what you want it to do for you, and does it.
What's with errors? Evey high level programming language has some rules you have to follow for it to understand what you want it to do. Those rules are called the "syntax" of that program. If you don't stick to those rules, the programing language will not understand what you want it to do, or worse, in some cases, misunderstand what you want it to do. If the high level programming language really doesn't understand what you want it to do, it will stop running your program and give you an error message.
You can try it by making a program1.rb that contains just of this
a = 10 +
and run it (with F5 or Tools/go, remember) and this is what you'll get
program1.rb:1: syntax error, unexpected $end
a = 10 +
In other words, the programming language is complaining about the "syntax", that is, you are not following the rules. you want to store a sum into a but the sum of 10 and what? So the programming language just gives up and says: hey, you made an error there, on line 1 of your program. I'm outta here!
Let's correct our program and run it again: change it to
a = 10 + 10
puts a
And run it, and you will see "20" in the output window. No errors, since you're following the rules of the Ruby language, so Ruby understands what you want it to do for you, and does it.