$(count) is the only Nightbot variable that keeps its value between command uses. For anything more complex you would need a workaround, for example a $(urlfetch) request to some custom API.
This workaround is possible using ehsankia’s quote custom API - read more about it here.
Click this link. It will generate three links and two tokens, a public token (8 characters long) and a private token (16 characters long). The public token is located within the first generated link. The private token is located within both the second and third generated links. The tokens are found after token=
and before &data=$(querystring)
Copy them and keep them somewhere safe!
I’ve set up 3 commands below:
!test and _test which work in tandem to add a win or loss depending on some condition
!score which displays the numbers of wins and losses
Either copy and paste these commands into chat or add them through the Nightbot dashboard. Add the commands through chat only if you are sure no one else is there, otherwise they might see your private token (which is used to edit the list)! Replace PUBLIC_TOKEN
with your public token and PRIVATE_TOKEN
with your private token. In the command response for !test you will have to write some code and a conditional that determines whether the player wins or loses against Nightbot.
!addcom -cd=5 !test -a=_test $(eval // Write some code here... if(CONDITION){`PRIVATE_TOKEN&data=win`;}else{`PRIVATE_TOKEN&data=loss`;})
!addcom -cd=5 _test $(eval a=`$(urlfetch https://twitch.center/customapi/addquote?token=$(query))`;b=decodeURIComponent(`$(querystring)`);b.includes(`PRIVATE_TOKEN`)?(b.includes(`win`)?`The player won against Nightbot!`:`The player lost to Nightbot...`):` `)
!addcom -cd=5 !score $(eval a=`$(urlfetch json https://twitch.center/customapi/quote/list?token=PUBLIC_TOKEN)`;w=a.match(/win/g);w?w.length:0;l=a.match(/loss/g);l?l.length:0;`${w} wins and ${l} losses.`;)