Success vs Number of Attempts Tracker

I’m looking to make a command that tracks successes and the overall number of attempts. Ideally, I would like to call it via the same command and pass “success” or “failure”, but not sure if that’s possible.

So, let’s say the variables are x/y, where x is a success and y is the total number of attempts. If I were to run !success it would increment both x and y by one, i.e. 1/1. However, if I were to call it via !failure, it would only increment y, i.e. 0/1. And then some function, like !total to return both, i.e. 3/5

Basically, I’m looking for a way to track overall attempts, while simultaneously tracking successes and then be able to return a total at any time. Sorry, I’m very new to Nightbot programming. Any help is greatly appreciated. Thank you!

Looks like back in '18, there was no way to track a variable across multiple commands. Not sure if this is still the case.

This is still the case, unfortunately. There’s only a count storage of command usage per command, but it can only be manipulated via our API externally (not internally with scripting).

One way you could do this is by using the quote system API. You’ll get your TOKENS by clicking on the second link in the post, use these in the commands I wrote. To know where to look for your PUBLIC_TOKEN and PRIVATE_TOKEN, look at the field bellow:

$(urlfetch https://twitch.center/customapi/quote?token=PUBLIC_TOKEN&data=$(querystring))
$(urlfetch https://twitch.center/customapi/addquote?token=PRIVATE_TOKEN&data=$(querystring))
$(urlfetch https://twitch.center/customapi/delquote?token=PRIVATE_TOKEN&data=$(querystring))

Keep your PRIVATE_TOKEN secret, don’t share it anywhere. To add a command containing your PRIVATE_TOKEN do it from the dashboard. Don’t use the chat as anyone could monitor it and copy the token, they could then edit your data.


To add success and attempts to the counters:
!success

$(urlfetch https://twitch.center/customapi/addquote?token=PRIVATE_TOKEN&data=s$(count))

!failure

$(urlfetch https://twitch.center/customapi/addquote?token=PRIVATE_TOKEN&data=a$(count))

Make sure !success and !failure are for moderators and above only and to add !total as an alias to these commands.


For the main command:
!total

$(eval q=`$(urlfetch json https://twitch.center/customapi/quote/list?token=PUBLIC_TOKEN&no_id=1)`;s=q.match(/s\d+/g);a=q.match(/a\d+/g);s==null?s=0:s=s.pop().replace(`s`,``);a==null?a=0:a=a.pop().replace(`a`,``);`Success/Attempts: ${s}/${a}`)

And then to reset the counters:
!sreset

!success \-c=0

!freset

!failure \-c=0

!totalreset

$(urlfetch https://twitch.center/customapi/delquote?token=PRIVATE_TOKEN&clear=1)

Make sure !sreset and !freset have !editcom as an alias, and that !sreset, !freset and !totalreset are for moderators and above only as well.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.