2

I am trying to create a string array in Imacros, and then get a string value and store in var 2, so that i can use a different (random value) each time.

but when i write this, I have the error on second line:

SET !VAR1 EVAL("var config = ['myConfigParameter1', '500', '4.1234213', 'http://an.url/'];config.join(';')")
SET !VAR2 EVAL("var config = '{{!VAR2}}'.split(';');config[0]")

Iam trying to run it in Imacros firefox and on running this it gives error on second line stating:

s is undefined, line: 7 (Error code: -1001)

I followed this tutorial to get a string value from array in imacros. http://www.iteamwork.de/imacros-scripting-use-more-than-x-variables-in-macro-script.html

What is wrong with that line?

How can i retrieve a random string and store in var2 so that i can use it in my imacros code ?

I also tried doing it core JS way by creating a separate js file but that didnt work either.

UPDATE:

Here is the full code:

VERSION BUILD=9030808 RECORDER=FX
SET !VAR1 EVAL("var config = ['myConfigParameter1', '500', '4.1234213', 'http://an.url/'];config.join(';')")
SET !VAR2 EVAL("var config = '{{!VAR2}}'.split(';');config[0]")
TAB T=1
wait seconds = 7
'TAG POS=1 TYPE=TEXTAREA ATTR=ID:chatmsg CONTENT=TestMessge
TAG POS=1 TYPE=TEXTAREA ATTR=ID:chatmsg CONTENT={{!VAR2}}
TAG POS=1 TYPE=INPUT:BUTTON ATTR=ID:sendbtn
wait seconds = 2
ONDIALOG POS=1 BUTTON=OK CONTENT=
wait seconds = 1
TAG POS=1 TYPE=INPUT:BUTTON ATTR=ID:disconnectbtn
ONDIALOG POS=1 BUTTON=OK CONTENT=
wait seconds = 2
ONDIALOG POS=1 BUTTON=OK CONTENT=
wait seconds = 1
TAG POS=1 TYPE=INPUT:BUTTON ATTR=*
ONDIALOG POS=1 BUTTON=OK CONTENT=

And here is my random line:

SET randomNumber EVAL("var min = 0; var max = 4; var randomNumber = Math.floor(Math.random() * (max - min + 1)) + min; randomNumber;")
SET !VAR2 EVAL("var config = '{{!VAR1}}'.split(';');config[{{randomNumber }]")

Random number is working fine but i dont know how to use the randomnumb variable inside the array to get random string. problem is in 2nd line now.

3
  • I don't see an "s" defined anywhere in your code; is that the full code of your script? Just those two lines? If not, please include the rest. Commented Oct 29, 2016 at 19:35
  • @jack i just added my complete code, my code runs perfect if I comment out that line 3. the problem is with that line Commented Oct 29, 2016 at 19:41
  • Can you clarify what the problem is now? Are you getting an error message, and is there some way you can view what values randomNumber is being evaluated to, to be sure it's actually working? (A console.log or printing it to the screen or something?) Commented Oct 29, 2016 at 20:29

1 Answer 1

1
SET !VAR2 EVAL("var config = '{{!VAR2}}'.split(';');config[0]")

I think you meant for this to join the array var you just set, right? So it would be:

SET !VAR2 EVAL("var config = '{{!VAR1}}'.split(';');config[0]")
Sign up to request clarification or add additional context in comments.

5 Comments

Perfect man, this works! let me just add the random number logic so that each time my loop works, it should get a random string from the array. I will then give ur answer as best :) Is there any place where i can learn imacros?
do you know how to use imacros with separate JS files? any working demo?
Haven't actually worked with iMacros myself, just recognized the JS issue. But for javascript documentation, MDN is a very good place to look. Here's their page on javascript arrays, for example (like your "config" one).
I am just updating my code to generate a random number and then use it in my array to get a random string, can u have a look it ?
Sure, you can add it to the original post - easier to read there than in comments.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.