Official Everybody Edits Forums

Do you think I could just leave this part blank and it'd be okay? We're just going to replace the whole thing with a header image anyway, right?

You are not logged in.

#1 2015-07-24 09:39:42

soulrunner
Member
Joined: 2015-03-10
Posts: 185

[Help] Breaking a for loop.

When I do !ssay start it starts up fine. Then when I try to stop it before It's finished I do !ssay stop and It just keeps on going. Thanks in advance.

                                case ".ssay":
                                case "!ssay":
                                case "#ssay":
                                    {
                                        if (admins.Contains(username))
                                        {
                                            if (arg.Length > 1)
                                            if (arg[1] == "start")
                                            {
                                                carryOn = true;
                                                for (int i = 5000 - 0; i >= 0; i -= 200)
                                                {
                                                    int ssay = rnd.Next(1, 10);
                                                    switch (ssay)
                                                    {
                                                        case 1:
                                                            {
                                                                say("Soul says RED");
                                                                Thread.Sleep(i);
                                                                sred();
                                                            }
                                                            break;
                                                        case 2:
                                                            {
                                                                say("Slow says RED");
                                                                Thread.Sleep(i);
                                                                nred();
                                                            }
                                                            break;
                                                        case 3:
                                                            {
                                                                say("Soul says ORANGE");
                                                                Thread.Sleep(i);
                                                                sorange();
                                                            }
                                                            break;
                                                        case 4:
                                                            {
                                                                say("Slow says ORANGE");
                                                                Thread.Sleep(i);
                                                                norange();
                                                            }
                                                            break;
                                                        case 5:
                                                            {
                                                                say("Soul says YELLOW");
                                                                Thread.Sleep(i);
                                                                syellow();
                                                            }
                                                            break;
                                                        case 6:
                                                            {
                                                                say("Slow says YELLOW");
                                                                Thread.Sleep(i);
                                                                nyellow();
                                                            }
                                                            break;
                                                        case 7:
                                                            {
                                                                say("Soul says GREEN");
                                                                Thread.Sleep(i);
                                                                sgreen();
                                                            }
                                                            break;
                                                        case 8:
                                                            {
                                                                say("Slow says GREEN");
                                                                Thread.Sleep(i);
                                                                ngreen();
                                                            }
                                                            break;
                                                        case 9:
                                                            {
                                                                say("Soul says BLUE");
                                                                Thread.Sleep(i);
                                                                sblue();
                                                            }
                                                            break;
                                                        case 10:
                                                            {
                                                                say("Slow says BLUE");
                                                                Thread.Sleep(i);
                                                                nblue();
                                                            }
                                                            break;
                                                    }
                                                    if (carryOn == false)
                                                    {
                                                        break;
                                                    }
                                                }

                                            }
                                            else if (arg[1] == "stop")
                                            {
                                                pm(username, "Stopping bot");
                                                carryOn = false;
                                                say(username + " has stopped the bot");
                                            }
                                            else
                                            {
                                                pm(username, "Only use start and stop please.");
                                            }
                                        }
                                        else
                                        {
                                            pm(username, "You do not have permission to use this command");
                                        }
                                        }
                                        break;

l141.gif

Offline

#2 2015-07-24 09:43:44, last edited by BuzzerBee (2015-07-24 10:06:44)

BuzzerBee
Forum Admin
From: Texas, U.S.A.
Joined: 2015-02-15
Posts: 4,575

Re: [Help] Breaking a for loop.

The problem is your starting a new instance of the for loop when you say "!ssay stop". It doesn't apply to the loop you already created with "!ssay".

At least that's what I got from it, I only briefly skimmed the code.

Do you have TeamViewer? Add me, my username is BuzzerBee.

EDIT: Nevermind, it was a lack of threading. I fixed it for him on TeamViewer.
Don't forget to thread your Thread.Sleeps! Or better yet, use await Task.Delay


TdQRyz3.png
https://wiki.everybodyedits.com/images/5/5d/135_bee

Offline

#3 2015-07-24 10:07:14

soulrunner
Member
Joined: 2015-03-10
Posts: 185

Re: [Help] Breaking a for loop.

Thank you BuzzerBee. Problem Fixed. Requesting thread lock.


l141.gif

Offline

soulrunner1437728834523979

Board footer

Powered by FluxBB

[ Started around 1734852318.0705 - Generated in 0.080 seconds, 12 queries executed - Memory usage: 1.4 MiB (Peak: 1.51 MiB) ]