AutoHotkey Community

It is currently May 26th, 2012, 7:20 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: Global Variables...
PostPosted: May 24th, 2008, 3:17 am 
Offline

Joined: May 24th, 2008, 1:27 am
Posts: 6
Hello all. Got a few questions, let's start with this one:

Code:
#persistent
#singleInstance

SetTimer, DoSomething, 3000
PauseDoSomething := NO

return


^#D::
  if (PauseDoSomething == NO)
    PauseDoSomething := YES
  else
    PauseDoSomething := NO
return

DoSomething:
  if (PauseDoSomething == YES)
    return

  ; Do Something Useful
  ...

return


In the above example, when ^#D is pressed or the timer triggers and DoSomething is executed, the variable PauseDoSomething is always empty. Any idea as to why that would be? It's first created and accessed in the Auto-Execute section, so it should be persistent at any point, or am I missing something?

Regards,
JHeikkilaJr[/code]


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 24th, 2008, 3:39 am 
If you use ":=" to define a variable, it's an expression... you have to enclose text in quotes
Code:
var := "text"
var = text


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: May 24th, 2008, 4:53 am 
Offline

Joined: April 28th, 2008, 2:55 pm
Posts: 48
I added quotes where needed and removed the double =

Give this a try (I did not test):

Code:

#persistent
#singleInstance

SetTimer, DoSomething, 3000
PauseDoSomething := "NO"

return


^#D::
  if (PauseDoSomething = "NO")
    PauseDoSomething := "YES"
  else
    PauseDoSomething := "NO"
return

DoSomething:
  if (PauseDoSomething = "YES")
    return

  ; Do Something Useful
  ...

return


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 24th, 2008, 12:17 pm 
Offline

Joined: May 24th, 2008, 1:27 am
Posts: 6
Unfortunately, I looked at my real code when I got home and it turns out that i use = instead of := in the assignments. Therefore, the literal quotes are not necessary, right?

Also, my If expressions use ==. Should I change them?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 24th, 2008, 5:26 pm 
Code:
If (Expression)

when you use If statements whatever is in parentheses is an expression so quotes are necessary in this case
the only difference between == and = is that == is case sensitive


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: May 24th, 2008, 6:53 pm 
Offline

Joined: April 28th, 2008, 2:55 pm
Posts: 48
Thanks - did not know that.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: bobbysoon, kkkddd1, tomL and 69 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group