When using Ternary Operators, is it possible to also assign a value to another variable? Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Gary-Atlan82
Posts: 74
Joined: 07 Mar 2023, 05:20

When using Ternary Operators, is it possible to also assign a value to another variable?

Post by Gary-Atlan82 » 27 Mar 2023, 06:46

I tried the following:

Code: Select all

Hello := "Hello World"
Test := Hello ~= "Hello" ? "Yes, Match!" (Word_Count := 2) : "No Match!"
OutputDebug, % "Test : "Test
OutputDebug, % "Word count is : "Word_Count
The console looks like:

Code: Select all

Test : Yes, Match!2
Word count is : 2
It seems that word_count does get assigned 2 but the value 2 is also added to Test, is it not possible to get a result that looks like this?

Code: Select all

Test : Yes, Match!
Word count is : 2
Any help would be greatly appreciated!

cat dog fox war
Posts: 38
Joined: 15 Mar 2023, 10:18

Re: When using Ternary Operators, is it possible to also assign a value to another variable?  Topic is solved

Post by cat dog fox war » 27 Mar 2023, 06:56

Code: Select all

Hello := "Hello World"
Test := Hello ~= "Hello" ? ("Yes, Match!", Word_Count := 2): "No Match!"
OutputDebug, % "Test : " Test
OutputDebug, % "Word count is : " Word_Count
Parentheses and commas


Post Reply

Return to “Ask for Help (v1)”