View unanswered posts | View active topics It is currently 20 Jul 2019 14:45

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.



Reply to topic  [ 3 posts ] 
JavaScript: Sending multiple commands at once 
Author Message
Veteran

Joined: 21 Mar 2016 09:17
Posts: 207
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.


06 Oct 2018 16:46
Profile
Site Admin
User avatar

Joined: 04 Mar 2010 01:14
Posts: 305
uhm?

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


06 Oct 2018 23:50
Profile
Wizard
User avatar

Joined: 03 Mar 2014 13:03
Posts: 165
Location: US West
Another way would be something like this...

Code:
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.


08 Oct 2018 18:12
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 3 posts ] 

Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group
Designed by ST Software.