What could cause bugs in a script that should work fine?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
prestonage
Posts: 35
Joined: 17 Nov 2021, 10:53

What could cause bugs in a script that should work fine?

Post by prestonage » 07 Dec 2021, 06:01

I have written a very long script automating some of my work, and I don't want help fixing it, so I won't post the whole thing, but I would like to ask a few general questions about what could cause an error. I started this only a month ago, but I've written at least 50,000 lines of code in AHK already. When I see an issue in the script, I immediately stop it and come up with a solution. However, about one in 50 times I run the script, it just bugs out.

For example, it seems to start on this section, where I send a random word from a list of options:

Code: Select all

Random, output, 49, 9999

Sleep, 10

Send % option%output%

Sleep, 10
Instead of sending one option, it sends four of them back-to-back. This isn't in a loop so I really don't understand it. I have all my entered data set to collect automatically into ini files so that I can access it if need be, and when this happens it writes the data 4 or 5 times instead of once.

So this is the stuff that is actually documented, the rest of the actions also seem wrong but the only verification is my seeing it with my eyes.

With this in mind, my questions are:

■ Does AHK just not work every time? Does it have a fail rate of less than 100%? Or...

■ Is the issue due to hardware being pushed too far? Because when I run the script, my computer is definitely being heavily used as far as CPU & memory go. Is it possible for AHK to fail if the hardware is being heavily used? For the record, I have put a Sleep command between every single line of code in the script.

■ Given a script doesn't have any errors, are there any other ways for it to fail internally (as opposed to interference from other processes, etc)?

And then specifically:

■ How could a command be repeated 4 times by mistake?


I am not just interested in fixing this specific issue, but in learning more about AHK in general.


EDIT: I resolved the issue that spurred this line of thinking, but I would still like to learn if it's possible for AHK to fail with flawless code, and what the reasons might be (the questions above).
Last edited by prestonage on 07 Dec 2021, 08:09, edited 2 times in total.

User avatar
mikeyww
Posts: 26851
Joined: 09 Sep 2014, 18:38

Re: What could cause bugs in a script that should work fine?

Post by mikeyww » 07 Dec 2021, 06:16

The answer is that your script has a bug. The lines that you posted work.

Demonstration:

Code: Select all

option1 = 2
Send % option1
Send FINISHED.
Return
2::
Send abc
3::
Send xyz
Return

Lepes
Posts: 141
Joined: 06 May 2021, 07:32
Location: Spain

Re: What could cause bugs in a script that should work fine?

Post by Lepes » 07 Dec 2021, 07:45

It happens to me everyday, I just read a command with their parameters and when I try, it doesn't work as I expect. Most times are documented on the "remark" section or maybe another command that influences the one I'm using.

There are tons of "exceptions", "special cases" you need to keep in mind when you code. It is not about AHK, all programming languages have their rules and exceptions.
There are two differents ways of coding, as far as I know, the legacy one and the other that I'm used to use on any other programming language. If you don't know differences, you are introducing those bugs too.

Programming is the art to introduce bugs where they shouldn't exist :lol:

Post Reply

Return to “Ask for Help (v1)”