• If you need help or want to discuss things, you now can also join us on our Discord Server!
  • A first preview of the unlimited version of SinusBot can be found in the Upcoming Changes thread. A version for Windows will follow, but we don't have a release date, yet.

EN Script told to stop but it's still running!

Status
Not open for further replies.

Doggy Doggo

Member
Hey guys I am trying to create a few commands for my bot, the reason I am creating these manually is I don't want to give people full access and want to limit what they can do.

Now here is the script so far https://pastebin.com/mxg4nuqY

Now everything works fine, it identifies the blocked user groups, BUT it still runs the command even though the script is meant to stop with 'return;'

Any ideas?
 
because you are using two forEach ( functions({}). It will return out of the first forEach-function and will resume in the next forEach. If I understand you correctly and you meant that.

If you want to return out of the chat-event, just use the normal for-loops, that should be the easiest way I guess.

Alternatively you could return a flag into the first forEach, which indicates that you found a blocked user and also return out of that.. (somehow) but I'm not sure about that and it's a bit ugly I guess.
 
I need both of the foreach, because there are potentially multiple configs for different usergroups.

It gets to the message and sends me that ( ev.client.chat(Extras.BlockedMsg); ) but it still goes into the else even though it shouldn't.
 
but it still goes into the else even though it shouldn't.
Nope, it should do that ^^
As Diesmon already mentioned the return only exits the anonymous function once (so it practically does nothing) but still keeps iterating the following elements.

This would work for example: (but it's not very nice)
Code:
var hasGroup = false;
var blockMsg;

config.BlockedExtras.forEach(function(Extras) {
    ev.client.getServerGroups().forEach(function(group) {
      if (group.id() == Extras.BlockedID) {
         hasGroup = true;
         blockMsg = Extras.BlockedMsg;
      }
   });
});

if (hasGroup) {
   ev.client.chat(blockMsg);
   return;
}
 
Status
Not open for further replies.
Back
Top Bottom