Javascript inside imacros script

Discussions and Tech Support related to automating the iMacros Browser or Internet Explorer from any scripting and programming language, such as VBS (WSH), VBA, VB, Perl, Delphi, C# or C++.
Forum rules
Before asking a question or reporting an issue:
1. Please review the list of FAQ's.
2. Use the Google search box (at the top of each forum page) to see if a similar problem or question has already been addressed. This will search the entire contents of the forums as well as the iMacros Wiki.
3. We can respond much faster to your posts if you include the following information:

CLICK HERE FOR IMPORTANT INFORMATION TO INCLUDE IN YOUR POST

Answering your own posts (e.g. attempting to "bump" your topic) drops your topic from the list of unanswered threads, so it may actually receive less views.

Javascript inside imacros script

by sc4rface on Tue Jan 16, 2018 2:07 am

I wrote small script to flash game with imacros. I must use this script inside javascript. My code looks like this, but imacros returns error like this: "Error -1100: Unknown command: VAR at line: 1" Additionaly i must to use AJAX to get values from local file and two arrays to switinch current value filling to form.

What's wrong? I can not use javascript this way?

Code: Select all
var messages = ["hello", "hi", "welcome"];
var nicknames = [];
var currentNick;
var currentMsg;
var msgNumber;

if (window.XMLHttpRequest) {
  xmlhttp = new XMLHttpRequest();
} else {
  xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}

xmlhttp.open("GET", "/herozero-scraper/nicknames.txt", false);
xmlhttp.send();
file = xmlhttp.responseText;
nicknames = file.split(',');

for (i = 0; i < nicknames.length; i++) {
  msgNumber = Math.floor(Math.random() * messages.length);
  currentNick = nicknames[i];
  currentMsg = messages[msgNumber];
  var macro = "CODE:";
  macro += "VERSION BUILD=12.0.501.6698" + "\n";
  macro += "TAB T=1" + "\n";
  macro += "TAB CLOSEALLOTHERS" + "\n";
  macro += "'SET !PLAYBACKDELAY 0.00" + "\n";
  macro += "SIZE X=1340 Y=902" + "\n";
  macro += "WAIT SECONDS=1" + "\n";
  macro += "DS CMD=MOVETO X=266 Y=757 CONTENT=" + "\n";
  macro += "WAIT SECONDS=1" + "\n";
  macro += "DS CMD=LDOWN X=266 Y=757 CONTENT=" + "\n";
  macro += "WAIT SECONDS=1" + "\n";
  macro += "DS CMD=LUP X=266 Y=757 CONTENT=" + "\n";
  macro += "SIZE X=1340 Y=902" + "\n";
  macro += "WAIT SECONDS=1" + "\n";
  macro += "DS CMD=LDOWN X=535 Y=293 CONTENT=" + "\n";
  macro += "WAIT SECONDS=1" + "\n";
  macro += "DS CMD=LUP X=535 Y=293 CONTENT=" + "\n";
  macro += "WAIT SECONDS=1" + "\n";
  macro += "DS CMD=KEY X=535 Y=293 CONTENT=" + currentNick + "" + "\n";
  macro += "SIZE X=1340 Y=902" + "\n";
  macro += "WAIT SECONDS=1" + "\n";
  macro += "DS CMD=LDOWN X=492 Y=389 CONTENT=" + "\n";
  macro += "WAIT SECONDS=1" + "\n";
  macro += "DS CMD=LUP X=492 Y=389 CONTENT=" + "\n";
  macro += "WAIT SECONDS=1" + "\n";
  macro += "DS CMD=KEY X=535 Y=293 CONTENT=" + currentMsg + "" + "\n";
  macro += "SIZE X=1340 Y=902" + "\n";
  macro += "WAIT SECONDS=1" + "\n";
  macro += "DS CMD=LDOWN X=660 Y=704 CONTENT=" + "\n";
  macro += "WAIT SECONDS=1" + "\n";
  macro += "DS CMD=LUP X=660 Y=704 CONTENT=" + "\n";
  macro += "SIZE X=1340 Y=902" + "\n";
  macro += "WAIT SECONDS=1" + "\n";
  macro += "DS CMD=MOVETO X=686 Y=576 CONTENT=" + "\n";
  macro += "WAIT SECONDS=1" + "\n";
  macro += "DS CMD=LDOWN X=686 Y=576 CONTENT=" + "\n";
  macro += "WAIT SECONDS=1" + "\n";
  macro += "DS CMD=LUP X=686 Y=576 CONTENT=" + "\n";
  macro += "WAIT SECONDS=1" + "\n";
  macro += "DS CMD=LDOWN X=975 Y=217 CONTENT=" + "\n";
  macro += "WAIT SECONDS=15" + "\n";
  macro += "DS CMD=LUP X=975 Y=217 CONTENT=" + "\n";
}
sc4rface
 
Posts: 3
Joined: Tue Jan 16, 2018 2:03 am

Re: Javascript inside imacros script

by chivracq on Tue Jan 16, 2018 7:09 am

sc4rface wrote:I wrote small script to flash game with imacros. I must use this script inside javascript. My code looks like this, but imacros returns error like this: "Error -1100: Unknown command: VAR at line: 1" Additionaly i must to use AJAX to get values from local file and two arrays to switinch current value filling to form.

What's wrong? I can not use javascript this way?

Code: Select all
var messages = ["hello", "hi", "welcome"];
var nicknames = [];
var currentNick;
var currentMsg;
var msgNumber;

if (window.XMLHttpRequest) {
  xmlhttp = new XMLHttpRequest();
} else {
  xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}

xmlhttp.open("GET", "/herozero-scraper/nicknames.txt", false);
xmlhttp.send();
file = xmlhttp.responseText;
nicknames = file.split(',');

for (i = 0; i < nicknames.length; i++) {
  msgNumber = Math.floor(Math.random() * messages.length);
  currentNick = nicknames[i];
  currentMsg = messages[msgNumber];
  var macro = "CODE:";
  macro += "VERSION BUILD=12.0.501.6698" + "\n";
  macro += "TAB T=1" + "\n";
  macro += "TAB CLOSEALLOTHERS" + "\n";
  macro += "'SET !PLAYBACKDELAY 0.00" + "\n";
  macro += "SIZE X=1340 Y=902" + "\n";
  macro += "WAIT SECONDS=1" + "\n";
  macro += "DS CMD=MOVETO X=266 Y=757 CONTENT=" + "\n";
  macro += "WAIT SECONDS=1" + "\n";
  macro += "DS CMD=LDOWN X=266 Y=757 CONTENT=" + "\n";
  macro += "WAIT SECONDS=1" + "\n";
  macro += "DS CMD=LUP X=266 Y=757 CONTENT=" + "\n";
  macro += "SIZE X=1340 Y=902" + "\n";
  macro += "WAIT SECONDS=1" + "\n";
  macro += "DS CMD=LDOWN X=535 Y=293 CONTENT=" + "\n";
  macro += "WAIT SECONDS=1" + "\n";
  macro += "DS CMD=LUP X=535 Y=293 CONTENT=" + "\n";
  macro += "WAIT SECONDS=1" + "\n";
  macro += "DS CMD=KEY X=535 Y=293 CONTENT=" + currentNick + "" + "\n";
  macro += "SIZE X=1340 Y=902" + "\n";
  macro += "WAIT SECONDS=1" + "\n";
  macro += "DS CMD=LDOWN X=492 Y=389 CONTENT=" + "\n";
  macro += "WAIT SECONDS=1" + "\n";
  macro += "DS CMD=LUP X=492 Y=389 CONTENT=" + "\n";
  macro += "WAIT SECONDS=1" + "\n";
  macro += "DS CMD=KEY X=535 Y=293 CONTENT=" + currentMsg + "" + "\n";
  macro += "SIZE X=1340 Y=902" + "\n";
  macro += "WAIT SECONDS=1" + "\n";
  macro += "DS CMD=LDOWN X=660 Y=704 CONTENT=" + "\n";
  macro += "WAIT SECONDS=1" + "\n";
  macro += "DS CMD=LUP X=660 Y=704 CONTENT=" + "\n";
  macro += "SIZE X=1340 Y=902" + "\n";
  macro += "WAIT SECONDS=1" + "\n";
  macro += "DS CMD=MOVETO X=686 Y=576 CONTENT=" + "\n";
  macro += "WAIT SECONDS=1" + "\n";
  macro += "DS CMD=LDOWN X=686 Y=576 CONTENT=" + "\n";
  macro += "WAIT SECONDS=1" + "\n";
  macro += "DS CMD=LUP X=686 Y=576 CONTENT=" + "\n";
  macro += "WAIT SECONDS=1" + "\n";
  macro += "DS CMD=LDOWN X=975 Y=217 CONTENT=" + "\n";
  macro += "WAIT SECONDS=15" + "\n";
  macro += "DS CMD=LUP X=975 Y=217 CONTENT=" + "\n";
}

(F)CIM...! :mrgreen: (Read my Sig...)

Using a '.js' Script means you are using iMacros for FF but I see a "VERSION BUILD=12.0.501.6698" in the middle of your Script which is for iMB v12.0 and 'DS' Mode Commands which are indeed only supported on iMB and IE. (And Flash Objects can indeed only be automated/controlled from iMacros using the 'DS' Mode.)
=> I guess you are probably using iMB v12.0...? :?

JavaScript Scripts (with a '.js' Extension and not '.iim' like you are probably trying to run your Script) can only run in Firefox unless you can find some "external" Compiler able to run JavaScript Scripts that you then could control from the Scripting Interface like for '.vbs', 'C++',, 'C#' etc Scripts.

And if you had paid attention to the Descriptions for the different Sub-Forums on this Forum, you would have noticed that no "JavaScript" or ".js" is mentioned for the 'Scripting Interface' Sub-Forum (where you then incorrectly opened your Thread, but I can understand the "confusion" as that's actually the Subject of your Post), while Threads related to '.js' Scripts are expected to be opened in the 'iMacros for FF' Sub-Forum where they are mentioned in that Sub-Forum Description. (But no need to duplicate your Thread now, the 'iMacros for FF' Sub-Forum wouldn't be completely "correct" either because of the 'DS' Mode parts in your Script...)

Because of your Flash Game, you'll indeed need the 'DS' Mode and therefore iMB.

I'm not completely sure what the beginning of your Script is doing with the 'XMLHttpRequest()' part, but it looks to me like it is simply retrieving the Content of your 'nicknames.txt' Local File and splitting its Content into an Array, ... which can be done directly from an '.iim' Script using the iMacros '!DATASOURCE' Command on your '.TXT' File, + 'EVAL()' for the split/shuffle/random parts.

And you'll need of course to reconvert your '.js' Script back to an '.iim' Script... iMB cannot run '.js' Scripts (natively like FF)...

>>>

+ For those interested, parallel Thread on SOF:
- Javascript inside imacros script
(No Replies/Answers yet...)
- (F)CIM = (Full) Config Info Missing: iMacros + Browser + OS with all 3 Versions...
- I usually don't even read the Question if that (required) Info is not mentioned...
- Script & URL usually help a lot for a more "educated" Help...
chivracq
 
Posts: 7714
Joined: Sat Apr 13, 2013 6:07 am
Location: Amsterdam (NL)


Return to Command Line and Scripting Interface

Who is online

Users browsing this forum: No registered users and 4 guests

-->