Godot Debugging Techniques EVERY Dev Should Know

Bacon and Games
3 Feb 202416:22

Summary

TLDRThis video script offers a detailed guide on advanced debugging techniques for game development, moving beyond basic 'print' statements. The speaker uses a Metroid Vania prototype to demonstrate scenarios where traditional console logging is insufficient and introduces more powerful methods like 'push error' and the debugger. They also show how to use the remote tree for runtime inspection and editing, as well as how to set breakpoints for step-by-step code analysis. The script concludes with tips on using visual aids like collision shapes for debugging, advocating for a more efficient and insightful approach to finding and fixing bugs in game development.

Takeaways

  • πŸ˜€ The script emphasizes the transition from using print statements to more advanced debugging techniques to save time and improve efficiency.
  • πŸ” It suggests that while print statements can be helpful, they can be visually mixed with other console output, making it difficult to isolate errors.
  • πŸ†• The video introduces the use of 'print_err' to make error messages stand out more in the console, but notes it doesn't add new functionality.
  • πŸ’‘ The script recommends using the 'push_error' method to send errors to the debugger, allowing for better inspection and navigation to the source of the error.
  • πŸ”§ It highlights the importance of using the debugger to expand and follow the logic of the code, providing a clearer path to identifying the root of the problem.
  • πŸ“š The speaker discusses the various print functions and how to navigate to their definitions for further investigation of alternative options.
  • πŸ‘€ The script introduces the concept of using the 'remote view' to inspect objects live during gameplay, offering a more dynamic debugging approach.
  • πŸ› οΈ It explains how to use the 'remote tree' for debugging, allowing real-time inspection and editing of game objects to identify and fix issues on the fly.
  • πŸ“± The video shows how to use breakpoints effectively to pause the game at specific points, inspect variables, and step through the code to find where logic fails.
  • πŸ”„ The script discusses the use of 'step into' and 'step over' features in the debugger to navigate through code methodically and understand the flow of execution.
  • πŸŽ›οΈ It also touches on the use of visual aids like 'visual Collision shapes' in the debugger to get immediate feedback on game mechanics and interactions.

Q & A

  • What is the main issue with using 'print' statements for debugging in the script?

    -The main issue is that 'print' statements can be underpowered and visually mixed with less critical outputs, making it difficult to isolate and identify errors effectively.

  • What alternative to 'print' is suggested in the script for better debugging?

    -The script suggests using the debugger or methods like 'push error' for better visibility and functionality in identifying and resolving errors.

  • How does using 'push error' improve the debugging experience compared to 'print'?

    -'push error' pushes the error message to the debugger, where it can be expanded and investigated in a more organized manner, separate from other console outputs.

  • What is the advantage of using the debugger over 'print' statements?

    -The debugger allows for the inspection of the state of the program at specific points, enabling the developer to follow the logic and directly jump to the line of code causing the issue.

  • What is the 'scene manager' mentioned in the script, and why is it relevant to debugging?

    -The 'scene manager' is a part of the game that handles the loading and transitioning between different game scenes. It is relevant to debugging because issues in scene loading can cause the game to fail or behave unexpectedly.

  • What is the purpose of the 'remote view' in the debugger, and how does it help with debugging?

    -The 'remote view' in the debugger shows the current state of the game objects and variables at runtime. It helps with debugging by providing a real-time inspection of the game's internal state, which is more useful than the static 'local view' from edit time.

  • How can the 'always on top' setting in the project settings improve the debugging process?

    -The 'always on top' setting ensures that the debugger window remains visible and in focus, allowing developers to inspect variables and objects without losing focus when interacting with the game.

  • What is the benefit of using breakpoints in the debugger?

    -Breakpoints allow the developer to pause the execution of the code at specific points, enabling them to inspect the state of variables and objects at that moment, which can be crucial for understanding and fixing complex issues.

  • What are the two main actions available when the code execution is paused at a breakpoint, and what are their purposes?

    -The two main actions are 'step into' and 'step over'. 'Step into' allows the developer to enter a function and execute it line by line, while 'step over' executes the current function without stepping into it, moving to the next line. These actions help in auditing the code and understanding the flow and state changes.

  • How can the 'visual Collision shapes' setting in the debugger help with game development?

    -The 'visual Collision shapes' setting provides visual feedback on collision detection within the game, allowing developers to see and adjust the positions and sizes of collision areas for better game mechanics and interactions.

  • What is the final advice given in the script regarding the use of 'print' statements and debugging?

    -The script advises not to completely quit using 'print' statements but to incorporate additional techniques such as using the debugger, breakpoints, and remote views to enhance the debugging process and write fewer bugs in the first place.

Outlines

00:00

🐞 Advanced Debugging Techniques

The speaker discusses the limitations of using 'print' statements for debugging and suggests more effective methods like using a debugger. They demonstrate using 'push error' to isolate errors in a game development scenario with a Metroidvania game prototype. The video also introduces the concept of using the debugger to trace and inspect the game's logic and objects in real-time, providing a clearer path to identifying and fixing bugs.

05:02

πŸ” Inspecting Objects and Debugging Live

This paragraph delves into the process of inspecting game objects at runtime to debug issues. The speaker explains how to use the remote view in the debugger to observe the game's state and make real-time edits to variables, such as player strength, to test hypotheses about the source of bugs. They also highlight the importance of using breakpoints to pause the game at critical points and inspect the state of data being passed between levels.

10:03

πŸ› οΈ Utilizing Breakpoints and Step-by-Step Debugging

The speaker provides a detailed explanation of how to use breakpoints in the code to identify the source of errors. They illustrate the process of stepping through code line by line to observe variable states and the order of operations, which is crucial for understanding where logic fails. The paragraph emphasizes the utility of stepping into or over functions to focus on specific parts of the code where errors are suspected, without getting bogged down by parts that are known to be correct.

15:04

🎨 Visual Debugging with Collision Shapes

In the final paragraph, the focus shifts to visual debugging tools such as collision shapes and area 2D triggers. The speaker explains how enabling visual collision shapes can provide immediate feedback on the game's collision mechanics, helping to identify issues that may not be immediately apparent through code inspection alone. They also touch on the importance of visual feedback in conjunction with other debugging techniques to ensure a comprehensive understanding of the game's behavior.

Mindmap

Keywords

πŸ’‘Debugging

Debugging is the process of finding and resolving bugs or defects that prevent correct operation of computer programs. In the video, the theme revolves around improving debugging techniques beyond using simple print statements to the console. The script discusses various methods such as using a debugger tool, setting breakpoints, and inspecting objects at runtime to effectively hunt down and fix bugs.

πŸ’‘Print Statements

Print statements are lines of code used to output information to the console for debugging purposes. The video suggests that while print statements are a basic method for debugging, they can be visually mixed with other console output and may not provide enough functionality for effective bug hunting. An example from the script is when the scene manager fails to load a level due to a typo, and using print statements doesn't help isolate the issue clearly.

πŸ’‘Debugger

A debugger is a tool used by programmers to test and debug their code by examining its execution step by step. The script emphasizes the use of a debugger as a more powerful alternative to print statements, allowing for the examination of variables and code flow in real-time. The video shows how to use the debugger to pause execution at breakpoints and inspect the state of the program.

πŸ’‘Breakpoints

Breakpoints are markers in the code that tell the debugger to pause the program's execution at that point. The script describes how to set breakpoints in the margin of the code, which allows the programmer to stop the program just before a particular line of code is executed, making it easier to inspect the current state of variables and objects, as demonstrated when the scene manager is about to pass data between levels.

πŸ’‘Scene Manager

A scene manager is a component in a game engine responsible for switching between different scenes or levels in a game. In the script, the scene manager is used as a context for demonstrating debugging techniques, such as using print statements and breakpoints to troubleshoot issues with loading a level file.

πŸ’‘Remote View

Remote view in the context of the script refers to inspecting the objects and variables of a running game as they exist at runtime, as opposed to the local view which shows the state at edit time. The video suggests enabling the remote view for a more useful debugging perspective, allowing the programmer to see and interact with the game's current state, such as the player's strength or the scene manager's variables.

πŸ’‘Step Into / Step Over

Step Into and Step Over are controls in a debugger that allow the programmer to execute code one line at a time, with Step Into entering into functions and Step Over executing the current function without stepping into it. The script uses these terms to explain how to carefully inspect the code line by line or function by function to find the source of a bug, such as when testing the logic of moving objects in the game.

πŸ’‘Data Packet

A data packet, in the context of the video, refers to a collection of data being passed from one level to another in a game. The script discusses how to use the debugger to inspect the contents of a data packet at runtime, which is not directly visible in the scene tree, to ensure that the correct information is being passed, such as the door the player is exiting through.

πŸ’‘Visual Collision Shapes

Visual collision shapes are graphical representations of the collision areas in a game, used for debugging purposes. The script mentions turning on visual collision shapes in the debugger to get immediate visual feedback on whether elements in the game are colliding as expected, which is useful for adjusting things like the length of a raycaster.

πŸ’‘Raycaster

A raycaster in gaming is a method used to detect collisions or intersections with objects along a line extending from a point, often used for line-of-sight or aiming mechanics. The video uses the raycaster as an example of how visual debugging can help a programmer see and correct issues like ensuring a raycaster is long enough to reach its intended target.

Highlights

Transitioning from using 'print' statements to more advanced debugging techniques can save time and improve efficiency in bug hunting.

In scenarios where 'print' is underpowered, using a debugger provides a more effective way to track down bugs.

Demonstration of debugging a Metroid Vania game prototype to illustrate the use of debugging tools over 'print' statements.

Using 'push error' instead of 'print' can help isolate error messages and make them more visible in the debugger.

The debugger allows for expanding and following logic, providing a clearer path to identifying the source of an error.

Different 'print' functions can be used, and clicking on them can lead directly to their definition for further exploration.

Switching to 'remote view' in the debugger provides a live representation of the game state, aiding in debugging.

Enabling 'always on top' for the debugger window keeps it in focus, allowing for continuous inspection without losing the view.

Using the debugger's 'remote tree' to inspect and edit variables at runtime can help identify and fix issues on-the-fly.

Setting breakpoints in the code allows for introspection at specific points, providing deeper insight into the program's state.

Stepping through code line by line with the debugger can help identify exactly where logic breaks or variables are undefined.

The debugger's 'step into' and 'step over' features are useful for auditing code and checking variable states incrementally.

Visualizing collision shapes and triggers during debugging can provide immediate feedback on game mechanics and interactions.

Debugging can be applied to non-scene tree elements like data packets passed between levels, which are not directly inspectable.

Using breakpoints to walk through code can reveal issues with generated or dynamically created elements that aren't easily inspectable.

Debugging not only helps in identifying bugs but also in understanding the flow of execution and variable states over time.

The video concludes with a reminder that while 'print' statements are not entirely obsolete, incorporating debugger tools can significantly enhance the debugging process.

Transcripts

play00:00

for the better part of my career I did

play00:01

most of my bug hunting by desperately

play00:03

printing messages to the console like a

play00:05

caveman cave

play00:08

person anyway it's time to quit using

play00:10

print and save yourself a bunch of time

play00:12

in the process let's

play00:15

[Music]

play00:20

go all right so I'm not actually

play00:22

suggesting you never use print again but

play00:25

there are some scenarios where print is

play00:27

underpowered the debugger or methods

play00:30

might be a little bit more effective for

play00:32

hunting down one of those pesky bugs in

play00:34

this video I'm going to use this Metroid

play00:36

Vania sooon prototype I've been fiddling

play00:39

with we're going to look at a couple of

play00:41

scenarios where I might need to debug

play00:43

this prototype let's take a look at this

play00:45

scene manager so this is actually an

play00:47

early version of what later became the

play00:50

scene manager video that I made I'll put

play00:52

that up in the corner now if you want to

play00:54

check that out the game when I run it

play00:56

will attempt to load this level two file

play00:59

and and let's just suppose for a second

play01:01

that I mistyped this and if I come down

play01:04

here I've got this check where if the

play01:07

resource it's trying to load doesn't

play01:10

exist it's going to dump out of it and

play01:12

it's going to print you know a message

play01:13

to that effect so if I run this you see

play01:16

nothing loads and I come down in here

play01:18

and yeah I do get this error showing you

play01:20

know does not exist you know it's kind

play01:22

of mixed in visually with all this other

play01:25

stuff that I've been outputting stuff

play01:26

that's probably less critical because

play01:28

none of this is forcing the game to fail

play01:30

to load you know I I can't click on this

play01:31

I can't really do anything useful with

play01:33

it and yeah maybe in this example I

play01:35

might just right here notice that oh

play01:37

it's that extra two but maybe I forgot

play01:39

where that's defined so the sort of next

play01:41

line of defense here is instead of using

play01:44

print I can use print err and if I run

play01:47

this I still get that same error stands

play01:50

out a little more but I'm not getting

play01:51

any new functionality out of this so

play01:55

instead of that we can use push error

play01:57

what you'll see now instead of showing

play01:59

up here with with all this other stuff

play02:00

it's actually gotten pushed over to the

play02:02

debugger where I can now actually expand

play02:04

it first of all and I can follow the

play02:06

logic okay the ready fired uh and then I

play02:08

got into the scene manager which called

play02:10

load scene and I can literally click on

play02:12

this move this to the side and it's

play02:14

going to take me right to that line and

play02:16

now I can investigate a little bit

play02:18

further and go okay so this failed in

play02:20

the scene manager let me scroll up oh

play02:22

yeah okay this is just a typo and now if

play02:24

I close this and rerun it it would be

play02:26

fixed there are actually quite a few

play02:28

different print functions and if you

play02:30

command click or control click on a PC

play02:33

it'll take you right to the definition

play02:34

and then you can scroll through and have

play02:36

a look at some of the other options that

play02:38

are

play02:40

[Music]

play02:43

available we could actually take that a

play02:45

step further cuz let's pretend for a

play02:46

second that this wasn't the error maybe

play02:49

following that thread into the scene

play02:50

manager got me closer but not all the

play02:53

way there the next line of defense is

play02:54

looking at some of these objects live um

play02:57

inspecting them so let's go up to editor

play02:59

editor settings and search for remote

play03:02

and then come down to debugger and check

play03:05

this always switch to remote scenry let

play03:08

me uncheck that real quick so you can

play03:09

see what this does when you run the game

play03:12

you get your window here and then here

play03:14

is my local view this is everything I

play03:16

did at edit time if I switch manually

play03:19

over to the remote view it's going to

play03:21

show me what's actually represented

play03:22

right here I've got the scene manager

play03:26

and Global these are my autol loads and

play03:28

then if I click Start it's going to take

play03:29

take us into well it's actually not

play03:31

going to take us in because that error

play03:33

is still there but what you would see is

play03:36

that level loaded you can see it already

play03:37

started doing some of that um but we're

play03:39

stuck because we haven't fixed that so

play03:41

if I come into editor settings and check

play03:45

this on now when I play this you see it

play03:49

automatically switches over to our

play03:51

remote view which generally from a

play03:53

debugging perspective is way more

play03:55

interesting and useful than your local

play03:57

view so I like to turn this on the other

play03:59

thing I like to turn on is under project

play04:01

settings with your advanced settings

play04:04

turned on you can search for always and

play04:06

then go to window and turn on always on

play04:10

top if I uncheck this and we run our

play04:13

game comes up automatically switches

play04:15

over to the remote but if I want to

play04:17

inspect one of these see as soon as I

play04:19

click it pushes that window to the

play04:22

background because it's lost Focus so

play04:24

with that turned on it switches to my

play04:27

remote view I can click on the scene man

play04:29

manager and look at the information in

play04:31

it I can click on all of these things

play04:34

and this is still going to stay front

play04:35

and center I find those to be to very

play04:37

helpful settings not just for debugging

play04:39

but for working on your game in general

play04:42

in a minute we're going to talk about

play04:43

how to use the debugger but before we do

play04:46

that I want to talk about how to use the

play04:47

remote tree to debug rather than having

play04:50

to use print statements so let me fire

play04:52

up this level one of the things in this

play04:54

game is that you can push more than one

play04:56

block at a time and so there's the sense

play04:59

of of the player strength and then the

play05:02

concept of the weight of the total

play05:04

objects that are being pushed so if I

play05:05

push this block up and try to push it

play05:07

again with the strength of one I can

play05:10

only push one block so this effectively

play05:13

is now solid because I can't move two at

play05:15

a time if I collect this strength object

play05:18

it should allow me to push both of these

play05:20

but it's not and this could be for a

play05:22

number of reasons it could be because

play05:24

the thing I collected is broken it could

play05:26

be that the logic behind tallying the

play05:29

total weight of the push is broken it

play05:30

could be a whole bunch of different

play05:31

things and I could go through my code

play05:34

and put print statements all over the

play05:36

place and try to figure out exactly

play05:38

where the error is but instead I can

play05:42

click over here onto my globals which is

play05:46

where I'm managing the player strength

play05:48

you can see it's set to one right now

play05:50

and now I can move my player around and

play05:51

I can collect this and I can see oh you

play05:55

know what player strength hasn't changed

play05:57

hang on a second so let me take a look

play05:59

at my strength upgrade oh well here's

play06:01

the issue I'm not adding one I'm adding

play06:05

zero so if I save this and play now when

play06:08

I collect this I can push one and oh now

play06:11

I can now I can push two great that's

play06:14

fixed not only can you inspect things at

play06:17

runtime but you can also edit them as a

play06:19

way to debug whether that's even the fix

play06:22

so let's say for example you know I push

play06:24

these and okay so my strength is one I'm

play06:27

trying to push two so of course of

play06:29

course that doesn't work let me click on

play06:31

globals and increase my strength to two

play06:34

now I can come back to the game and push

play06:35

and oh it works okay so the issue

play06:37

actually is the player strength it's not

play06:39

something else and then that might be

play06:40

where I go in and fix this but what if

play06:43

we're running into an issue we want to

play06:45

test that isn't represented in our scene

play06:47

tree how do we inspect that that's where

play06:50

the debugger can give you insight into

play06:53

things that the scene tree

play06:56

[Music]

play06:58

can't

play06:59

so let's jump over to our scene manager

play07:02

again this portion of code right here is

play07:05

where we're passing data from one level

play07:08

to the next so this is this data to pass

play07:11

packet is where we're defining a bunch

play07:13

of things like the door that the player

play07:15

came through and whether they're

play07:16

bringing a crate with them this doesn't

play07:19

exist in the scene tree it gets created

play07:22

by the level you're exiting and passed

play07:24

off to the level that you're entering so

play07:26

there isn't really an easy way to come

play07:28

into the scene to click on something and

play07:30

take a look so we can use the debugger

play07:33

by clicking in this margin here you see

play07:35

this little red dot when I click here it

play07:37

creates this little red dot which means

play07:40

that it's going to execute code up until

play07:41

that point and then it's going to stop

play07:43

before it continues and I can put as

play07:45

many of these as I want and I can walk

play07:47

through them and take a look into the

play07:49

variables and objects and other things

play07:52

in that moment in time before continuing

play07:54

on so if I run this now we're going to

play07:56

see it when I click Start because it's

play07:58

using that scene manager so you see it's

play08:01

paused that's why I have this little

play08:02

arrow in here and I don't know where to

play08:05

put this so with it paused I have a

play08:07

couple of options I can step through my

play08:10

code one line at a time um and we'll get

play08:12

into why you might do that in a second

play08:15

or I can click this little continue

play08:17

button which is just going to say all

play08:18

right just continue executing from here

play08:20

on out until you hit another break point

play08:21

so I'm going to click that because I

play08:22

don't actually want to inspect anything

play08:24

right now I'm going to keep clicking

play08:25

this until we get into our level and

play08:27

then what I actually want to do is I

play08:29

want to look at the data packet that I'm

play08:31

handing off oh actually got to move the

play08:33

blocks into place now the door is open

play08:36

and I can pass and now I'm going to hit

play08:37

that break point so we're we're right

play08:41

here and so this data to pass does exist

play08:45

and I can actually just scroll down here

play08:47

and you can see right here here's my

play08:48

data to pass and if I click on this it's

play08:50

going to open up in our properties

play08:51

window just like we're used to seeing

play08:53

when we're editing our game this is the

play08:55

departing door ID so we're exiting

play08:58

through East and when we enter into the

play09:02

next level we're entering through the

play09:04

west door so if I hit continue again my

play09:06

player gets positioned right here which

play09:08

is one unit to the right of the west

play09:11

door now granted this level is a

play09:14

placeholder and only has the one West

play09:16

door but if we had a North a South and

play09:18

an East door it's not going to know

play09:19

where to put the player unless I tell it

play09:21

where I came from but if for example I I

play09:24

came through this door actually here we

play09:26

can do this we can do this live so if I

play09:28

go to

play09:29

level two and click on my level Gateway

play09:34

here right you see over here I'm

play09:37

defining destination G Gateway West well

play09:41

maybe I duplicated this from another

play09:44

door in the room and then I forgot to

play09:46

change it maybe it said East if I play

play09:48

this again oops hang on oh this is

play09:52

actually a good opportunity to show you

play09:53

this so the reason it started Us in the

play09:55

level that we left from is that I'm

play09:57

actually in the middle of writing the

play09:58

save system and and it remembered that I

play10:00

was in that room when I quit and so it

play10:03

put me back there and that's not what I

play10:04

want during this test so an easy way to

play10:06

undo that is I can go into project open

play10:08

user data folder and it's going to bring

play10:10

up this it's my save file which I can

play10:13

just delete and now if I test this again

play10:16

and we're going to have to skip through

play10:18

this break point now we're in this level

play10:20

let me push my crates into place and now

play10:23

when I go through this door it's

play10:25

actually going to CRA well it's not

play10:27

going to crash let me continue through

play10:28

now you see I'm here and not here and

play10:31

that's because this is the default

play10:33

starting point I currently have in this

play10:34

temp level so let's do this one more

play10:37

time so we've got that breakpoint set up

play10:39

right now if I go through this now it

play10:42

pauses and I can come in here to the

play10:44

data to pass and

play10:47

go huh destination gate East well that's

play10:51

not right because I'm coming from the

play10:53

East so I have to end in the west so I

play10:55

can quit this and go back in here and

play10:59

you know reselect that and fix this

play11:01

issue here so you might be thinking well

play11:03

do you really need the break point can't

play11:04

you just come in here click on level

play11:05

Gateway and look at this and see that

play11:07

it's wrong yes you absolutely can do

play11:09

that this is a contrived example where

play11:11

we know the problem at a time if I had a

play11:14

much more complex game maybe it's

play11:16

procedurally generated stuff and you

play11:17

know it's harder for me to recreate

play11:19

exactly the scenario you know one uh I

play11:22

don't know where to look in the first

play11:23

place um that's what the break point

play11:25

might get you is that introspection but

play11:28

also maybe it just doesn't exist in a

play11:30

form like this because things are being

play11:32

generated on the fly so you know that's

play11:34

where using break points and inspecting

play11:37

your code uh one line at a time and

play11:39

looking at the objects as they exist in

play11:41

that moment uh can be really powerful

play11:43

getting back to the the different

play11:45

controls here in the debugger let's um

play11:48

let's uncheck that because we don't want

play11:50

to do that anymore and let's go over to

play11:52

our level objects and the way this

play11:54

system works is when the player presses

play11:56

a direction the request move fires and

play12:00

we check whether or not we're able to

play12:02

move into that space if we are then we

play12:05

attempt to move the tile and then when

play12:07

everything is done this move ended

play12:08

function fires and the turn is over

play12:11

let's say I've got an error somewhere in

play12:13

that chain of actions and I'm not

play12:16

exactly sure where it is I can put a

play12:18

break point here and this might be a

play12:21

kind of a janky game to check it on to

play12:23

test it on because we're going to get a

play12:24

lot of break points because the turns

play12:26

are short but you know if I press left

play12:28

you'll see it's attempting to move and

play12:30

now it's paused here and instead of

play12:32

hitting continue I might want to step

play12:34

through my code one line at a time and

play12:37

see how the variables change and in what

play12:39

order and you know where the logic

play12:41

breaks so I can actually I can press

play12:43

these two items down here will

play12:45

respectively step into a function or

play12:48

step over a function and both of them

play12:50

will move one line at a time so if I

play12:54

click this one what you see is going to

play12:56

happen is it's going to go to the next

play12:58

line and if I click it one more time

play13:00

it's going to go from line 11 to line 12

play13:02

it still executed that function it's

play13:05

just not going to walk you line by line

play13:06

through it why is that important well in

play13:09

this case maybe I know that my check all

play13:11

moves function is perfectly fine you

play13:13

know if this were let me pause this for

play13:15

a second let's say there was a line here

play13:17

that was significantly more benign I

play13:19

know this is working so if I run this

play13:21

code and I start stepping through it I

play13:24

get to this and I'm like I don't need to

play13:26

granted that's one line but if this were

play13:28

a a larger function that I know to be

play13:30

sound I can step over that function

play13:33

instead of into it and I can actually

play13:35

verify okay here's X yeah okay X is four

play13:39

that's correct If This Were a really

play13:41

long function that I knew to be working

play13:44

I wouldn't want to jump into it and go

play13:46

through that line by line I just I want

play13:48

to continue through and you know look at

play13:50

other lines where I think the logic

play13:52

might be failing me so you know if I ran

play13:54

this again and I try to move and I hit

play13:57

my break point if I I step down to this

play14:00

and then into my check all moves

play14:02

function as an example by clicking the

play14:04

step into you see it's going to take me

play14:06

here check all moves and now I can

play14:08

either continue through the entirety of

play14:10

this or I can step through line by line

play14:13

and follow the breadcrumbs as I'm going

play14:17

and at any point if I go well if it's

play14:20

working up until this point let me just

play14:21

continue and it's going to you know you

play14:23

can see it's continued the execution and

play14:25

now it's actually waiting for input and

play14:27

if I move again we're going to hit that

play14:29

breakpoint again and everything's going

play14:30

to repeat so these two features step

play14:33

into and step over can be really helpful

play14:35

if you have a hunch for roughly where

play14:37

your error might be but you're not sure

play14:39

and you want to go through and kind of

play14:41

audit like okay let me run this one line

play14:44

check the variables does everything line

play14:45

up the way it's supposed to be you know

play14:47

what sometimes you'll find is you're

play14:49

trying to access something before it

play14:50

exists and so you step through your code

play14:53

one line at a time and you go oh this is

play14:55

undefined I was expecting this to be

play14:57

defined at this point so let me figure

play14:59

out why this thing isn't existing at the

play15:01

moment that I expected it

play15:03

[Music]

play15:06

to as you've probably noticed when I'm

play15:09

testing this I'm not actually seeing my

play15:12

Collision shapes and sometimes that can

play15:13

be an issue so here's my Ray Caster

play15:16

here's all the different triggers more

play15:18

or less these are area 2DS if I under

play15:21

debug I can actually turn on visual

play15:24

Collision shapes and various other

play15:26

things to give me that feedack back

play15:29

while I'm also testing so that I can see

play15:31

oh you know what I thought these two

play15:32

things were overlapping or they're not

play15:34

so for example you know now I can see my

play15:37

raycaster and let's say and actually

play15:39

it's helping me visualize when that Ray

play15:41

Caster is see that it turns red because

play15:44

it's it's colliding with something so

play15:46

maybe you know if I thought my Ray cter

play15:48

was long enough and it wasn't uh this

play15:50

would give me that visual feedback that

play15:53

oh you know what I just need to make

play15:54

this a little bit longer for what I'm

play15:55

using it for okay so you don't have to

play15:58

completely quit using print but I hope

play16:00

this gives you a couple extra techniques

play16:02

for hunting down bugs in your code and

play16:03

if you'd like some tips for writing

play16:05

fewer bugs in the first place check out

play16:06

this video right up here until next time

play16:10

be kind to yourself and be kind to

play16:12

others I'll see you in the next

play16:15

[Music]

play16:20

video

Rate This
β˜…
β˜…
β˜…
β˜…
β˜…

5.0 / 5 (0 votes)

Related Tags
Game DebuggingPrint AlternativesScene ManagerRemote DebuggingBreakpointsRuntime InspectionCode AuditingVisual FeedbackGame DevelopmentError Tracking