Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Inline code is done by surrounding the code with _**single**_ backticks, eg:
- `example`
- Code blocks are handled by prepending _each_ line of the code with _**four spaces**_, eg:
- <space><space><space><space>example
- As for the code -- I'd work on getting your script to work _without an infinite loop_ first. Get the buttons, labels & progress controls working like you'd want...then tackle the looping portion of it. While I've not personally used `SetTimer` for my projects, here it would be the right call imo; as /u/joesii pointed out in his second comment.
- Here's an example of why we're leaning that way:
- ; Global variables
- val := 0
- inc := 1
- ; Update/Game Loop
- SetTimer, myLoop, 200
- ; Build GUI
- Gui, Add, Text, w200 +HWNDhText, %val%
- Gui, Add, Button, +ginvert, Invert
- Gui, Show, % "x" . (A_ScreenWidth / 2) . " y" . (A_ScreenHeight / 2), Example
- ; End the auto-execute section
- return
- ; Exit application if GUI is closed (or crashes)
- GuiEscape(GuiHwnd) {
- ExitApp
- }
- GuiClose(GuiHwnd) {
- ExitApp
- }
- ; Update/Game Logic
- myLoop() {
- ; Import global variables
- global val
- global hText
- global inc
- ; Increment Text value
- val += inc
- ; Update Text
- GuiControll,, %hText%, %val%
- }
- ; Action on Button Click
- invert() {
- ; Import global variables
- global inc
- ; Invert Increment Value
- inc *= -1
- }
- There's a couple of extra functions in there to handle exiting the application when you close to GUI, as otherwise it'll just keep running in the background...
- But with the above example, the `Text` control continues to update every 200ms. When the `Button` control is clicked; the `invert()` function is called, which inverts the increment value...but, _the timer keeps running_.
- With the infinite loop example, while you _could_ get that working, you may find that the button's gSub (or function) is never called; as the `Loop {}` statement is still executing...holding up the thread.
- Also, small correction -- AHK does have some kind of multithreading, but does not give us nearly the same control over it as traditional programming languages. In this case, the `timer` is, effectively, running on another thread ([source](https://www.autohotkey.com/docs/misc/Threads.htm)).
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement