Making code more effective and easier to read and understand

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Gylletanken
Posts: 28
Joined: 30 Nov 2024, 13:38

Making code more effective and easier to read and understand

Post by Gylletanken » 14 Dec 2024, 09:20

How do i make this more efficient and easier to understand? Code:

Code: Select all

#SingleInstance


CoordMode, mouse, screen

Pause


5::
 Send /
 Sleep 100
 Send Giving free wins on blockdrop
 Send {Enter}


 return



4::
 Send /
 sleep 100
 Send Join my block drop for 10/20
 Sleep 100
 Send {Enter}
 Sleep 5000
 Send /
 Sleep 100
 Send Who wanna join my block drop for 10/20
 Send {Enter}

return


3::
 Send /
 sleep 100
 Send MAKE A BLOCK DROP FOR 10 OR 20
 Sleep 100
 Send {Enter}

return

 z::
  Click, 957, 1032
  sleep 2000
  Click, 957, 1032
  Sleep 1650
  Click, 957, 1032
  Sleep 1400
  Click, 957, 1032
  Sleep 1400
  Click, 957, 1032
  Sleep 1900
  Click, 957, 1032
  Sleep 1550
  Click, 957, 1032

return




  x::ExitApp


Thank you :)

Peabianjay
Posts: 136
Joined: 07 Nov 2015, 22:50

Re: Making code more effective and easier to read and understand

Post by Peabianjay » 14 Dec 2024, 22:33

I often use more or less unnessary functions simply to improve readability.

Instead of repeating " Click, 957, 1032 sleep # you could use a little function named according to what you're clicking:

Code: Select all

4::
slow_send(  5000, "Join my block drop for 10/20" )
slow_send(  1, "Who wanna join my block drop for 10/20" )
return

z::
poke_the_bear( 2000 )
poke_the_bear( 1650 )
.
.
.
return

slow_send( mydelay, mymessage )
{
     Send /
     sleep 100
     Send %mymessage%
     Sleep 100
     Send {Enter}
     Sleep %mydelay%
}

poke_the_bear( mydelay )
{
     Click, 957, 1032
     sleep %mydelay%
}
Note that "efficient" isn't clear. Make what efficient? Efficient coding means making function calls (as I've done here), so you don't have to write blocks of code many times. In some cases, you want space efficiency (for massive data work), or speed efficiency (for real time response/calculations).

Rarely can you "do it all".

Post Reply

Return to “Ask for Help (v1)”