How to create timed events in custom script


#1

Hi everybody, working on my custom script for this fabulous bot i’m not sure how to continue on…
Basically I want my script to output a choice to chatters and let them vote, then compile the votes within say 60s and output the result.
I know how to do the math part but i’m not sure how to work with time within phantom bot … how can I do the 60s timer ?
Also, i’d want my script to periodically send a text output to the chat, how can I create a function who sends output to the chat each X secs ?

I’ve checked in pointSystem.js as I know there is a reward system ok points each X s but i’m not sure of what i’ve found there

in function runPointsPayout() :
if (onlinePayoutInterval > 0 && (lastPayout + (onlinePayoutInterval * 6e4)) <= now) {…

why the 6e4 ? shouldn’t it work without it ?
Also how are these script called “passively” ? is phantombot emitting some secret command to trigger it ? Or the scripts are executed repeatedly in background ?

Thanks for reading and helping, and thanks to the creator of this awesome bot !


#2

Check out systems/pollSystem.js, it does some of what you are after including setting up a timer.

The “6e4” is notation for the number of 0’s after a number. In this case 60000 - 60,000 milliseconds, or 60 seconds, or one minute.

Once a timer is created as you are seeing, it runs in the background as a thread. That is how it runs passively. Since that code you are looking at it just in the script global scope, it is executed when the script is loaded.


#3

ok thanks a bunch :slight_smile:

I think I more or less get it … i’l go check what’s in the poll system, didn’t think of it i admit ^^’

i’m gonna try some things and come back whinning when it won’t works, thanks again !