Page 1 of 1

Traytip, variables, and little help with If arguments

Posted: 23 Jul 2016, 02:43
by LiveFyre
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

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

Posted: 23 Jul 2016, 04:33
by Masonjar13
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.

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

Posted: 23 Jul 2016, 07:22
by wolf_II
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.

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

Posted: 23 Jul 2016, 13:13
by LiveFyre
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. =\

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

Posted: 23 Jul 2016, 15:00
by hunter99
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.

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

Posted: 23 Jul 2016, 17:52
by Masonjar13
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."

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

Posted: 23 Jul 2016, 18:50
by lexikos
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.

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

Posted: 23 Jul 2016, 19:24
by Masonjar13
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.