JavaScript: Sending multiple commands at once

Need help with quests? Maybe just some advice on which guilds to choose? This is the forum for you. Note that you must be a validated player to view this forum. (Note: Quest help should come in the form of helpful suggestions/hints, but not direct solutions/walkthrough info.)
Forum rules
- Use common sense and be respectful towards each other at all times, even when disagreeing.
- Do not reveal sensitive game information. Guild secrets, player seconds are examples of things not allowed.
Post Reply
Kwevin
Veteran
Posts: 207
Joined: 21 Mar 2016 09:17

JavaScript: Sending multiple commands at once

Post by Kwevin » 06 Oct 2018 16:46

So I'm trying to make an herbing script for the web client, and I need it to send multiple commands at the same time. Right now my code looks something like this:

gwc.connection.send("disembark");
if (gwc.gmcp.data.room.id == "6fTEU.") {
gwc.connection.send("n");
gwc.connection.send("n");
gwc.connection.send("search here for herbs");
}

In Mudlet, all I'd have to do is use "sendAll". Is there any way I can condense potentially hundreds of commands into one line of JS?
Alea iacta est. Serius regredi est.

User avatar
cotillion
Site Admin
Posts: 310
Joined: 04 Mar 2010 01:14

Re: JavaScript: Sending multiple commands at once

Post by cotillion » 06 Oct 2018 23:50

uhm?

[ 'n', 'e', 'w' ].map((word) => gwc.connection.send)

User avatar
Shanoga
Wizard
Posts: 168
Joined: 03 Mar 2014 13:03
Location: US West

Re: JavaScript: Sending multiple commands at once

Post by Shanoga » 08 Oct 2018 18:12

Another way would be something like this...

Code: Select all

if (gwc.gmcp.data.room.id == "6fTEU.") {
  actions = ['n', 'n', 'search here for herbs'];
}

actions.forEach(function(action) {
  gwc.connection.send(action);
});
What you do here is you create an array with each of the commands you would like to send, then you use a forEach function on that array to execute the gwc.connection.send function on each element of that array. If you have multiple room IDs you want to check, then have a long series of if--elseif--else conditions and use the last few lines at the end of the script.

Post Reply
http://tworzymyatmosfere.pl/przescieradla-jedwabne-z-gumka/