# I want to make an addition function by applying function \$(count)

I want your help.
I want to make an addition function by applying function \$(count).

For example, define as follows:
a = 1, b = 2 at one’s time
b - a = 2 - 1 = 1

I want to make an addition subtraction function in this way.
Is there a way?

나는 당신의 도움을 받기 원합니다.
나는 함수 \$(count)를 응용하여 덧셈 함수를 만들고 싶습니다.

예를 들어 아래처럼 정의합니다.
a = 1, b = 2 일 때
b - a = 2 - 1 = 1

이런 식으로 덧셈 뺄셈 함수를 만들고 싶다.
방법이 있습니까?

Hey @bellhidira!

Solution #1
Wouldn’t a math command be simpler?

``````!addcom !math -cd=5 \$(eval b=decodeURIComponent(`\$(querystring)`);if(b){try{`\${b} = \${eval(b)}`;}catch(e){`Invalid mathematical expression!`;}}else{`There is no input...`;}})
``````

Credit to @RokettoJanpu

Solution #2
Otherwise, to do what you’re asking for… We’ll use ehsankia’s quote system.

``````!addcom a -cd=5 \$(eval if(isNaN(`\$(query)`)==false){q=`\$(urlfetch https://twitch.center/customapi/editquote?token=PRIVATE_TOKEN&data=1 \$(query))`;`a = \$(query)`;}else if(isNaN(`\$(query)`)==true){a=`\$(urlfetch https://twitch.center/customapi/quote?token=PUBLIC_TOKEN&no_id=1&data=1)`;b=`\$(urlfetch https://twitch.center/customapi/quote?token=PUBLIC_TOKEN&no_id=1&data=2)`;try{`a \$(query) = {\$(eval a \$(query))}`;}catch(e){`Invalid mathematical expression!`;}}else{` `;})
!addcom b -cd=5 \$(eval if(isNaN(`\$(query)`)==false){q=`\$(urlfetch https://twitch.center/customapi/editquote?token=PRIVATE_TOKEN&data=2 \$(query))`;`b = \$(query)`;}else if(isNaN(`\$(query)`)==true){a=`\$(urlfetch https://twitch.center/customapi/quote?token=PUBLIC_TOKEN&no_id=1&data=1)`;b=`\$(urlfetch https://twitch.center/customapi/quote?token=PUBLIC_TOKEN&no_id=1&data=2)`;try{`b \$(query) = {\$(eval b \$(query))}`;}catch(e){`Invalid mathematical expression!`;}}else{` `;})
``````

This way, if you type a 5 and b 9 and then do b - a it’ll give you b - a = 4 and a + b will give you a + b = 14, etc. Any type of mathematical expression being available.

However, with this system, you’ll have to initiate the quote system first, here’s how I recommend to do it:

``````!addcom !init -cd=5 \$(urlfetch https://twitch.center/customapi/addquote?token=PRIVATE_TOKEN&data=\$(query))
!init 0
!init 1
!delcom !init
``````

Solution #3
Now, if you really want to use \$(count) you’ll have to call a and b the number of time you need them to reach and you’ll need a way to reset them in case you want to get to a lower number than a and/or b currently are.
So let’s say you want a to be equal to 4 you’ll have to call a four times. But if a is equal to 7, then you’ll have to reset a first with a command such as !reseta.
Anyway, here’s how to do it:

``````!addcom a -cd=5 \$(eval if(`\$(query)`){a=`\$(urlfetch https://twitch.center/customapi/quote?token=PUBLIC_TOKEN&no_id=1&data=1)`;b=`\$(urlfetch https://twitch.center/customapi/quote?token=PUBLIC_TOKEN&no_id=1&data=2)`;try{`a \$(query) = {\$(eval a \$(query))}`;}catch(e){`Invalid mathematical expression!`;}}else{q=`\$(urlfetch https://twitch.center/customapi/editquote?token=PRIVATE_TOKEN&data=1 \$(count))`;`a = \$(count)`;})
!addcom b -cd=5 \$(eval if(`\$(query)`){a=`\$(urlfetch https://twitch.center/customapi/quote?token=PUBLIC_TOKEN&no_id=1&data=1)`;b=`\$(urlfetch https://twitch.center/customapi/quote?token=PUBLIC_TOKEN&no_id=1&data=2)`;try{`b \$(query) = {\$(eval b \$(query))}`;}catch(e){`Invalid mathematical expression!`;}}else{q=`\$(urlfetch https://twitch.center/customapi/editquote?token=PRIVATE_TOKEN&data=2 \$(count))`;`b = \$(count)`;})
!addcom !reseta -cd=5 -a=!editcom a \-c=0
!addcom !resetb -cd=5 -a=!editcom b \-c=0
``````

But with this system, you’ll have to initiate the quote system first too, here’s how I recommend to do it:

``````!addcom !init -cd=5 \$(urlfetch https://twitch.center/customapi/addquote?token=PRIVATE_TOKEN&data=\$(query))
!init 0
!init 1
!delcom !init
``````

For solutions #2 and #3
To get your PUBLIC_TOKEN (8 characters) and PRIVATE_TOKEN (16 characters), use the second link in ehsankia’s quote system post. Store your tokens somewhere safe to add them back in case the command is edited by mistake, you don’t want to lose them.
And don’t share your PRIVATE_TOKEN anywhere, that’s why I’d recommend adding a and b from your dashboard so you don’t share your PRIVATE_TOKEN in chat, in that case remove !addcom and -cd=5 from the command message, a and b would, of course, be the commands names. Same for !init.

The commands I wrote are in the order I recommend them, this means that solution #1 is the simplest one, and solution #3 is basically you complicating your life, but the solution #2 is a mess too, haha! But I can’t judge, choose the solution that seems best to you and best meet your goals.

2 Likes

@bellhidira

Just like the solutions posted above, this solution is possible using ehsan’s quote API.

## Command Setups

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:
!setvalue and _setvalue which work in tandem to declare number variables
!math which calculates an expression

Copy and paste the following command setups into chat. Replace `PUBLIC_TOKEN` with your public token and `PRIVATE_TOKEN` with your private token.

``````!addcom -cd=5 !setvalue -a=_setvalue \$(eval a=decodeURIComponent(`\$(querystring)`).match(/[A-Za-z]\w*\s?=\s?[+-]?(\d*[.])?\d+/g);`PRIVATE_TOKEN&data=\${encodeURIComponent((a?a.join(`,`):`"e"`)+`;`)}`)

!addcom -cd=5 _setvalue \$(eval d=decodeURIComponent;a=`\$(urlfetch https://twitch.center/customapi/addquote?token=\$(query))`;b=d(d(`\$(querystring)`));if(b.includes(`PRIVATE_TOKEN`)){c=b.split(`&data=`)[1].split(`,`).map(a=>a.split(`=`)[0].trim()).join(`, `);c!=`"e";`?`Successfully set values for: \${c}`.slice(0,400):`Failed to set any values!`;}else{`Use !setvalue`;})

!addcom -cd=5 !math \$(eval _=`\$(urlfetch json https://twitch.center/customapi/quote/list?token=PUBLIC_TOKEN&no_id=1)`;if(_!=`There are no quotes added`){eval(_);}__=decodeURIComponent(`\$(querystring)`);if(__){try{`\${__} = \${eval(__)}`.slice(0,400);}catch(e){`Invalid mathematical expression!`;}}else{`There is no input...`;})
``````

## Declaring Variables

To declare a number variable, type:

``````!setvalue VARIABLE_NAME = VALUE
``````

where VARIABLE_NAME is your variable name and VALUE is the numeric value of the variable. VALUE can be any integer or float (decimal number).

An example of declaring a variable “a” with a value of 42:

``````!setvalue a = 42
``````

You can declare multiple variables in one go. For example, declaring variables “first_number” and “second_number” with the values 420 and -3.14159, respectively:

``````!setvalue first_number = 420 second_number = -3.14159
``````

You can exclude the spaces surrounding the “=” symbol if you wish. I only put in spaces to make the command usage examples easier to read. For example:

``````!setvalue first_number=420 second_number=-3.14159
``````

Once variables are declared, they retain their value between command uses. Re-assigning variables is permitted.

## Calculating Expressions

The command to calculate expressions is:

``````!math [expression]
``````

An example of using !math

``````!math 2+2
``````

which will return:

``````2+2 = 4
``````

Let us declare variables “a” and “b” with the values 3 and 4, respectively. First type:

``````!setvalue a = 3 b = 4
``````

Now if you add “a” and “b”

``````!math a+b
``````

This will return:

``a+b = 7``
1 Like

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