Author Topic: How do I use @calcpre@/@calcpost@ variables?  (Read 1924 times)

0 Members and 1 Guest are viewing this topic.

Nazo

  • Padawan
  • **
  • Posts: 70
  • Karma: +2/-0
  • Expert on Twitch Bots
    • View Profile
  • Twitch Name: OverlordNazo
How do I use @calcpre@/@calcpost@ variables?
« on: December 18, 2015, 04:49:11 AM »
I know that @calcpre@ comes before @calcpost@, but that's just about all I know. Can someone explain this in a litte more depth?
★ Twitch Bot Expert ★


YouTube: Lord Nazo
Twitch: OverlordNazo
Twitter: @Lord_Nazo

Dante557

  • Advisor
  • Councilor
  • **
  • Posts: 555
  • Karma: +26/-0
  • Sometimes Helpful, Sometimes Not :D
    • View Profile
    • My Twitch Page
  • Twitch Name: Dante557
Re: How do I use @calcpre@/@calcpost@ variables?
« Reply #1 on: December 18, 2015, 04:57:29 AM »
This will be changing in the next update (It'll all be going to a singular @calc@ variable) but basically it's all in terms of how things are processed. @calcpre@ gets processed before an @if@ statement is called whereas @calcpost@ is done after the @if@ statement.

They both do the same thing other then this difference. As for how to use them...

Code: [Select]
@calcpre@: Executes before @if@ : @calcpre@[op,num1,num2] , e.g. @calcpre@[+,5,4]. Available operaions (+,-,*,/)
@calcpost@: Executes after @if@ :@calcpost@[op,num1,num2] , e.g. @calcpost@[+,5,4]. Available operaions (+,-,*,/)

Thanks,
Dante557
If you need to get through to me you can try to contact me on Twitter @ http://www.twitter.com/dante556

Nazo

  • Padawan
  • **
  • Posts: 70
  • Karma: +2/-0
  • Expert on Twitch Bots
    • View Profile
  • Twitch Name: OverlordNazo
Re: How do I use @calcpre@/@calcpost@ variables?
« Reply #2 on: December 19, 2015, 03:29:20 AM »
If you or someone else could post an example that uses this, that would be great!
★ Twitch Bot Expert ★


YouTube: Lord Nazo
Twitch: OverlordNazo
Twitter: @Lord_Nazo

Dante557

  • Advisor
  • Councilor
  • **
  • Posts: 555
  • Karma: +26/-0
  • Sometimes Helpful, Sometimes Not :D
    • View Profile
    • My Twitch Page
  • Twitch Name: Dante557
Re: How do I use @calcpre@/@calcpost@ variables?
« Reply #3 on: December 19, 2015, 04:30:29 AM »
Lets say, for some reason, you want to check to see if a viewer enters a number that's greater or equal to the number you input. For this example it'll just be something simple like 10 + 10 but you could also use numbers that you get from text files using @readfile@ or numbers that are randomly generated by the @rand@ variable (Like if you wanted to put your own bias on the number itself).

With this in mind, and using both @calcpre@ and @calcpost@ in the same @if@ statement you could do the following

Code: [Select]
@if@[>=||@target@||@calcpre@[+,10,10]||@target@ is greater or equal to @calcpost@[+,10,10]||@target@ is less than @calcpost@[+,10,10]]
Which, when the new update gets released to the general public, will be

Code: [Select]
@if@[>=||@target@||@calc@[+|10|10]||@target@ is greater or equal to @calc@[+|10|10]||@target@ is less than @calc@[+|10|10]]
For the first example, we need to use @calcpre@ for it to actually be used in the @if@ statement itself. This is due to how commands are currently prioritised in Deepbot which you can see at the bottom of this page deepbot.deep.sg/wiki/Custom+Commands.

Both @calcpre@ and @calcpost@ will come out as 20 in this example and result in the following

Code: [Select]
20:18   dante557: !test 19
20:18  dante557bot: 19 is less than 20
20:18   dante557: !test 20
20:18  dante557bot: 20 is greater or equal to 20

As I mentioned this is only extremely basic usage of the variable. It'll be a whole lot simpler when the update does drop but will, obviously, break commands that are currently using @calcpre@ and @calcpost@

Thanks,
Dante557
If you need to get through to me you can try to contact me on Twitter @ http://www.twitter.com/dante556

Nazo

  • Padawan
  • **
  • Posts: 70
  • Karma: +2/-0
  • Expert on Twitch Bots
    • View Profile
  • Twitch Name: OverlordNazo
Re: How do I use @calcpre@/@calcpost@ variables?
« Reply #4 on: December 19, 2015, 08:39:39 AM »
Awesome! Thank you! :)
★ Twitch Bot Expert ★


YouTube: Lord Nazo
Twitch: OverlordNazo
Twitter: @Lord_Nazo