Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Studio Chat / how to handle unexpected errors in large code?

Author
Message
dandrews
3
Years of Service
User Offline
Joined: 26th Jun 2020
Location:
Posted: 4th Jul 2023 15:29
just seeing if anyone has suggestions for how to find and handle errors in code in a way that i can see whats happening instead of the app closing or the basic error message coming up. the basic error messages are a big help for sure, as of right now ive been putting do loops anywhere im having issues and printing whats happenig. So besides a "if error print this" after every line of code what are others doing? thanks!
smerf
19
Years of Service
User Offline
Joined: 24th Feb 2005
Location: nm usa
Posted: 4th Jul 2023 17:50
100% of your code should be inside functions essentially unless you use jumps from loop to loop. One method that is usefull i just putting a print of flag in the top of each function that updates as the prog runs. This will let you know the function that failed. From there you can isolate the code to a small area. Ive used the debugger maybe 10 times in 15 years the general error messages are pretty useful. so in each function gosub goto ect u can just have an update. i imagine u could get cool and cleaver with it and make it a function on its own like

blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 4th Jul 2023 17:55
Have you tried using debug?
PartTimeCoder
AGK Tool Maker
9
Years of Service
User Offline
Joined: 9th Mar 2015
Location: London UK
Posted: 4th Jul 2023 18:51 Edited at: 4th Jul 2023 19:01
Yup, as blink0k says use debug

to clarify, Use the Log("Your string") function to print out the state of your variables and run the game in debug mode, if your variables are numbers be sure to wrap them in the Str() function ... Log is also a math function when used with numbers! .... weird they did that Id have called it Debug but NM!



Edit: combine with smerf's approach and you got a pretty good reporting system, I would only go to such lengths with real problem areas tho!

you can also use the variable watcher but its easier just to "Log" .... unless its really problematic code then you want to use the debugger to its fullest and stick vars on the watch list and step into/out of code ... I never had to go that far to be honest, not with AppGameKit, C++ on the other hand the debugger is your best friend!! lol
Open Source plugins
Cl - DnD Plugin
Buy Me A Coffee

Attachments

Login to view attachments
dandrews
3
Years of Service
User Offline
Joined: 26th Jun 2020
Location:
Posted: 4th Jul 2023 19:26
thanks all. im asking because some functions i use multiple place of course so when i get an error it doesnt really tell me what function it came from to produce the error
PartTimeCoder
AGK Tool Maker
9
Years of Service
User Offline
Joined: 9th Mar 2015
Location: London UK
Posted: 4th Jul 2023 19:54
Yea a Lua type stack trace system would be nice you can get the calling function further up the stack, but alas!

you could implement your own pseudo stacktrace if you have a problematic function called from multiple places

something like


But it would have to be giving me serious headaches for me to go to those lengths
Open Source plugins
Cl - DnD Plugin
Buy Me A Coffee
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 4th Jul 2023 23:27
Debug shows you the stack
PartTimeCoder
AGK Tool Maker
9
Years of Service
User Offline
Joined: 9th Mar 2015
Location: London UK
Posted: 5th Jul 2023 01:37
Ha!, Shows how little I've used it!

Is there a video showing the full usage of the debugger, if not, there should be
Open Source plugins
Cl - DnD Plugin
Buy Me A Coffee
dandrews
3
Years of Service
User Offline
Joined: 26th Jun 2020
Location:
Posted: 5th Jul 2023 02:16
yeah it would be great to see it in use
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 5th Jul 2023 02:59 Edited at: 5th Jul 2023 03:01
F8 to start debugger
1. Top left you can see the Stack. I'm pretty sure it's the same with classic
2. The red dots are breakpoints, you can set them by clicking on that column
3. Hover over a variable and it will show you it's contents
4. You can add "watch" variables at the left where you can modify their contents

There's a lot of other functionality I am not familiar with. I think there are a few videos on YouTube by TGC demonstrating the finer details

Trust me, spend a few minutes with it and it will radically change and speed up the way you develop stuff.

Login to post a reply

Server time is: 2024-05-02 00:07:50
Your offset time is: 2024-05-02 00:07:50