Loop script until...

Discussions and Tech Support related to the iMacros Firefox Add-on, including the built-in Javascript scripting interface for playing .js files.
Forum rules
Before asking a question or reporting an issue:
1. Please review the list of FAQ's.
2. Use the search box (at the top of each forum page) to see if a similar problem or question has already been addressed.
3. Try searching the iMacros Wiki - it contains the complete iMacros reference as well as plenty of samples and tutorials.
4. We can respond much faster to your posts if you include the following information: CLICK HERE FOR IMPORTANT INFORMATION TO INCLUDE IN YOUR POST
ssjmaz
Posts: 6
Joined: Sat Aug 13, 2011 5:21 pm

Loop script until...

Post by ssjmaz » Sat Aug 13, 2011 5:27 pm

I'm on a website with javascript and i use imacros to click on a certain button, this i solved, easy enough, but i want the script to stop when a number appears and it's a number between to values lets say the script should stop if in a certain zone of the website a number between 1 and 10 should appear is this possible?
pmwfilm
Posts: 12
Joined: Wed Aug 10, 2011 3:59 am

Re: Loop script until...

Post by pmwfilm » Sat Aug 13, 2011 11:50 pm

T?hat is going to require a batch list in Javascript. iMacros does not have conditional statements. you are looking at something like this...

Code: Select all

while (extracted >=1<=10)
{
iimPlay("CODE: insert the imacro code for clicking the button here")
iimPlay("CODE: insert iMacros code fro text area you are trting to get the value of here :* EXTRACT=TXT")
extracted = iimGetLastExtract (extracted)
}


This will loop until it is between 1 & 10.
I don't have any way to test the code so let me know how it goes.
ssjmaz
Posts: 6
Joined: Sat Aug 13, 2011 5:21 pm

Re: Loop script until...

Post by ssjmaz » Sun Aug 14, 2011 2:12 pm

This is my code:

Code: Select all

    while (extracted >=1<=10)
    {
    iimPlay("CODE: TAB T=1
TAG POS=1 TYPE=IMG ATTR=SRC:button.gif
wait seconds=1")
    iimPlay("CODE: Level: :* EXTRACT=TXT")
    extracted = iimGetLastExtract (extracted)
    }

And i get error: "SyntaxError: unknown command: WHILE, line: 1 (Error code: -910)
User avatar
322126384
Posts: 32
Joined: Sat Jul 23, 2011 1:39 am

Re: Loop script until...

Post by 322126384 » Sun Aug 14, 2011 7:42 pm

Here is my code:

Code: Select all

while (extracted >=1<=10)
{
iimPlay("CODE: REFRESH")
iimPlay("CODE: TAG POS=1 TYPE=P ATTR=TXT:"Level:<SP>*"* EXTRACT=TXT")
extracted = iimGetLastExtract (extracted)
}
But I get this error:

SyntaxError: missing ) after argument list (Error code: 991)

I'm new to javascript, but i tried adjusting the script but it didn't help.
-322126384
pmwfilm
Posts: 12
Joined: Wed Aug 10, 2011 3:59 am

Re: Loop script until...

Post by pmwfilm » Mon Aug 15, 2011 3:12 am

Ok a few different problems her. First you have to define extracted before you go into the while loop (my fault for not putting that in my code). Second, line 4 is a mess and im not exactly sure what you are trying to do. Third, anything in the iimPlay() has to be on one line. Use \n to change lines.

So lets see if this gets us any closer.

Code: Select all

var extracted = null;
while (extracted >=1<=10)
{
iimPlay("CODE: REFRESH")
iimPlay("CODE: TAG POS=1 TYPE=P ATTR=TXT:Level:* EXTRACT=TXT")
extracted = iimGetLastExtract (extracted)
}
now this code is not clicking a button. its just refreshing. Is that what you want? Refreshing is going to be much slower than just pressing a button. Im guessing you are trying to do this.

Code: Select all

extracted = null;
    while (extracted >=1<=10)
    {
    iimPlay("CODE: TAB T=1\n TAG POS=1 TYPE=IMG ATTR=SRC:button.gif\n wait seconds=1")
    iimPlay("CODE: TAG POS=1 TYPE=P ATTR=TXT:Level:* EXTRACT=TXT")
    extracted = iimGetLastExtract (extracted)
    }
I don't know what the site looks like so this all kind of a guessing game. To make this a bit easier record a macro where you click the button and then click the number that you are trying to extract. So i can see the specific actions or just send me link to the site.
ssjmaz
Posts: 6
Joined: Sat Aug 13, 2011 5:21 pm

Re: Loop script until...

Post by ssjmaz » Mon Aug 15, 2011 9:17 am

The website is: www.pokemonvortex.org and i need a macro for the map part to find legendary pokemons , the macro needs to click on the move button and when it encounters a legendary pokemon should stop , normal pokemon have a level between 8 and 15 and legendary pokemons have a level between 50 and 100, these level are found on the map. So i want this macro to stop the looped clicking of the move button when on screen appears a pokemon with level between 50 and 100.
pmwfilm
Posts: 12
Joined: Wed Aug 10, 2011 3:59 am

Re: Loop script until...

Post by pmwfilm » Tue Aug 16, 2011 2:10 am

I don't have an account so I can't see any of that. Just record a macro where you click the button and then click the number that you are trying to extract and post it and im sure we can figure this out.
User avatar
322126384
Posts: 32
Joined: Sat Jul 23, 2011 1:39 am

Re: Loop script until...

Post by 322126384 » Tue Aug 16, 2011 2:46 am

what a coincidence, i am using the same website. here is the recorded macro like you requested

Code: Select all

VERSION BUILD=7300701 RECORDER=FX
TAB T=1
TAG POS=1 TYPE=IMG ATTR=SRC:http://static.pokemonvortex.org/images/maps/arrows/arrowup.gif
TAG POS=1 TYPE=P ATTR=TXT:Level:<SP>13
The part where it says arrowup there are 7 other options. it is actually just an image ( Image) that navigates your sprite up on the map.
-322126384
pmwfilm
Posts: 12
Joined: Wed Aug 10, 2011 3:59 am

Re: Loop script until...

Post by pmwfilm » Tue Aug 16, 2011 8:19 am

Ok great, lets try this.

Code: Select all

var pokLevel = null;
while (pokLevel >=50<=100)
{
iimPlay("CODE: TAG POS=1 TYPE=IMG ATTR=SRC:http://static.pokemonvortex.org/images/maps/arrows/arrowup.gif");
iimPlay("CODE: TAG POS=1 TYPE=P ATTR=TXT:Level:* EXTRACT=TXT");
pokLevel = iimGetLastExtract ();
}
alert("Encountered a Legendary Pokemon. Level " + pokLevel);  
I think we've got it with this one. One of you test it on the site and let me know.
ssjmaz
Posts: 6
Joined: Sat Aug 13, 2011 5:21 pm

Re: Loop script until...

Post by ssjmaz » Tue Aug 16, 2011 10:35 am

In firefox i'm getting the same error as my previous posts.
"SyntaxError: unknown command: WHILE, line: 1 (Error code: -910)

When i try to run this macro in iMacros browser it doesn't do anything i click play and nothing really happens.
Tom, Tech Support
Posts: 3527
Joined: Mon May 31, 2010 4:59 pm

Re: Loop script until...

Post by Tom, Tech Support » Tue Aug 16, 2011 1:32 pm

ssjmaz wrote:In firefox i'm getting the same error as my previous posts.
"SyntaxError: unknown command: WHILE, line: 1 (Error code: -910)

When i try to run this macro in iMacros browser it doesn't do anything i click play and nothing really happens.
Make sure the file is saved as a .js file and not .iim. This is Javascript code and not macro code. The Javascript code is calling the macros via the built-in Javascript scripting interface.
Regards,

Tom, iMacros Support
User avatar
322126384
Posts: 32
Joined: Sat Jul 23, 2011 1:39 am

Re: Loop script until...

Post by 322126384 » Tue Aug 16, 2011 6:11 pm

the script is not working. even though the string "Level: 88" appeared, the script continued, if anything it sped up. Which is kind of odd. I dont know what's wrong, i just copy and pasted the script you wrote, into a .js file and played it.
-322126384
User avatar
322126384
Posts: 32
Joined: Sat Jul 23, 2011 1:39 am

Re: Loop script until...

Post by 322126384 » Tue Aug 16, 2011 10:43 pm

It took me about 3 hours of searching but then it hit me. why not just use the SEARCH command. It has REGEXP. Here is a code i wrote:

Code: Select all

TAG POS=1 TYPE=IMG ATTR=SRC:http://static.pokemonvortex.org/images/maps/arrows/arrowup.gif
SET !ERRORIGNORE YES
SEARCH SOURCE=REGEXP:"Level: ([4-9]{2})" EXTRACT=$1
SET !ERRORIGNORE NO
TAG POS=1 TYPE=P ATTR=TXT:Level:<SP>{{!EXTRACT}} CONTENT=EVENT:FAIL_IF_FOUND
the code clicks on the up arrow. then it searches for Level: 44-99. then it is passed to the TAG command which encorporates the FAIL_IF_FOUND event and looks in the html elements for "Level: (whichever number between 44-99 was found)".

This code is not tested yet so i'll be doing that now. i'll get back to you with the results. hopefully it works!
-322126384
User avatar
322126384
Posts: 32
Joined: Sat Jul 23, 2011 1:39 am

Re: Loop script until...

Post by 322126384 » Wed Aug 17, 2011 1:02 am

i just tested the macro and it runs perfectly. I just caught 3 legendary pokemon! :D Good Luck Catching Pokemon!!
-322126384
MattBell7
Posts: 627
Joined: Thu Nov 26, 2009 11:07 am
Location: United Kingdom

Re: Loop script until...

Post by MattBell7 » Wed Aug 17, 2011 6:57 am

your regex is wrong [4-9]{2} will match 44-49, 54-59, ..94-99

you need ([5-9][0-9]) which will match 50-99
Post Reply