Author Topic: Troubleshooting Your Designs  (Read 17295 times)

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Troubleshooting Your Designs
« on: June 28, 2011, 07:00:32 PM »
Troubleshooting Your Designs





1.  Introduction
2.  What have you just been working on?
3.  Finding error messages
4.  Analyse what your code is doing
5.  Comment out suspect parts
6.  Use Developer Mode
7.  Write down in words what your code ought to be doing
8.  Use the console to test values in-game
9.  Use a test MessageBox
10. Assign asteroid names to the values of your variables
11. Ask on the forums for help
12. Sleep on it








1. Introduction

So you made it through the beginners guide!  ...or maybe you didn't.  I can't possibly hope to cover every individual bug you might encounter, so instead I will cover the basic tools and techniques used to troubleshoot a map.

Understand that everyone gets bugs.  If you made it through all the examples in the beginners guide without a single bug along the way, you are definitely the exception rather than the rule!
Bugs are something you will constantly have to deal with, so it makes sense to get comfortable with troubleshooting them early on.



So.  You've got a bug.  Lets say for example your map doesn't load at all.  Where do you start?




2. What have you just been working on?

If you've just added 2 new lines of code, and now the level won't load anymore, the chances are high that the lines you just entered caused the problem.  Go and take another look at them.  Is there a typo?

Are you referring to any variables that haven't been assigned a value yet?  Did you use a dot instead of a colon or vice versa?  EG did you write GetAsteroid(0).AddSeedlings(100) instead of GetAsteroid(0):AddSeedlings(100)?  The difference is small but it can be sufficient to prevent the level from loading.

Look for common mistakes and correct any you find.




3. Finding error messages

Suppose your map won't load and you can't spot which part of your code is wrong.



Eufloria will typically give you an error message.  Read what this says!!  It will often give a number, this is the line number where the code causing the error is located so be sure to look for that.
If your text editor does not display line numbers, I suggest you download Notepad++.  It's free and awesome.

Eufloria will sometimes give you specific information about what caused the bug, sometimes even mentioning a specific variable that is causing the problem.  Then again, sometimes it does not give specific information, but is more generalised.

There are more error messages too - not just the popup error messages you see when your level fails to load.  Sometimes your level will load but stop working instantly, so any active scripting won't proceed.  In this case, you will probably be able to tell something is not right, but you have no clues as to what the problem is because the level managed to get past the initial loading, so there is no messagebox with the error message.

In this case, it's a good idea to check the console to look for the error message there.



The console is accessed by pressing the Tilde key.  (`)
The tilde key is the key to the left of "1" on most keyboards.


When you open the console, any recent error messages will be displayed there.  As with the above, it will sometimes be specific, other times general.. sometimes it mentions a line number, other times it does not.

Note: Occasionally an error message gets "stuck" in the console.  To check if there is a stuck error message, just type something into the console and press enter.  You can type anything you like, eg type in "fish" and press enter.  You should see an error message in response, because obviously Eufloria doesn't know any "fish" command...  if there was a stuck error message, you will also see this appear now.




4. Analyse what your code is doing

Try to think about all the possible values your variables might be assigned.  Will they ever run into a situation where a number is divided by zero?  If that case arises, you have a crash on your hands.



Try to spot logic flaws in your code.  If you have a condtional statement like "if x > y then", make sure that this condition is met when it's appropriate.  Think everything through, and take your time.  Avoid changing things randomly and hoping for the best - that almost never works.  Instead, work on your understanding of what is happening in the code, and let that guide your changes.




5. Comment out suspect parts

We covered commenting briefly in the Beginner's Guide.  If you put a double dash (--) at the start of a line, you "comment it out".  This means anything on that line written after the double-dashes will no longer be run and instead is just treated as a comment.
The aim of this troubleshooting approach is to comment out large sections of your code until you've stripped the level back to a state where it will load again.



Then, un-comment your code a few lines at a time until you discover the point where it no longer works.
This helps you to pinpoint which part of the code is causing the issue.




6. Use Developer Mode

Pressing CTRL-D during gameplay toggles Developer Mode on and off.
Once you have activated Developer Mode, you can use the Function keys F1-F12 to activate different useful functions.  F4 and F12 are the most useful ones.



Spend 2 minutes learning what these do, and your level designing will be that much easier going forward.




7. Write down in words what your code ought to be doing

Sometimes the simple act of writing things down helps you to realise where your code and your intentions differ.



Don't underestimate the usefulness of this exercise for both planning and troubleshooting!




8. Use the console to test values in-game

If your level loads but produces unexpected results, this can often be the best investigative tool.
Suppose you are trying to draw a line on the screen, and the line's location is to be based on the position of an asteroid.
Maybe you have an "angle" variable which is calculated, and then used in a subsequent calculation to figure out the coordinates of the line.

At certain points, you know that "angle" ought to be within a certain range.  For example, at the start of the level you expect (from your plans) that "angle" will have a value of about 50.

Test whether it really does have a value of 50!  Load up your level and open the console.
Then type the following: print (angle)
Press enter and the console will show the value of the "angle" variable.



Maybe it turns out to be 12484382834832483248324.12321 - then you KNOW something isn't right!  Time to study the way "angle" is being calculated...




9. Use a test MessageBox

Eufloria stops running your level code if it encounters an error.
It's possible to exploit this behaviour to see "how far through the code does it get before reaching the error?"
If you have a long section of code and you know at a certain point it is failing, try adding the following line at an opportune point:

Code: [Select]
MessageBox("Fish")
Now run the level.  If you see a Fish messagebox, you know that the code ran fine up until the message box....  so you know the code above it must be fine, and the code below must contain the error.  Go move the Fish command further down a bit, and then try again.  Repeat in this manner until you find the line that is causing the problem.






10. Assign asteroid names to the values of your variables

If you have a variable that you want to monitor closely during testing, one neat trick is to place a command like this inside your LevelLogic's While loop:

Code: [Select]
GetAsteroid(0).Name = MyVariable
Where "MyVariable" is the variable you want to monitor.
Now when the game is running, the name of the asteroid will constantly change to reflect the value of MyVariable.  This allows you to see the values fluctuating in real time while the code is running, and can help a great deal in spotting problems.




11. Ask on the forums for help

That's what we're here for!  You could be the greatest coder in the world, sometimes it just takes another pair of eyes to spot the problem.



When asking for help, please ALWAYS post the level file you are working on.  Don't just post the part of the code you think is causing the problem.  Maybe you don't think the other stuff is relevant but people - including me - have assumed that before, and then later discovered some of that "irrelevant" code was actually the root cause of the problem.  Learn from my mistake and just attach the whole .lua file.  :>




12. Sleep on it

Hey, soldier.  Been working on this for a while?

Is it 3am?



4am?

If it's really late and you've been working on this for ages, sometimes the best thing to do is to just call it a night and get some sleep.  When you wake up, your mind will be more focused, and last night's impossible barriers become mere toy puzzles in the face of your well-rested intellect.  Going to sleep is not giving up.. it's a tactical retreat.  :>
« Last Edit: June 29, 2011, 10:08:38 PM by annikk.exe »

Bonobo

  • Achiever
  • Old Oak
  • ****
  • Thank You
  • -Given: 139
  • -Receive: 12
  • Posts: 670
  • Eufloria: Yes
Re: Troubleshooting your designs
« Reply #1 on: June 28, 2011, 10:01:49 PM »
[..]
Going to sleep is not giving up.. it's a tactical retreat.
This is going to be a CLASSIC!

Aino

  • Ent
  • ******
  • Thank You
  • -Given: 4
  • -Receive: 30
  • Posts: 1,527
  • Eufloria: Yes
Re: Troubleshooting your designs
« Reply #2 on: June 28, 2011, 11:02:00 PM »
Finally :D

And sleeping on it works, just so you know... You clear up your minsd just as you go sleeping, after that yiou think and think untill you sleep, that's my case atleast :P

dragoonreas

  • Seedling
  • **
  • Thank You
  • -Given: 2
  • -Receive: 1
  • Posts: 37
  • Eufloria: Yes
Re: Troubleshooting your designs
« Reply #3 on: June 29, 2011, 12:04:55 AM »
I didn't actually know about the developer mode was until you talked about it recently in another thread, and it sounds really handy. I'll certainly be using it the next time I'm debugging & testing something.

The only suggestion I have to add to the guide would be to mention the print function, and maybe suggest using it instead of MessageBox in the "Use the console to test values in-game" section. This way the values you look up will be saved as output in the console so they can be referred to later, rather than just having them disappear when you close the message box.

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: Troubleshooting your designs
« Reply #4 on: June 29, 2011, 12:11:52 AM »
Hmmm yes that is a good idea.  It's not what I do, but it's probably a better habit to get new people into.. :>

Pilchard123

  • Tester
  • Old Oak
  • ****
  • Thank You
  • -Given: 4
  • -Receive: 24
  • Posts: 932
  • Eufloria: Yes
Re: Troubleshooting your designs
« Reply #5 on: June 29, 2011, 03:26:02 AM »
Sleep on it
Is it 3am?  Answer honestly... ;)
If it's really late and you've been at this for ages, sometimes the best thing to do is to just call it a night and get some sleep.  When you wake up, your mind will be more focused, and last night's impossible barriers become mere toy puzzles in the face of your well-rested intellect.  Going to sleep is not giving up.. it's a tactical retreat.  :>

You're a fine one to talk, Annikk.

(click to show/hide)

And my personal favourite:

(click to show/hide)
Yeah, do as the man says, not as he does.  :P

Aino

  • Ent
  • ******
  • Thank You
  • -Given: 4
  • -Receive: 30
  • Posts: 1,527
  • Eufloria: Yes
Re: Troubleshooting your designs
« Reply #6 on: June 29, 2011, 04:02:18 AM »
Lol Pilchard, that was hilarious :)

I never sleep that much either, because it is in the shine of the fullmoon I code fastest and most logical, thats why GetMouseX() and GetMouseY() came up, would you even imagine that it should look like that... I can't even remember how I put that together xD

Bonobo

  • Achiever
  • Old Oak
  • ****
  • Thank You
  • -Given: 139
  • -Receive: 12
  • Posts: 670
  • Eufloria: Yes
Re: Troubleshooting your designs
« Reply #7 on: June 29, 2011, 04:19:45 AM »
[..]

Yeah, do as the man says, not as he does.  :P
Vvvvvvvery cool, Pilchard123! There’s a Turkish proverb that says: “Do as your teacher says, not as he does!”

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: Troubleshooting your designs
« Reply #8 on: June 29, 2011, 08:28:23 PM »
Indeed, do as I say, not as I do :P

I do go to sleep though, eventually.  I reach a certain point where I know my brain is not operating properly, and I normally call it quits at that point because I worry I'm going to make poor changes and mess everything up..

I've done a massive update on this today.  Any further feedback?  I'm particularly interested to know if any of the parts don't seem clear.  Is it all very easy to understand?

Aino

  • Ent
  • ******
  • Thank You
  • -Given: 4
  • -Receive: 30
  • Posts: 1,527
  • Eufloria: Yes
Re: Troubleshooting your designs
« Reply #9 on: June 29, 2011, 09:29:24 PM »
To clean it up: Use anchors :)

Like this:

The text  starts here, this is an actual anchor!

Code: [Select]
[anchor=Start]The text  starts here, this is an actual anchor![/anchor]
(click to show/hide)

and to go to the top:

Go to top

Code: [Select]
[iurl=#Start]Go to top[/iurl]
NOTE: yuo can use this to go up and down, not only up :)

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: Troubleshooting your designs
« Reply #10 on: June 29, 2011, 09:33:22 PM »
Awesome, I didn't know you could do that.  :>

Aino

  • Ent
  • ******
  • Thank You
  • -Given: 4
  • -Receive: 30
  • Posts: 1,527
  • Eufloria: Yes
Re: Troubleshooting your designs
« Reply #11 on: June 29, 2011, 09:36:36 PM »
Well, it's hard to do it on SMF BBCode, atleast hard to find out how, took me 15 minutes to google around just for posting that :P

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: Troubleshooting your designs
« Reply #12 on: June 29, 2011, 09:46:21 PM »
I've never come across that BBcode functionality before.  Cheers for that! :>

Aino

  • Ent
  • ******
  • Thank You
  • -Given: 4
  • -Receive: 30
  • Posts: 1,527
  • Eufloria: Yes
Re: Troubleshooting Your Designs
« Reply #13 on: June 29, 2011, 09:48:42 PM »
Looking good, and much easier to find what you want, maybe do this to all the other posts you have too?

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: Troubleshooting Your Designs
« Reply #14 on: June 29, 2011, 10:15:18 PM »
Yeah I have a lot of plans for the other guides.. I'd like to roll them all into one big thread to reduce some of the sticky clutter in this subform.  I want to totally overhaul the beginner's guide, to get people using While GameRunning() do right from the outset, etc.  I also want to do an advanced guide where I will cover things like drawing, matrices, converting maths to code, and other crazyness.  One thing at a time though... :>

Aino

  • Ent
  • ******
  • Thank You
  • -Given: 4
  • -Receive: 30
  • Posts: 1,527
  • Eufloria: Yes
Re: Troubleshooting Your Designs
« Reply #15 on: June 29, 2011, 10:25:17 PM »
Hehe, hope it turns out good :P

collapsoul

  • No Intel Inside
  • Sapling
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 54
Re: Troubleshooting Your Designs
« Reply #16 on: December 06, 2011, 05:30:03 PM »
Bringin' topic up, it very well deserves that.

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: Troubleshooting Your Designs
« Reply #17 on: May 28, 2012, 05:54:17 PM »
I should really organise all my guides into one big thread...

Tomfloria

  • Shrub
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 232
Re: Troubleshooting Your Designs
« Reply #18 on: May 28, 2012, 06:38:23 PM »
You should Annikk haha, you have loads haha

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: Troubleshooting Your Designs
« Reply #19 on: May 28, 2012, 06:49:41 PM »
It'd be a big task..

Eufloria Admin

  • Global Moderator
  • Seedling
  • *****
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 38
Re: Troubleshooting Your Designs
« Reply #20 on: May 28, 2012, 07:55:01 PM »
Ok, doing it.

Going to take a while though...

Eufloria Admin

  • Global Moderator
  • Seedling
  • *****
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 38
Re: Troubleshooting Your Designs
« Reply #21 on: May 28, 2012, 08:00:38 PM »
Witness my admin form!

Pilchard123

  • Tester
  • Old Oak
  • ****
  • Thank You
  • -Given: 4
  • -Receive: 24
  • Posts: 932
  • Eufloria: Yes
Re: Troubleshooting Your Designs
« Reply #22 on: May 29, 2012, 01:28:26 AM »
Wow, when did you hit your limit break? You haven't been this powerful for months!

Just...no Supernova, please. I don't want to have to wait for years just to carry on coding.