Debugging in Thunkable X (Video)

I thought I’d share a process I use for debugging my projects. It involves creating a function that can be used over and over throughout the code blocks in order to help determine where things are going wrong, whether or not certain blocks are ever triggering, and what the values of several variables are.

Here’s a screenshot of what I’ve set up:

The real power comes from being able to quickly change the delay (and even set it to 0 seconds) or just remove the contents of the function so that it doesn’t run at all when you’re ready to publish. I cover all of that in the video.

If you want to try out the project yourself: Thunkable

And a video that shows how to do this and explains why I do it this way:

14 Likes

Thank you for sharing your thoughts. Very useful :clap:t2:

2 Likes

I found the issue, When I add the dvl or dvg and select the data source, it crashes, When I removed the data source it works. But i need that dvl. What to do?

This is a topic related to debugging in general. It’s not really for specific questions about problems you’ve found in your code.

I recommend starting a new topic and including as many details (e.g. screenshots, link to your project) as possible.

2 Likes

I’m sorry, I wasn’t aware of that. I’ll do it

Hi @tatiang, using the video you sent to me, I created the Debug blocks (See below)

Debug blocks

I then tried to get them to work to find my issues by adding a User_Values_Label to the Debug blocks. The plan was to find if my Login Page was searching for my Username during the Login process.

See video for what happened:

Andos

Okay so it runs through the loop and completes the set of blocks in when Debug Click and successfully displays 1, 2, 3, 4, 5, end. Did that answer your question?

Hi @tatiang, I’m afraid it doesn’t answer my question because as my Login Screen loads, it stops at the loading icon. This suggests to me that it, either, for some reason has stopped finding the Firebase Sheet with Member details or it somehow has stopped verifying the sheet details. In which case, how can this Debug operation run through my Firebase sheet and not find anything wrong? Or, is the Debug operation not checking the Firebase Members sheet? I really don’t understand what it is that I am doing.

Are my blocks correctly set up to check my Firebase sheet? If not, how do I do this?

Please see my blocks below:

Andos.

The when Debug Click set of blocks doesn’t have anything to do with your Firebase data, as far as I can tell.

Now that you have a Run_Debug function, add it to the SignIn block because that’s where you want to see what’s happening. So inside of SignIn, add the function a few times to see where it works (displays the message) and where it doesn’t.

Edit: actually, now that I look more closely, you’re not using any Firebase blocks except the SignIn. So I’m not sure how much good that type of debugging is going to do. But I’d still try it!

More importantly, you need to debug the getUser function as I think I mentioned earlier. That’s where I’d focus my time. Check that the list of values blocks are returning the values you expect them to. Don’t rely on those blocks without double-checking.

Hi @tatiang, I apologise for sounding stupid but, how do I fit the Run_Debug function into the getUser block so it works.

Have I inserted the Run_Debug function correctly? See below:

I am still only receiving the result in the video below:

Andos

Hi @tatiang, I have a few questions…

  1. If the Run_Debug function counts 1 thru 5, does that mean there are no errors?

  2. What should I be seeing?

  3. My members’ list is not being displayed in the countdown. Is there a way to make this happen?

  4. With no Members’ List contents being shown, does that imply that the Members’ List
    is not being read?

I am guessing by “messages” you mean the “Starting”, “Running”, “Complete” and “End” messages, or should I receive some sort of other message?

  1. What are the numbers 1 thru 5 actually counting and what is their purpose? Are they counting rows in the “Firebase” spreadsheet?

Once again, I apologise for what may seem to be “stupid” questions but I somehow am not qrasping what the Run_Debug function is trying to do exactly.

Andos.

Andos.

I think you misunderstood the purpose of the debugging function. It doesn’t tell you anything by itself. All it does is display a value and then wait so you can read that value on the screen.

It’s no different than using these blocks:
Set label’s text to “1”
Wait 1 second

But I got tired of adding and configuring those blocks over and over again so I made a function to save me time.

So why use them? Well, what I usually do is to space the debug function throughout any blocks that don’t seem to be working. Like this

When [event]
Debug “1”
[Some blocks]
Debug “2”
[some blocks]
Debug “3”

That way, when I preview my project, if I only see “1”… “2” then I know the code stopped working between where I have debug “2” and where I have debug “3”. Then I can add more debugging functions between those to further narrow down what is causing the problem.

But it’s possible that all of the blocks run and I see “1”… “2”… “3”. Then what? Well, in your case you might set the debug function to display the value of each of your variables in the getUser function. That way you can see if their values are what you expect them to be. Or you might display the number of rows in your data source. Maybe you think it’s 25 but it’s really 600 or 10. That happened to me recently.

So the debug function can help to show you values while your project is running rather than only at the end. It helps to slow things down so you can figure out where something went wrong.

If it still doesn’t make sense, share a new project link and I can provide a screenshot of your blocks with debugging blocks added.

Hi @tatiang, I sort of understand a little better but I still don’t really know where I should put these blocks or how they would fit. Below, I have attached a project link, as requested, for you to look at.

https://x.thunkable.com/copy/30abe8cafdbf40b76b5f4a6403210b90

Andos.

Here’s how I would set up the blocks. The basic idea is that each time you set a variable value, you then display that variable. And I would probably increase the wait time in the Run_Debug function to 1 or 2 seconds so you have enough time to see the values that appear.

Hi @tatiang, I shall try this and let you know how I get on.

Andos.

Hi @tatiang, I set up the blocks as you suggested. (see below).

Blocks for debugging get_user function:

The Live Test result link is shown below:

Does this mean there are no errors in my "getUser function?

Or, have done something wrong?

Andos.

Hi @tatiang, I’ve just spotted and error I made please ignore previous results image and video. The amended image and video are below:

Blocks image

Live Test result video

Andos.

I don’t understand the video. It’s looping through numbers 1-5 which I suggested is not that helpful. Where are the debugging values inside of the getUser function (“index”, “username”, etc.)?

Hi @tatiang, I have placed the Run_Debug blocks within the getUser as you suggested (see blocks)

but it just counts thru with numbers.

Has this anything to do with my Debug Click blocks below?

I can’t help thinking that the Debug function isn’t picking up/ reading anything.

Andos.

Clicking the Debug button is just going to show 1, 2, 3, 4, 5 again.

For the debugging to work properly, you have to call the getUser function. That happens here: