Traytip, variables, and little help with If arguments

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
LiveFyre
Posts: 3
Joined: 23 Jul 2016, 02:30

Traytip, variables, and little help with If arguments

23 Jul 2016, 02:43

So, I'm trying to do a very simple test script. I already have the code to set the variables using ImageSearch, but I'm wondering if I can do this somehow..

Code: Select all

Traytip, Test, "I am seeing " If VariableOne = 1 { %VariableOne% } Else If VariableTwo = 1 { %VariableTwo% } " on screen currently.
Or would it be better (and by that, I mean comparatively less code) to just set multiple possible Traytips based on which variable isn't 0?

Also, I have done some scripting work in Lua before.. does ahk have anything that would look like..

Code: Select all

if(Variable==[amount] { do this } else { do that }
Or am I already close? If/Else haven't been kind to me in this program. x_x
User avatar
Masonjar13
Posts: 1555
Joined: 20 Jul 2014, 10:16
Location: Не Россия
Contact:

Re: Traytip, variables, and little help with If arguments

23 Jul 2016, 04:33

If statements are not contained on one line.

Code: Select all

if(variable=amount){
; do stuff
}else{
; do other stuff
}
Read through the tutorial to understand the syntax.
Last edited by Masonjar13 on 23 Jul 2016, 19:25, edited 2 times in total.
OS: Windows 10 Pro | Editor: Notepad++
My Personal Function Library | Old Build - New Build
wolf_II
Posts: 2688
Joined: 08 Feb 2015, 20:55

Re: Traytip, variables, and little help with If arguments

23 Jul 2016, 07:22

Try this:

Code: Select all

Var1 = 1 ; (un)comment this line
Var2 = 1
TrayTip, Test, % "I am seeing " (Var1=1 ? "Var1" : Var2=1 ? "Var2" : "neither") " on screen currently."
MsgBox,,,, 5
I hope that helps.
LiveFyre
Posts: 3
Joined: 23 Jul 2016, 02:30

Re: Traytip, variables, and little help with If arguments

23 Jul 2016, 13:13

Ahhh, thank you wolf! That's perfect.

Mason, I had already tried something like that. Maybe I need to update my AHK version? It kept complaining about not being able to find the initial If when I did as you're suggesting.. and when I tried to have the bracket on the same line as the If.

Edit: Okay.. after putting the snippit into actual testing (and getting some sleep which I'm sure made a difference), I wanted to ask, is there a way to have it output the variable as plain text, or skip it if nothing is found? Like..

Code: Select all

TrayTip, Test, % "I am seeing " (var1? "%var1%" : "nothing") " on screen currently."
where Var1 is set earlier in the code via ImageSearch functionality, up to 3. Or do I have to break that up into 3 separate variables and have the traytip check for each? Trying to avoid the latter because that just feels like sloppy code. =\
hunter99
Posts: 129
Joined: 20 Jan 2014, 17:57

Re: Traytip, variables, and little help with If arguments

23 Jul 2016, 15:00

Hi LiveFyre;
Maybe this? This will show you what is in the Vars, I take it that is is what you want to know.

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
Var1 = 3 ; (un)comment this line
Var2 = 2
TrayTip, Test, I am seeing Var1 = %Var1%`nI am seeing Var2 = %Var2% 

;the %Vars% gives the contents. Show as many Vars as you want.
;change the text to what you want, the `n gives a new line, leave out for one lone line.

MsgBox,,,, 5

hunter99

EDIT: Reread your orig. post, think maybe you are going to check a ton of vars.
If so you may be better off doing the logic in the script , loading result to a var and using that in TrayTip.
Guess what I would like to know is how many variables will you want to look at.
User avatar
Masonjar13
Posts: 1555
Joined: 20 Jul 2014, 10:16
Location: Не Россия
Contact:

Re: Traytip, variables, and little help with If arguments

23 Jul 2016, 17:52

LiveFyre wrote:

Code: Select all

TrayTip, Test, % "I am seeing " (var1? "%var1%" : "nothing") " on screen currently."
Close.

Code: Select all

TrayTip, Test, % "I am seeing " (var1? var1 : "nothing") " on screen currently."
OS: Windows 10 Pro | Editor: Notepad++
My Personal Function Library | Old Build - New Build
lexikos
Posts: 9583
Joined: 30 Sep 2013, 04:07
Contact:

Re: Traytip, variables, and little help with If arguments

23 Jul 2016, 18:50

Masonjar13 wrote:If statements are not contained on one line.
...
AHK is a C/C++ written interpreter, and the methodology has close similarities.
That's confusing. I suppose you mean "The AHK interpreter was written in C++", but that's irrelevant - it could be written in C or ASM and still parse exactly the same syntax. I would not assume that the language was in any way based on C/C++ just because the program was written in C++.

The AutoHotkey language has some similarities to C/C++, but bringing that up here makes little sense. C/C++ does not require you to use line breaks in most cases.
User avatar
Masonjar13
Posts: 1555
Joined: 20 Jul 2014, 10:16
Location: Не Россия
Contact:

Re: Traytip, variables, and little help with If arguments

23 Jul 2016, 19:24

lexikos wrote:That's confusing. I suppose you mean "The AHK interpreter was written in C++", but that's irrelevant - it could be written in C or ASM and still parse exactly the same syntax. I would not assume that the language was in any way based on C/C++ just because the program was written in C++.

The AutoHotkey language has some similarities to C/C++, but bringing that up here makes little sense. C/C++ does not require you to use line breaks in most cases.
That is what I meant, and no, it doesn't make sense. I felt like I meant to add to that (more specific), but I forgot to? I don't remember. I'll redact that.
OS: Windows 10 Pro | Editor: Notepad++
My Personal Function Library | Old Build - New Build

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: doodles333, Frogrammer and 272 guests