1

For many people who use the bgt engine, they are newbies to scripting. The process of game creation can be an intimidating one, especially for those who do not realize the task that is ahead of them. Besides developing the game mechanics, finding sounds and/or music, and making documentation, the game has to be programmed, tested, debugged and tested again.

    Writing the code that makes the game can be the hardest part for many. Evidently, you will make mistakes. Even I make them. There are two major kinds of mistakes when programming, syntactical mistakes and logical mistakes.

  • syntactical mistakes are errors in the code that stop bgt from understanding your code. For example, calling a function with the wrong kinds of parameters. Bgt will either give you a compilation error when you try and run the game, or a runtime error if the game is already running, when it sees a syntactical mistake. In both cases, the program will close and it will be your job to fix the problem.

  • Logical mistakes do not stop bgt from running the game, but something will act oddly. For example, if you are making a sidescroller and you have defined pits, it is logical that if the player does not jump over the pit, he should fall into it. If he does not fall in, this is a logical mistake. Logical mistakes are often harder to correct than syntactical mistakes, especially for people who are novices to programming. These novices often copy example code without fully understanding what it does, and pay the price for it later. Understanding what the code does is integral to fixing logical mistakes.

Newbies to bgt are often put off by what seems like insurmountable compilation errors. But really, these errors are tremendously helpful when troubleshooting syntactical mistakes. BGT really makes a notable effort to point you in the right direction towards fixing the nitty-gritty so that you can get back to programming new features into your game. I'll attempt to cover some of the most common compilation errors and warnings you will receive from bgt, and strategies to fixing them and/or avoiding them in the future.
Remember, compilation errors always reference line numbers. Use your text editor's go to line feature to help narrow your search.

Expected "x", instead found "y"
  • Did you terminate your last statement with a semicolon? This is by far the biggest reason for this error. A lot of novices, as well as people who are transitioning from some other programming language, such as javascript, that doesn't require semicolons, get this error.

  • Too many closing parentheses? This is another common one for me. I often nest 2 or 3 function calls in a single statement and put an incorrect number of closing parentheses at the end. Wrong numbers of closed braces and quotes will be discussed later.

unexpected end of file

Anyone who's made a game in bgt knows and dreads this error. The main reason you get it is that you didn't close a brace in your code. Bgt will let you know where the unclosed brace is, which is a tremendous help. Go there and count your braces carefully. A useful technique is to comment out what you're closing so that you don't have to puzzle over it later. For example:

void main)
{
int x=4, y=7;
while(x<y)
{
if(x==6)
{
alert("","x is 6");
] //if
x++;
]//while
]//void main
unexpected token

This usually happens if you have too many closing braces, but you are not defining a class (see the next error if you are). Since you can't define an if statement outside a function, you often get "if" as the unexpected token, though you also often get "}" as the unexpected token. Either way, it means you over closed your brace.

expected method or property

Usually this error shows up if you close too many braces while defining a class method.

Expected expression value

This usually references the condition of an if, while, doWhile, or for statement. The error is usually pretty easy to spot and it's usually a typo, for example you use = instead of == to denote "is equal to".

non-terminated string literal

This one is one of the most annoying errors to receive if you don't test your code often. The main reason for the annoyance is that the line number that BGT shows you rarely is the culprit. The problem is always on a line above the referenced line, and there is no limit to how far up it could be. You usually get this error if you are concatonating strings and variables together and accidentally switch the plus sign and the quotation mark, or forget one of them. It is also possible that you simply forgot to close your opening quote, or you forgot an opening quote. If you forget both quotes and you haven't concatonated aynthing, you will get a message about something not being declared instead.

variable x is not declared

This is usually easy enough to fix. You either forgot to put quotes around a literal string, or just forgot to define a variable.

no matching signatures to and candidates are

When you call a function, bgt looks for a signature that matches the function name and parameters. A signature contains the function name, the types of variables of the parameters, and the return type. If you try and call an undefined function or call it with incorrect parameters, bgt will give you this error. If the name is defined but the parameters are wrong, it will tell you what parameters can be used.

not all paths return a value

This error fires when you define a function that returns a variable. The best thing to do is to make it return an empty variable, such as 0 if you are returning a numeric variable, an empty string if the return type is string, or null if you are returning an object handle. You can then return other things by using conditional expressions, and the compiler will be appeased too.

the subtype has no default factory

If you are creating an array of classes, it is wise to define a default constructor without parameters, even if you don't do anything in the constructor. Otherwise, you will get this error, and the information will not help you very much.

Warning: unreachable code

This will not hinder you from starting the game, but it is important to keep track of because it could explain why something you expect doesn't happen at runtime. Unreachable code is code that the compiler won't run because the execution was cut off somewhere above it. The most common ways to cut off line-by-line execution are break, continue and return. Code defined below these keywords will not be executed because the compiler was redirected somewhere else. For example, break terminates a loop, and moves execution on to the code defined right after the loop. Since your unreachable code is still in the loop, it is skipped.

warning: implicit conversion is not exact

This usually happens when you are shuffling integer and floating point variables around. Since integers are far less precise than floats, whenever you assign an integer variable to the value of a float, you lose a lot of precision, which can affect things such as testing for equality. For example:

int pi=3.1415926535;
double d_pi=3.1415926535;
if(pi==d_pi) alert("","pi is equal to pi!");

At first glance, you might think that you would get an alert. But you won't, because the value of the pi variable is actually 3, because it's an integer! that's why bgt warns you.

other compilation errors are far less common than the ones I've described above. If you get one of them, feel free to ask on the bgt forum, or create a topic in the development room, or even send me a pm.

I like to sleep, Sleep is good,
This is how I do it: Lie on a nice warm cozy bed, and dream dreams about how to rule the world!
Follow @TheGreatAthlon5 on twitter for humorous facts and game updates!
If you like my posts, thumb me up!

Thumbs up +2