mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Dec 2013
Posts: 2
H
hljiu Offline OP
Bowl of petunias
OP Offline
Bowl of petunias
H
Joined: Dec 2013
Posts: 2
Hello. I've recently began messing around programming with the mIRC scripts and it's been quite fun! Right now, I'm trying to have my bot print out random facts from a text file when given a command in a twitch chat.

Approach 1)

on *:TEXT:!automode1:#: {
if ( $nick == hljiu) {
msg $chan Starting automode.
.timerLinks 0 30 msg $chan $read(facts.txt, n)
}
}


The bot is able to read a random line from my facts file every 30 seconds, but it seems that only the same fact is being read. Isn't $read supposed to pick a random line to be read for each time interval, according to the code?





Approach 2)

on *:TEXT:!automode2:#: {
if ( $nick == hljiu) {
msg $chan Starting automode.
.timerLinks 0 30 myAlias
}
}

alias myAlias {
var %linenum = $r(1,34)$
msg $chan $read(facts.txt, n, %linenum )
}

When I try this code, nothing even appears on the twitch chat that the bot is in. Instead, I see results being printed on tmi.twitch.tv instead of the current chat's channel. However, the facts being read are random this time instead of the same line being repeated like in the previous code. What is the problem here?

Joined: Dec 2013
Posts: 2
H
hljiu Offline OP
Bowl of petunias
OP Offline
Bowl of petunias
H
Joined: Dec 2013
Posts: 2
Wait, I messed up that alias.

After putting /auto inside the alias section in the script editor and the following code in remote:

alias auto {
/timerAuto 0 30 msg $chan $read( facts.txt, n, $r(1,34 ) )
}

I then try calling /auto from the channel window in the mIRC client. However, I still get the output where only one line from the text file is being output over and over.

Joined: Mar 2010
Posts: 146
Vogon poet
Offline
Vogon poet
Joined: Mar 2010
Posts: 146
You're using /timer. It evals the $read() part as soon as you execute the /timer command. That's why you get stuck with a single line. You must Use $!read() or use $eval() to prevent that.

You don't need that $r() part. $read() itself gives you a random line.


Nothing...
Joined: Dec 2013
Posts: 10
T
Pikka bird
Offline
Pikka bird
T
Joined: Dec 2013
Posts: 10
On approach 2, you're getting the wrong chan because you're doing your processing in an alias. If you notice the difference between #1 and #2 is that in #1 you pass the $chan into the msg command from the on TEXT event, whereas in #2 you give it $chan inside the alias. With timers, by the time the timer fires, it has forgotten what $chan means in context to your script, so it uses a different $chan (I forget what the rules for picking the other chan are).

To fix this, pass the $chan into your alias like:

Code:
on *:TEXT:!automode2:#: {
  if ( $nick == hljiu) {
    msg $chan Starting automode.
    .timerLinks 0 30 myAlias $chan
  }
}

alias myAlias {
  var %chan = $$1
  var %linenum = $r(1,34)$
  msg %chan $read(facts.txt, n, %linenum )
}


*I am not saying that this is the better solution to your problem. Only trying to inform you as to why it was messaging the wrong $chan.

Last edited by TestCoder; 29/12/13 04:23 PM.

Link Copied to Clipboard