Directive if question (#IF) Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
frd
Posts: 42
Joined: 19 Jul 2018, 10:01

Directive if question (#IF)

20 Jun 2019, 15:14

Hello there! I have two interfaces to deal with: one for each language. I tried to do the following:

Code: Select all

language = 1

#if (language = 1)
a::b

#if (language = 2)
a::c
And it doesn't work. What am I doing wrong? Also, is this the ideal approach to this problem? Thanks in advance!
User avatar
Hellbent
Posts: 2109
Joined: 23 Sep 2017, 13:34

Re: Directive if question (#IF)  Topic is solved

20 Jun 2019, 15:22

Seems to work for me.

Code: Select all


#SingleInstance,Force

language := 1

Numpad1::   ;< swap
	language := (language=1)?(2):(1)
	return

#if (language = 1)
a::b

#if (language = 2)
a::c

#if

Esc::ExitApp


Do you have other code not shown?
frd
Posts: 42
Joined: 19 Jul 2018, 10:01

Re: Directive if question (#IF)

20 Jun 2019, 16:16

Yes I do have code not shown. But there are no directives before that one, only two functions and a few hotkeys. I tried again and put the [variable := 1] in the very beginning of the code and now it´s working! So this is a solved issue now. Thanks for helping me out. Also, Ive been learning a lot with your tutorials, youve helped me a lot already :D :D :D

When I tried to assign a value to the variable exactly before the #if directive, it didnt work. Maybe some conflict that I can´t understand now. Again, thanks for taking your time to help!!! =D
User avatar
Hellbent
Posts: 2109
Joined: 23 Sep 2017, 13:34

Re: Directive if question (#IF)

20 Jun 2019, 16:56

frd wrote:
20 Jun 2019, 16:16
I tried again and put the [variable := 1] in the very beginning of the code and now it´s working! So this is a solved issue now.
Hi frd.
Have a read through this. It should clear up what was happening.


The Top of the Script (the Auto-execute Section)


***Edit***
Ok I just had a quick read through of the section I just posted and it doesn't really explain what I said it will explain lol.

The short of it is that after the auto-execute section. only code contained in labels, functions, hotkeys, hotstrings, etc will ever have a chance to get ran.
So if your [Var :=1] was sitting all alone in your code after the auto-execute section, it would never get any love.
frd
Posts: 42
Joined: 19 Jul 2018, 10:01

Re: Directive if question (#IF)

20 Jun 2019, 20:41

This is world-class help. Now I can fully understand why it didnt work! Yes, my variable was in the middle of the script... Getting no love haha thanks again!

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: doodles333, wilkster and 326 guests