Var doesn't update when label re-run

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Hybridnyckel
Posts: 11
Joined: 24 May 2017, 08:53

Var doesn't update when label re-run

15 Aug 2017, 04:12

Code: Select all

label:

; even after
var =

; and
var := clipboard
clipboard =
MsgBox %var%
The value of var is sometimes (not that often but often enough) still the same as the previous time the label was run. How to fix this? Clipboard is used for a lot of other vars in between this, so the problem can't be the clipboard variable not updating.
User avatar
Exaskryz
Posts: 2882
Joined: 17 Oct 2015, 20:28

Re: Var doesn't update when label re-run

15 Aug 2017, 09:24

Are we sure it can't be the clipboard not updating? That is the only thing I can come up with. You can try doing diagnostics with a Tooltip (so a MsgBox doesn't interrupt the flow) such as Tooltip value: %var% immediately after the var = to confirm that var is blank to begin with. If it is, then we would conclude that var := clipboard is getting the previous value of the clipboard before the system is able to update that value.

ClipWait is a command you may be interested in.

It could be a problem of the Ctrl+C or whichever approach to copying you use in your target program not registering immediately.
Hybridnyckel
Posts: 11
Joined: 24 May 2017, 08:53

Re: Var doesn't update when label re-run

16 Aug 2017, 01:46

Yep. It can't be the clipboard not updating. As I said, the clipboard is used to get a lot of other vars, and is used many times before it is used for this particular var again. Still this particular var seems sometimes stuck, or jump back, to it's previous value. To be sure the clipboard is emptied and then assigned I started to use the following:

Code: Select all

clipboard =
If clipboard is not space
	MsgBox Error! clipboard = %clipboard%.
Send, {Home}{Down 3}^{Right}^+{Left}^c
ClipWait
If clipboard is space
	MsgBox Error!
 
This doesn't seem to help though. As you can see I'm also using ClipWait, the code in the first post wasn't from the actual script, I just wanted to show that it's under a label that's being re-run over and over like a pseudo-loop. For each time it's opens a new url and doing the ^a^c thing. Everything works fine except this var, that fails maybe 1 time out of 20. And I haven't messed up the labels and gotos so that these rows can be missed.
User avatar
Exaskryz
Posts: 2882
Joined: 17 Oct 2015, 20:28

Re: Var doesn't update when label re-run

16 Aug 2017, 12:51

You're using gotos? Sometimes logic gets a bit sloppy on that, I would recommend GoSub instead. But it may require reworking the logic of your code to accommodate it.

But that's probably nothing to do with the var not updating.

I haven't heard of a variable failing to update like you describe. It's probably something in a larger context that we'd need to see to think "Ah ha, that could be a problem." As it is, I would think if this label is being run by SetTimer there's a synchronization issue. But you didn't mention that one, so I am at a loss for an explanation of what is going on and how it might be resolved.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Descolada, Google [Bot], Lamron750 and 225 guests