Page 1 of 1

Using variables

Posted: 20 Oct 2017, 07:07
by carthagod
Hi!

Just discovered AutoHotKey and it's fantastic!
I'm trying to write some scripts and I have a very basic problem: I don't understand how variables are supposed to work. I HAVE seen the page https://autohotkey.com/docs/Variables.htm but it doesn't help me.

In ording to test setting and retrieving a variable, I'm trying to set a certain value (ex:12) to a variable, then display it in a message box when hotkey pressed. Here's what I have:

Code: Select all

MyVar:=12
^F4:: MsgBox, %MyVar%
If I do so, the Message box displays an empty value.

Can someone please explain more clearly than the documentation how variables are supposed to work?

Thanks !!
Best,
Thomas

NB : I'm not a dev nore a super-geek so don't hesitate to be very basic in your explanations. I do have some programming notions though, so not problem with the concept of variable itself.

Re: Using variables

Posted: 20 Oct 2017, 07:14
by Helgef
Hello and welcome.
There is nothing wrong with your script. It displays 12 in the message box. If that code is part of a larger script, you need to consider the auto execute section. Also, see the tutorial.

Re: Using variables

Posted: 21 Oct 2017, 03:14
by carthagod
OK I get it. Thanks a lot Helgef !