IF / ELSE statement

Get help with using AutoHotkey and its commands and hotkeys
euras
Posts: 338
Joined: 05 Nov 2015, 12:56

IF / ELSE statement

Post by euras » 21 Nov 2017, 07:07

A simple question why the first example works and the second one not?

Code: Select all

uf = 1
If (uf = 1)
   uf = New Text
ufa := uf
MsgBox % ufa ; this one works

Code: Select all

uf = 1
ufa := (uf = 1)?(uf = New Text):("") ; this one doesn't give me any value
MsgBox % ufa
While this example works..

Code: Select all

count = 5
 result := (count > 2 and count < 10)?(count + 3):(count <= 2)?(count - 1):("10")
 MsgBox % result
User avatar
divanebaba
Posts: 743
Joined: 20 Dec 2016, 03:53
Location: Diaspora

Re: IF / ELSE statement

Post by divanebaba » 21 Nov 2017, 07:34

ufa := (uf = 1)?(ufa = New Text):("") ; this one doesn't give me any value

This (ufa = New Text) is not a value, string or something else, you can store in a variable.

Try this:

Code: Select all

uf = 1
ufa := (uf = 1)?("New Text"):("") ; this one will give you a value
MsgBox % ufa
return
"New Text" is storable into a variable.
[Starklichtbirne IQ >> 250!!] Dank deutscher Lehrerempfehlung, nur Süperdepp und Hartz4-Bezieher, statt Abitürient und Einkommensbezieher.
[Strong light bulb IQ >> 250!!] Thanks to german teacher's recommendation, willful and welfare recipient, instead of high school graduate and moneymaker.

Entering high school for foreign children is not prohibited in GERMANY, it's only made nearly impossible by government.
Virtually the only way - visiting high school abroad.

ADVERTISING: Patent pending strip accumulator - süper advanced technology - priceless inexpensive, space-saving, energy efficient - Patent priority for sale.
euras
Posts: 338
Joined: 05 Nov 2015, 12:56

Re: IF / ELSE statement

Post by euras » 21 Nov 2017, 16:34

so using this method I cannot create a new variable, just change the active one?
A_AhkUser
Posts: 872
Joined: 06 Mar 2017, 16:18
Location: France

Re: IF / ELSE statement

Post by A_AhkUser » 21 Nov 2017, 16:58

Code: Select all

var = true ; string 'true'
MsgBox % var
var := "true" ; the colon-equal operator evaluates an expression and stores the result in a variable; in this case, everything that is not encloed in quotes is supposed to be the name of a variable
MsgBox % var
var := true ; true as boolean value using thecolon-equal operator - displays 1
MsgBox % var

x := (var) ? ("True", newvar:=functiontest()) : ("False", newvar:=400) ; if var is true x will be set to the string "True" and newvar will be set to the value returned by the function "functiontest"
MsgBox % x
MsgBox % newvar
x := (not var) ? ("True", newvar:=functiontest()) : ("False", newvar:=400) ; if var is false x will be set to the string "False" and newvar will be set to 400
MsgBox % x
MsgBox % newvar


functiontest() {
return "Hello, world!"
}
[url=https://autohotkey.com/boards/viewtopic.php?f=56&p=215673#p215673][b][font=Segoe UI][color=#1ea2db]Video Game[/color] [color=#bbbbbb]Reader[/color][/font][/b][/url] eAutocomplete

euras
Posts: 338
Joined: 05 Nov 2015, 12:56

Re: IF / ELSE statement

Post by euras » 22 Nov 2017, 12:22

thank you! now it makes sense for me :)
Post Reply

Return to “Ask For Help”