mIRC Home    About    Download    Register    News    Help

Print Thread
#264761 10/01/19 03:09 PM
Joined: Jan 2019
Posts: 6
D
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
D
Joined: Jan 2019
Posts: 6
I am currently making a Twitch Bot which will answer questions in chat by displaying a command. I am highly new to this program of programming and can't seem to get the if statements to work with the variables.
Code:
on *:TEXT:how old is dapper:#: {
     var %ageCount = %ageCount. $+ $nick 
     inc %ageCount. $+ $nick 1
     if (%ageCount. $+ $nick == 1) {
          msg $chan !age $nick
     }
}

Joined: Jan 2004
Posts: 2,127
Hoopy frood
Offline
Hoopy frood
Joined: Jan 2004
Posts: 2,127
See examples here of syntax for creating dynamic variable names vs retrieving from them.

maroon #264764 10/01/19 04:37 PM
Joined: Jan 2019
Posts: 6
D
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
D
Joined: Jan 2019
Posts: 6
Originally Posted By: maroon
See examples here of syntax for creating dynamic variable names vs retrieving from them.


I looked at the link before and couldn't get it to work. This is the latest revision, which, again, still doesn't work.
Code:
on *:TEXT:how old is dapper:#: {
     var %ageCount = $eval($+{%,ageCount.,$nick),2)
     inc %ageCount. $+ $nick 1
     if (%ageCount. $+ $nick == 1) {
          msg $chan !age $nick
     }
}

Joined: Jan 2004
Posts: 2,127
Hoopy frood
Offline
Hoopy frood
Joined: Jan 2004
Posts: 2,127
For one, you have a curly brace instead of a parenthesis.

You're using the wrong syntax inside the if() statement, so it's joining the contents of the variable named %ageCount. with the contents of $nick, then comparing that string with 1.

maroon #264766 10/01/19 05:07 PM
Joined: Jan 2019
Posts: 6
D
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
D
Joined: Jan 2019
Posts: 6
Originally Posted By: maroon
For one, you have a curly brace instead of a parenthesis.

You're using the wrong syntax inside the if() statement, so it's joining the contents of the variable named %ageCount. with the contents of $nick, then comparing that string with 1.


I fixed the curly brace instead of the parenthesis. Now, no matter what the value is at, it will still repeat the command. Progress. Still not sure what to change to make it so it truly does only work when the variable is less than, greater than or equal to a certain number.

Code:
on *:TEXT:how old is dapper:#: {
     var %ageCount = $eval($+(%,ageCount.,$nick),2)
     inc %ageCount. $+ $nick 1
     if ($eval($+(%,ageCount.,$nick) == 1)) {
          msg $chan !age $nick
     }
}

Joined: Jan 2004
Posts: 2,127
Hoopy frood
Offline
Hoopy frood
Joined: Jan 2004
Posts: 2,127
You have a parenthesis in the wrong location, so you're doing

if (string including equals signs and a 1)

An echo following the if() condition shows the strings used on each side of the ==:

//echo -a $v1 vs $v2

shows: %ageCount. == 1 vs

As an additional debugging tool, you can use the -s switch for /var and /inc to give a display of the variable name being set, and the value being placed into it. When used in the editbox, the display shows in the active window, but from an event it will be in the Status Window.

maroon #264772 11/01/19 02:25 AM
Joined: Jan 2019
Posts: 6
D
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
D
Joined: Jan 2019
Posts: 6
Originally Posted By: maroon
You have a parenthesis in the wrong location, so you're doing

if (string including equals signs and a 1)

An echo following the if() condition shows the strings used on each side of the ==:

//echo -a $v1 vs $v2

shows: %ageCount. == 1 vs

As an additional debugging tool, you can use the -s switch for /var and /inc to give a display of the variable name being set, and the value being placed into it. When used in the editbox, the display shows in the active window, but from an event it will be in the Status Window.


Update, still can't get it to work.
Code:
on *:TEXT:how old is dapper:#: {
     var %ageCount = $eval($+(%,ageCount.,$nick),2)
     inc %ageCount. $+ $nick 1
     if ($eval($+(%,ageCount.,$nick) == 1)) {
         //echo -a $v1 vs $v2
         shows: %ageCount. == 1 vs
          msg $chan !age $nick
     }
}

Joined: Jan 2004
Posts: 2,127
Hoopy frood
Offline
Hoopy frood
Joined: Jan 2004
Posts: 2,127
You didn't fix your parenthesis. The purpose of the echo was to show your error to you, and the "shows:" line was to tell you what the result of the 'echo' would show. An important tool in debugging your problem is to add echo messages so you can see what the script is trying to do.

The $+() identifier joins together several comma-delimited items. The $eval(string,N) identifier evaluates the string, doing it N times, with default one time if the N parameter isn't used. In this case, you're putting the $() output inside the $eval() along with the string of the == and the string of the 1. By enclosing term2 inside the parenthesis, you're transforming this from comparing term1 vs term2 into having no term2 at all and comparing whether term1 is $true or $false.

The echo is showing $v1 as the result of evaluating the string one times due to the ,N parameter not being used. You used $eval up above to evaluate a string twice. See the difference in how this string is evaluated zero one or two times, by pasting each of these commands in an editbox:

//echo -a $eval($ $+ version,0)
//echo -a $eval($ $+ version,1)
//echo -a $eval($ $+ version,2)

Just as important as having matching parenthesis is having them enclosing the correct things.

maroon #264774 11/01/19 03:39 AM
Joined: Jan 2019
Posts: 6
D
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
D
Joined: Jan 2019
Posts: 6
Originally Posted By: maroon
You didn't fix your parenthesis. The purpose of the echo was to show your error to you, and the "shows:" line was to tell you what the result of the 'echo' would show. An important tool in debugging your problem is to add echo messages so you can see what the script is trying to do.

The $+() identifier joins together several comma-delimited items. The $eval(string,N) identifier evaluates the string, doing it N times, with default one time if the N parameter isn't used. In this case, you're putting the $() output inside the $eval() along with the string of the == and the string of the 1. By enclosing term2 inside the parenthesis, you're transforming this from comparing term1 vs term2 into having no term2 at all and comparing whether term1 is $true or $false.

The echo is showing $v1 as the result of evaluating the string one times due to the ,N parameter not being used. You used $eval up above to evaluate a string twice. See the difference in how this string is evaluated zero one or two times, by pasting each of these commands in an editbox:

//echo -a $eval($ $+ version,0)
//echo -a $eval($ $+ version,1)
//echo -a $eval($ $+ version,2)

Just as important as having matching parenthesis is having them enclosing the correct things.


Ah. I get what you're saying. This is what it looks like now although it still isn't working. How could I get this working?
Code:
on *:TEXT:how old is dapper:#: {
     var %ageCount = $eval($+(%,ageCount.,$nick),2)
     inc %ageCount. $+ $nick 1
     if ($($eval($+(%,ageCount.,$nick),1)) ==) {
          msg $chan !age $nick
     }
}

Last edited by DapperBot; 11/01/19 03:40 AM.
Joined: Jan 2004
Posts: 2,127
Hoopy frood
Offline
Hoopy frood
Joined: Jan 2004
Posts: 2,127
The $() identifier is an alias for $eval(), so in effect you're un-necessarily using $eval() twice. Plus you now don't even have a term#2. When you use the == operator it's required to have a term#2, even if you use $null.

Also, you don't want to evaluate the assembled variable once, because as the 3 echoes showing the 3 levels of evaluation, you're comparing a string beginning with a percent sign against 'nothing', which will never be true.

If you've correctly loaded the %ageCount variable with the value of the dynamic variable, you could use %ageCount inside your if() statement instead of repeating the assembly of the dynamic variable again.

maroon #264776 11/01/19 05:35 AM
Joined: Jan 2019
Posts: 6
D
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
D
Joined: Jan 2019
Posts: 6
Originally Posted By: maroon
The $() identifier is an alias for $eval(), so in effect you're un-necessarily using $eval() twice. Plus you now don't even have a term#2. When you use the == operator it's required to have a term#2, even if you use $null.

Also, you don't want to evaluate the assembled variable once, because as the 3 echoes showing the 3 levels of evaluation, you're comparing a string beginning with a percent sign against 'nothing', which will never be true.

If you've correctly loaded the %ageCount variable with the value of the dynamic variable, you could use %ageCount inside your if() statement instead of repeating the assembly of the dynamic variable again.


Like I said at the beginning, I am extremely new to this programming language. All I want is to count how many times the message is sent and if it reaches <3, 3 or >4 then do something different. My code remains to look that same as above as I don't understand what I am needing to change in your latest message.
Code:
on *:TEXT:how old is dapper:#: {
     var %ageCount = $eval($+(%,ageCount.,$nick),2)
     inc %ageCount. $+ $nick 1
     if ($($eval($+(%,ageCount.,$nick),1)) ==) {
          msg $chan !age $nick
     }
}

Joined: Jan 2019
Posts: 4
F
Self-satisified door
Offline
Self-satisified door
F
Joined: Jan 2019
Posts: 4
Here is a tiny code to get started and see what is happening, you can expand this code easily but it is also nice to see how it works (:
Code:
on *:text:how old is dapper:#: {
  inc -s %ageCount 1
  if (%ageCount >= 3) {
    //echo -a !age $nick
  }
}

Like maroon said, put a //echo after a command to see what is going on in the script, e.g:
Code:
on *:text:how old is dapper:#: {
  //echo -a thisIsTriggerd
  inc -s %ageCount 1
  //echo -a thisIsTriggerdAlso
  if (%ageCount >= 3) {
   //echo -a thisIsTheLastTrigger EOF
  }
}

etc. etc.


Link Copied to Clipboard