mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Feb 2015
Posts: 7
S
Sphyrwa Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
S
Joined: Feb 2015
Posts: 7
Hello, I got some help the last time, maybe I can get it again smile

I have a callvote script that allows the channel owner or person who has been granted rights via a command (the state of the user is saved to an ini file) to call a vote as follows:
!callvote option1 option2 option3 ... optionAdInfinitum

The users can use !vote option1/option2/option3/.../optionAdInfinitum.

Using !callvote creates a file $+($chan,_voting.ini) where the each vote option is represented as a separate topic. Each of the topics has an item called "count", which counts how many times that particular topic has been voted for.

E.g. here's how the file would look like after there was a command !callvote One Two Three and then someone used !vote Three

Code:
[Voted]
0=0 ;this is a dummy value just so that this topic would be created in the very top. Names of people who have voted will be added here every time someone uses the !vote command.
Anonymous=yes

[One]
Count=0

[Two]
Count=0

[Three]
Count=1


What I would need help is the !endvote command I have made, which causes the script to identify how many topics (vote options) are in the ini file, and then message the channel those results, every topic result being in a different line.

Here's where the problem comes in: the while loop to read each new topic and results completes itself as fast as possible with /timer having an effect but not one that is desired.

Here's the code for the !endvote script:

Code:
on *:TEXT:!ENDVOTE:*:{
  if ($ini(Promotelist.ini,$+($chr(35),$lower($nick))) != 0) || ($readini(Promotelist.ini, n, $chan, $nick == 1)) {
    if ($isfile($+($chan,_voting.ini)) == $true) {
      var %x 2
      var %y $ini($+($chan,_voting.ini),0)
      var %z $ini($+($chan,_voting.ini),%x)
      while (%x <= %y) {
        /timer 1 3 /msg $chan $ini($+($chan,_voting.ini),%x) : $readini($+($chan,_voting.ini), n, %z, Count)
        /inc %x 1
      }
      ;/remove $+($chan,_voting.ini)
    }
    else {
      /msg $chan ERROR: No vote in progress!
    }
  }
  else {
    /msg $chan ERROR: Insufficient privileges!
  }
}


The problem is the while loop. I want it to do each pass after 3 seconds (as instructed by the timer), so the output would be like:

Vote1 : 1
*3 seconds pass*
Vote2 : 0
*3 seconds pass*
Vote3 : 5
etc

But here is how it works instead:
*3 seconds pass*
Vote1 : 1
Vote2 : 0
Vote3 : 5

Which is not how I want it to be, because it would be spammy and get me kicked from the channel for flooding.

Joined: Feb 2003
Posts: 2,812
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2003
Posts: 2,812
You cannot slow down or pause scripts. The timer command queues a timer thread and your script immediately continues on its merry way. If your script calls /timer three times, each with a 3 second delay, all three will fire after 3 seconds elapse from their issue in your while loop.

Users have requested a /sleep command in the Features Requests forum on several occasions. I think it'd be a neat and practical feature.


Well. At least I won lunch.
Good philosophy, see good in bad, I like!
Joined: Feb 2015
Posts: 7
S
Sphyrwa Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
S
Joined: Feb 2015
Posts: 7
In that case, is there a feasible workaround?

Joined: Dec 2013
Posts: 779
N
Hoopy frood
Offline
Hoopy frood
N
Joined: Dec 2013
Posts: 779
Start timers to evaluate 3 seconds apart from each other.
First timer to evaluate after 3, second after 6.

You can do this by using
timer 1 $calc(%i * 3)
Let %i be 1, then inc %i by 1 per each loop.


Nillens @ irc.twitch.tv
Nillen @ irc.rizon.net
Joined: Feb 2015
Posts: 7
S
Sphyrwa Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
S
Joined: Feb 2015
Posts: 7
Code:
      var %i 1
      while (%x <= %y) {
        /timer 1 $calc(%i * 3) /msg $chan $ini($+($chan,_voting.ini),%x) : $readini($+($chan,_voting.ini), n, %z, Count)
        /inc %x 1
      }

It still spams it all at once after the timer has expired. I seem to be using the timer in the wrong spot but I don't really have an idea where I should be using it instead.

Joined: Dec 2013
Posts: 779
N
Hoopy frood
Offline
Hoopy frood
N
Joined: Dec 2013
Posts: 779
You're not increasing %i as far as I can see.
%i will constantly be 1. 1 * 3 = 3, so all timers will use 3 as their evaluation time.
if you just add "inc %i" there, it should work as intended. as %i will then after one loop turn into 2. 2 * 3 = 6, so the second timer will evaluate after 6 seconds.


Nillens @ irc.twitch.tv
Nillen @ irc.rizon.net
Joined: Feb 2015
Posts: 7
S
Sphyrwa Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
S
Joined: Feb 2015
Posts: 7
/me facepalms.

That worked. Thank you very much for the help.


Link Copied to Clipboard