Reputation: 281
I currently make a iMacro script that use ImageSearch to find the image and perform other function. If the image1 match imagesearch then perform task1, else if perform task2.
If IMAGESEARCH POS=1 IMAGE=IMAGE1.png CONFIDENCE=65
TAG POS=1 TYPE=INPUT:TEXT ATTR=ID:bet-amount CONTENT=0.01
TAG POS=1 TYPE=BUTTON:SUBMIT ATTR=ID:bet-bt
Else If IMAGESEARCH POS=1 IMAGE=IMAGE2.png CONFIDENCE=65
TAG POS=1 TYPE=BUTTON:SUBMIT ATTR=ID:bet-multiplier
TAG POS=1 TYPE=BUTTON:SUBMIT ATTR=ID:bet-bt
How can I make the if statement ?
Upvotes: 3
Views: 24890
Reputation: 700
"there is no IF ELSE statement in imacros – Bestmacros Oct 31 '13 at 8:01"
=> Indeed, but "You have to use JavaScript scripting." is incorrect...! You can achieve some Conditional Behaviour like in this Case in pure '.iim':
SET !ERRORIGNORE YES
SET !TIMEOUT_STEP 0
IMAGESEARCH POS=1 IMAGE=IMAGE1.png CONFIDENCE=65
SET ClickAmount EVAL("var y='{{!IMAGEY}}'; var z; if(y>0){z=1;} else{z=0;}; z;")
TAG POS={{ClickAmount}} TYPE=INPUT:TEXT ATTR=ID:bet-amount CONTENT=0.01
TAG POS={{ClickAmount}} TYPE=BUTTON:SUBMIT ATTR=ID:bet-bt
IMAGESEARCH POS=1 IMAGE=IMAGE2.png CONFIDENCE=65
SET ClickMultiplier EVAL("var y='{{!IMAGEY}}', a='{{ClickAmount}}'; var z; if(a==1){z=0;} else if(y>0){z=1;} else{z=0;}; z;")
TAG POS={{ClickMultiplier}} TYPE=BUTTON:SUBMIT ATTR=ID:bet-multiplier
TAG POS={{ClickMultiplier}} TYPE=BUTTON:SUBMIT ATTR=ID:bet-bt
=> All the 'IF/ELSE' Logic in one single '.iim' Macro, very similar to @OP's original Script, and will work directly in iMB or IE, instead of using 4 Scripts requiring a main '.js' Script that will only work in FF...!
(Not tested, I've never used 'IMAGESEARCH' as I only use the free Add-on (with FF), according to the Wiki, '!IMAGEX' and '!IMAGEY' are supposed to hold the Coordinates if the Image is found and I suppose valid Coordinates must be >0, at least for '!IMAGEY'. The '!IMAGEX' and '!IMAGEY' Variables may need to be reset to 'NULL' before the 2nd 'IMAGESEARCH' if it doesn't occur automatically... (I cannot test...))
Upvotes: 1
Reputation: 3547
You have to use JavaScript scripting. You have an example here
Loop in Imacros using Javascript
In your case this would be first macro
IMAGESEARCH POS=1 IMAGE=IMAGE1.png CONFIDENCE=65
This would be second macro
IMAGESEARCH POS=1 IMAGE=IMAGE2.png CONFIDENCE=65
This would be third macro.
TAG POS=1 TYPE=INPUT:TEXT ATTR=ID:bet-amount CONTENT=0.01
TAG POS=1 TYPE=BUTTON:SUBMIT ATTR=ID:bet-bt
And this would be fourth macro.
TAG POS=1 TYPE=BUTTON:SUBMIT ATTR=ID:bet-multiplier
TAG POS=1 TYPE=BUTTON:SUBMIT ATTR=ID:bet-bt
So this is how it's supposed to look like.
if(iimPlay(macro1)>0)
{
iimPlay(macro3)
}
else if(iimPlay(macro2)>0)
{
iimPlay(macro4)
}
Upvotes: 3