mIRC Home    About    Download    Register    News    Help

Print Thread
Page 1 of 2 1 2
#208617 25/01/09 12:17 AM
Joined: Jan 2009
Posts: 25
F
Fernin Offline OP
Ameglian cow
OP Offline
Ameglian cow
F
Joined: Jan 2009
Posts: 25
Just recently, I downloaded a bot, DreamBot 5.1, for a channel I frequent. Going through its programs, I'm starting to understand how it's programmed and the ins and outs of the language for writing new commands for it. However, studying a language can only get me so far... I still only have half a clue of what I'm doing. So far, I've been able to program a new !fortune command into it, to get it to spit out a random fortune, which was a very simple thing to do, all I basically did was take one of its back talk responses and edit it into the games commands section. My next venture has been to program a new game into it, and my thoughts were either to try a hangman game or a Mastermind kind of game. However... since I'm only kind of aware of if I'm doing the right thing, I haven't had much luck yet.

Code:
;@@@ Mastermind @@@
on 1:text:*mastermind:#: {
  if (%!mastermind == on) {
    if ($1 == %c $+ mastermind) {
      if ($me !isvoice $chan) {
      MSG $chan Sorry, I've lost the privilege to speak. Try again later when I've been reactivated.
      halt
    }    
     set %fnum $rand(1,9)
     set %snum $rand(1,9)
     set %tnum $rand(1,9)
     set %hnum $rand(1,9)
     set %mnum %fnum $+ %snum $+ %tnum $+ %hnum
bt $chan The number is %mnum
	}
on 1:text:*guess:#: {
  if ($1 == %c $+ guess) {
        if (%mnum == $null) { msg $chan I'm not thinking of a number yet. | halt }
        if ($2 !isnum 1000-9999 ) { msg $chan Enter a number between 1000 and 9999 | halt }
        if ($2 == %mnum ) { 
	msg $chan You win!
                unset %mnum | halt
	}
        if ($2 != %mnum { msg $chan Guess again! | halt }
           }
}
}
}
}
}


Hmm, I think I grabbed some extra }'s at the end there...

Anyways, I know that code is hideously mangled and nowhere near right, but I think I'm doing alright, considering I just started learning this about three days ago. I'd like to continue learning this and get this crap working, so I'll finally get to my point...

Can anyone link me to a place where I can learn this programming language for mIRC?

Joined: Aug 2004
Posts: 7,252
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
I don't think I'd hear any arguements or even serious discussion on the matter, by stating that the mIRC scripter's bible is the help file.
/help

There are several sites that also have tutorials, but for the beginner, even these tutorials can be confusing.

You can check tutorials (if you think you're up to them, or just want to give them a try) at Hawkee, mIRC Scripts, and mIRC.net

Joined: Jan 2009
Posts: 25
F
Fernin Offline OP
Ameglian cow
OP Offline
Ameglian cow
F
Joined: Jan 2009
Posts: 25
While I may be a beginner at programming in mIRC, I'm hardly a beginner at programming in general. I've gone through Java, Javascript, C++, C#, VB, and a couple others, so I'm not really anticipating any trouble with this stuff. Thanks for the links, though, they'll definitely come in handy. laugh

Joined: Jan 2009
Posts: 25
F
Fernin Offline OP
Ameglian cow
OP Offline
Ameglian cow
F
Joined: Jan 2009
Posts: 25
There doesn't seem to be any kind of edit button, so I'm forced into double posting...

I've been working my way through the tutorials, and haven't yet found specifically what I'm looking for yet, the thing that'll let me move on with my program testing, so I figure it's easier to just ask... In the code there, you can see that I'm trying to get it to recognize the !guess command. When I do the !mastermind command, the bot's mIRC section tells me "ON Unknown Command." I'm assuming this is referring to the !guess command, as that gets absolutely no response from the bot, while the first section, setting the random number and telling me what it is, works just fine. What am I missing that will, for lack of a better word, activate the command?

Joined: Nov 2006
Posts: 1,559
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Nov 2006
Posts: 1,559
Most likely your code has a "bracket mismatch" resulting in a nested event (one event inside another event, not allowed). e.g.:
Code:
on <EVENT1> {
  if (something) {
    - do something - 
  }
  - do something -

  on <EVENT2> {
    - do something -
  }
}
...note that there's an "even" number of opening and closing brackets, but the second event definition is in fact interpreted like a command "on", because it's inside the command part of the first event.

It has to be like:
Code:
on <EVENT1> {
  if (something) {
    - do something - 
  }
  - do something -
}

on <EVENT2> {
  - do something -
}


mIRC will reallign (indent acc. to brackets) the code if you switch tabs in the scripts editor, or close and reopen the editor, or click the "check brackets" button (upper right corner). You'll soon get used to this method of detecting bracket problems smile

Joined: Aug 2004
Posts: 7,252
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
These forums do allow editing, but it is time sensitive.
If I recall correctly, you can edit your posts for up to 1 hour after posting.

Joined: Jan 2009
Posts: 25
F
Fernin Offline OP
Ameglian cow
OP Offline
Ameglian cow
F
Joined: Jan 2009
Posts: 25
Code:
;@@@ Mastermind @@@
on 1:text:*mastermind:#: {
  if (%!mastermind == on) {
    if ($1 == %c $+ mastermind) {
      if ($me !isvoice $chan) {
        MSG $chan Sorry, I've lost the privilege to speak. Try again later when I've been reactivated.
        halt
      }    
      set %fnum $rand(1,9)
      set %snum $rand(1,9)
      set %tnum $rand(1,9)
      set %hnum $rand(1,9)
      set %mnum %fnum $+ %snum $+ %tnum $+ %hnum
      bt $chan The number is %mnum
      	}
    }
  }
  on 1:text:*guess:#: {
    if ($1 == %c $+ guess) {
      if (%mnum == $null) { msg $chan I'm not thinking of a number yet. | halt }
      if ($2 !isnum 1000-9999) { msg $chan Enter a number between 1000 and 9999 | halt }
      if ($2 == %mnum) { 
        	msg $chan You win!
        unset %mnum | halt
        	}
        if ($2 != %mnum) { msg $chan Guess again! | halt }
      }
    }


I did what you suggested and put it into the scripts editor in mIRC (up until now I've been working in notepad, in the folders where the bot actually reads these from...)
Near as I can tell, I have an even number of brackets now and they all line up correctly, but it's telling me I have a bracket mismatch in line 18, the on 1:text:*guess:#: line. It also stops recognizing anything below this in the file with it written like this. When I add another bracket to the bottom, giving me an uneven number, it recognizes everything below this section again, but the editor tells me I have a bracket mismatch in line 4. What do I have screwed up here?

Last edited by Fernin; 25/01/09 06:56 PM.
Joined: Jun 2007
Posts: 933
5
Hoopy frood
Offline
Hoopy frood
5
Joined: Jun 2007
Posts: 933
The problem is that, in the first on TEXT event, there is a "Tab" character in front of your third closing bracket, counted from the bottom.

EDIT: the same goes for the third closing bracket from the bottom up in the second on TEXT event.

Last edited by 5618; 25/01/09 07:02 PM.
Joined: Jan 2009
Posts: 25
F
Fernin Offline OP
Ameglian cow
OP Offline
Ameglian cow
F
Joined: Jan 2009
Posts: 25
Huh, first language I've worked in where proper formatting and spacing is actually important... At least it works now, thanks.

Moving on to my next bit, I'm trying to get it to recognize each of the individual digits that are input with the !guess command. I couldn't find any normal substring function in the Text and Numbers section of the help, only things such as $left, $right, and $mid. I'm trying to be able to separate the digits out to be able to compare and use them. Say I enter !guess 5998, I'm looking for a function that will I can use to set 4 variables, which would end up with the numbers 5, 9, 9, and 8. Using $mid, I'm able to pick out the 5 and the 8, but I can't get it to grab just the 9 and the 9, it keeps grabbing 99 or 98, or in one case, 3, I still have no clue how that one happened. Which function should I be using for this task?

Last edited by Fernin; 25/01/09 10:05 PM.
Joined: Jul 2006
Posts: 4,144
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,144
You should be able to get this working with $mid :
Code:
on *:text:*:#:{
tokenize 32 $strip($1-)
;strip all control code
if ($1 == !guess) {
var %a = 1, %b = $len($$2)
while (%a <= %b) {
set -l $+(%,%a) $mid($2,%a,1)
;/set -l is the same as /var but it let you make dynamic variable (here %N where N is a number between 1- %b)
inc %a
}
echo -a > %1 - %2 - %3 - %4 ... <
} 
}


#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Joined: Jan 2009
Posts: 25
F
Fernin Offline OP
Ameglian cow
OP Offline
Ameglian cow
F
Joined: Jan 2009
Posts: 25
Getting further along now, ran into a new snag. (While I didn't end up using any of your code, Wims, you did lead me into realizing how to get the individual numbers out using $mid, so thanks for that).

I have it so that it's almost playable, save for the snag... Telling them how many numbers they have that aren't correct, but are out of place. I've been testing with the number 4678 for about the past hour or so, and every combination I've tried has ended screwy in some way. I tried using the $count function to check each guessed number against the original, as well as each original number against the guessed number, but if I entered the number 4444 as the guess, it'd come up with 1 correct and 3 out of place. I tried comparing each guessed number to each original number, but that also resulted in it telling me I had 1 correct and 3 out of place. After that, I set it up to compare each of the four guessed numbers to each other, to see if any of those were the same, and if they were, subtracting the number that was the same from the total I got in the previous attempt. (I know, flawed logic, but it got me the right answer in the one situation). On submitting 4444, it did give me the right answer of 1 correct and 0 out of place, but on trying 4111, it told me I had 1 correct and -1 out of place. Is there something obvious I'm missing as a way to compare each number and get an accurate "# out of place" total, or is this going to be far lengthier than I first thought?

Joined: Aug 2004
Posts: 7,252
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
There is absolutely nothing wrong with using a lengthy code, if it works.
Once you have a working, although, lengthy code, there are several helpers on this forum, which will be more than happy to review your code, and make suggestions as to how you can make it shorter and/or faster (note: one does not necessarily mean the other)

Regarding checking if the numbers are in the correct location or not, using a loop and comparing to instances of $mid is a good way of doing this.

You might want to take a look at my Scrambled Word Game snippet, as it appears to be similar to what you're trying to do.

Joined: Jan 2009
Posts: 25
F
Fernin Offline OP
Ameglian cow
OP Offline
Ameglian cow
F
Joined: Jan 2009
Posts: 25
Well, it's a good thing there's nothing wrong with lengthy code, this thing's getting up there already...

Code:
;@@@ Mastermind @@@
on 1:text:*mastermind:#: {
  if (%!mastermind == on) {
    if ($1 == %c $+ mastermind) {
      if ($me !isvoice $chan) {
        MSG $chan Sorry, I've lost the privilege to speak. Try again later when I've been reactivated.
        halt
      }    
      set %fnum $rand(1,9)
      set %snum $rand(1,9)
      set %tnum $rand(1,9)
      set %hnum $rand(1,9)
      set %counter 0
      set %mnum %fnum $+ %snum $+ %tnum $+ %hnum
      bt $chan I'm thinking of a number... It's a four digit number, between 1000 and 9999. Try and guess it with !guess (####)
    }
  }
}
on 1:text:*guess*:#: {
  if ($1 == %c $+ guess) {
    if (%mnum == $null) { msg $chan I'm not thinking of a number yet. | halt }
    if ($2 !isnum 1000-9999) { msg $chan Enter a number between 1000 and 9999 | halt }
    if ($2 == %mnum) { 
      msg $chan That's right! %mnum $+ ! You win, $nick $+ ! And it only took %counter guesses. Type !mastermind to start a new guessing game.
      unset %mnum | halt
    }
    if ($2 != %mnum) { 
      inc %counter
      set %gfnum $mid($2, 1, 1)
      set %gsnum $mid($2, 2, 1)
      set %gtnum $mid($2, 3, 1)
      set %ghnum $mid($2, 4, 1)
      set %correct 0
      set %close1 0
      set %closef 0
      set %closes 0
      set %closet 0
      set %closeh 0
      if (%gfnum == %fnum) { inc %closef }
      if (%gfnum == %snum) { inc %closef }
      if (%gfnum == %tnum) { inc %closef }
      if (%gfnum == %hnum) { inc %closef }
      if (%gsnum == %snum) { inc %closes }
      if (%gsnum == %tnum) { inc %closes }
      if (%gsnum == %hnum) { inc %closes }
      if (%gsnum == %fnum) { inc %closes }
      if (%gtnum == %tnum) { inc %closet }
      if (%gtnum == %hnum) { inc %closet }
      if (%gtnum == %fnum) { inc %closet }
      if (%gtnum == %snum) { inc %closet }
      if (%ghnum == %hnum) { inc %closeh }
      if (%ghnum == %fnum) { inc %closeh }
      if (%ghnum == %snum) { inc %closeh }
      if (%ghnum == %tnum) { inc %closeh }
      if (%gfnum == %fnum) { inc %correct }
      if (%gsnum == %snum) { inc %correct }
      if (%gtnum == %tnum) { inc %correct }
      if (%ghnum == %hnum) { inc %correct }
      if (%closef >= 1) { inc %close1 }
      if (%closes >= 1) { inc %close1 }
      if (%closet >= 1) { inc %close1 }
      if (%closeh >= 1) { inc %close1 }
      set %close %close1 - %correct 
      msg $chan You have %correct correct.
      msg $chan You have %close out of place.
    }
  }
}


Sorry for the lack of comments, I almost never comment my own work... Should be fairly easy to follow, though. The code works fine, it just has logical errors in it leading to it being screwy, depending what number is set and what numbers are guessed. (Which obviously isn't a good thing). And if you're still unsure of what it is I'm trying to do, take a look at the wiki page for the game: http://en.wikipedia.org/wiki/Mastermind_(board_game) ...Yeah, that was supposed to be linked way back up in the first post, I dunno how the other page ended up getting linked. Must've had the wrong thing copied at the time.

Last edited by Fernin; 27/01/09 01:04 AM.
Joined: Jun 2007
Posts: 933
5
Hoopy frood
Offline
Hoopy frood
5
Joined: Jun 2007
Posts: 933
I haven't tested it, but try this...
Code:
on 1:text:*guess*:#: {
  if ($1 == %c $+ guess) {
    if (%mnum == $null) { msg $chan I'm not thinking of a number yet. | halt }
    if ($2 !isnum 1000-9999) { msg $chan Enter a number between 1000 and 9999 | halt }
    if ($2 == %mnum) { 
      msg $chan That's right! %mnum $+ ! You win, $nick $+ ! And it only took %counter guesses. Type !mastermind to start a new guessing game.
      unset %mnum | halt
    }
    if ($2 != %mnum) { 
      inc %counter
      var %gfnum = $mid($2, 1, 1), %gsnum = $mid($2, 2, 1), %gtnum = $mid($2, 3, 1), %ghnum = $mid($2, 4, 1)
      var %correct = 0, %close = 0
      var %numbers = $+(%fnum,.,%snum,.,%tnum,.,%hnum)
      if (%gfnum == %fnum)      { inc %correct | var %numbers = $remtok(%numbers,%gfnum,1,46) }
      if (%gsnum == %snum)      { inc %correct | var %numbers = $remtok(%numbers,%gsnum,1,46) }
      if (%gtnum == %tnum)      { inc %correct | var %numbers = $remtok(%numbers,%gtnum,1,46) }
      if (%ghnum == %hnum)      { inc %correct | var %numbers = $remtok(%numbers,%ghnum,1,46) }
      if (%gfnum isin %numbers) { inc %close | var %numbers = $remtok(%numbers,%gfnum,1,46) }
      if (%gsnum isin %numbers) { inc %close | var %numbers = $remtok(%numbers,%gsnum,1,46) }
      if (%gtnum isin %numbers) { inc %close | var %numbers = $remtok(%numbers,%gtnum,1,46) }
      if (%ghnum isin %numbers) { inc %close | var %numbers = $remtok(%numbers,%ghnum,1,46) }
      msg $chan You have %correct correct.
      msg $chan You have %close out of place.
    }
  }
}


P.S. You may want to use $rand(1000,9999) to set %mnum, since now your number will never contain zeros, unless that is you intention. If that is indeed your intention, then you should probably change your statement where you check if the input isnum 1000-9999 to also check for "if (0 !isin $$2)" or people may be trying with zeros for ages.

Last edited by 5618; 27/01/09 07:04 PM.
Joined: Jan 2009
Posts: 25
F
Fernin Offline OP
Ameglian cow
OP Offline
Ameglian cow
F
Joined: Jan 2009
Posts: 25
Hmm, that's a lot better than what I had, but there's still some tinkering to be done... I noticed that the $remtok block always removed %gfnum from %numbers, I'm assuming it's supposed to be two %gfnums, two %gsnums, so on down the line. Even after making that switch, however, there's still some logical errors somewhere in it. Testing out 1223 right now, when I guess 1111, it tells me I have one correct and one out of place. Same number, guessing 2222, it tells me I have two correct and one out of place, guessing 3333, it tells me 1 correct and 0 out of place. The 3 seems to be the only one working, though I haven't figured out why yet. Progress is definitely good, though, and I do appreciate all your help. smile

Joined: Jun 2007
Posts: 933
5
Hoopy frood
Offline
Hoopy frood
5
Joined: Jun 2007
Posts: 933
I did mess up those vars, yes. Maybe you changed it incorrectly? Try with my (now) edited code. I see no reason why you'd get '1 out of place'.

Joined: Jan 2009
Posts: 25
F
Fernin Offline OP
Ameglian cow
OP Offline
Ameglian cow
F
Joined: Jan 2009
Posts: 25
I didn't change them incorrectly, they were spot on. You're absolutely right that it should work, but for whatever reason, it isn't. I have exactly what you have down, but it's still not working. I'm trying to figure out, logically, how 2222 could end up with 1 correct and 2 out of place, and I'm ending up confused... It'd check the first 2, find that it is in %numbers, add 1 to %close, then remove a 2 from %numbers. But then, how would there still be a pair of 2's for it to tell me that there are 2 correct?

Joined: Jun 2007
Posts: 933
5
Hoopy frood
Offline
Hoopy frood
5
Joined: Jun 2007
Posts: 933
Note that my code may have changed since you last looked at it. wink

Joined: Jan 2009
Posts: 25
F
Fernin Offline OP
Ameglian cow
OP Offline
Ameglian cow
F
Joined: Jan 2009
Posts: 25
Well, that new code has definitely come the closest to being right, but there's still some errors when the actual number has 2 or more digits the same... I logged this earlier today.

[14:13] <not_sure> !guess 2359
[14:13] <+LexiaBot9000> You have 2 correct and 2 out of place.
[14:14] <not_sure> !guess 2953
[14:14] <+LexiaBot9000> You have 0 correct and 3 out of place.
[14:14] <not_sure> uh oh
[14:14] <Fernin> ohhh bother...
[14:14] <not_sure> !guess 5329
[14:14] <+LexiaBot9000> You have 3 correct and 1 out of place.
[14:15] <not_sure> well, umm
[14:15] <not_sure> !guess 2222
[14:15] <+LexiaBot9000> You have 0 correct and 0 out of place.
[14:15] <not_sure> !guess 3333
[14:15] <+LexiaBot9000> You have 2 correct and 0 out of place.
[14:15] <not_sure> !guess 5339
[14:15] <+LexiaBot9000> That's right! 5339! You win, not_sure!

And unrelated to that is another problem I'm having, setting up a score file for it to keep track of everyone's scores.

Code:
on 1:text:*score:#: {
  if ($1 == %c $+ score) {
    set %sname $2
    if (%sname != $null) && ($readini(ini\mastermind.rank,Rank,%sname) != $null) {
      msg $chan %sname $+ 's current record is $readini(ini\mastermind.rank,Rank,%sname) guesses.
    }
    if (%sname != $null) && ($readini(ini\mastermind.rank,Rank,%sname) == $null) {
      msg $chan I don't have any records for nick %sname $+ .
    }
    if (%sname == $null) && ($readini(ini\mastermind.rank,Rank,$nick) != $null) {
      msg $chan $nick $+ , your current record is $readini(ini\mastermind.rank,Rank,$nick) guesses.
    }
    else {
      msg $chan ...Who the hell are you again? I don't have any records for $nick $+ .
    }    
  }
}


As of now, the else works, and the third if, with %sname null and their record not null also works. However, when you try to look up either a name it does or doesn't have, it does nothing. What'd I screw up this time?

Edit: Before you ask, and I know you will since it's the obvious thing to ask, the file does exist, in that location, and I know it's being written to correctly when they get an answer right.

Last edited by Fernin; 29/01/09 01:54 AM.
Joined: Jun 2007
Posts: 933
5
Hoopy frood
Offline
Hoopy frood
5
Joined: Jun 2007
Posts: 933
Ok, quick (dirty) fix:
Code:
    if ($2 != %mnum) { 
      inc %counter
      var %gfnum = $mid($2, 1, 1), %gsnum = $mid($2, 2, 1), %gtnum = $mid($2, 3, 1), %ghnum = $mid($2, 4, 1)
      var %correct = 0, %close = 0
      var %numbers = $+(%fnum,.,%snum,.,%tnum,.,%hnum)
      if (%gfnum == %fnum)      { inc %correct | var %gfnum = x | var %numbers = $remtok(%numbers,%gfnum,1,46) }
      if (%gsnum == %snum)      { inc %correct | var %gsnum = x | var %numbers = $remtok(%numbers,%gsnum,1,46) }
      if (%gtnum == %tnum)      { inc %correct | var %gtnum = x | var %numbers = $remtok(%numbers,%gtnum,1,46) }
      if (%ghnum == %hnum)      { inc %correct | var %ghnum = x | var %numbers = $remtok(%numbers,%ghnum,1,46) }
      if (%gfnum isin %numbers) { inc %close | var %numbers = $remtok(%numbers,%gfnum,1,46) }
      if (%gsnum isin %numbers) { inc %close | var %numbers = $remtok(%numbers,%gsnum,1,46) }
      if (%gtnum isin %numbers) { inc %close | var %numbers = $remtok(%numbers,%gtnum,1,46) }
      if (%ghnum isin %numbers) { inc %close | var %numbers = $remtok(%numbers,%ghnum,1,46) }
      msg $chan You have %correct correct.
      msg $chan You have %close out of place.
    }

And...
Code:
on 1:text:*score:#: {
  if ($1 == %c $+ score) {
    if ($2) {
      set %sname $2
      if ($readini(ini\mastermind.rank,Rank,%sname)) { msg $chan %sname $+ 's current record is $v1 guesses. }
      else { msg $chan I don't have any records for nick %sname $+ . }
    }
    elseif ($readini(ini\mastermind.rank,Rank,$nick)) { msg $chan $nick $+ , your current record is $v1 guesses. }
    else { msg $chan ...Who the hell are you again? I don't have any records for $nick $+ . }    
  }
}

Your initial code wasn't exactly wrong, I just made it look nicer/more efficient. Your problem was the matchtext section of the on TEXT event:
Code:
on 1:text:*score:#: {

You're matching *score so any sentence ending in score, like !score, flooblescore, highscore, but not score Fernin or scoresofwomen.

Page 1 of 2 1 2

Link Copied to Clipboard