mIRC Home    About    Download    Register    News    Help

Print Thread
Page 1 of 3 1 2 3
#187690 10/10/07 08:18 PM
Joined: Apr 2007
Posts: 228
M
Mpot Offline OP
Fjord artisan
OP Offline
Fjord artisan
M
Joined: Apr 2007
Posts: 228
I've been thinking about this for a while, but I'm not sure how I'd pull it off. Something with $read, I'm sure, but I don't /what/ to do with $read. Basically, let's say if $nick join #, and if $nick matched a line in a .txt file, it would run a command on them.

Something like

if ($nick isin $read(friends.txt)) { msg $chan Hi there buddy! }

But that'd pick a random line. And I'm sure that's not a valid format. Just a demonstration of sorts.

Ideas?

Mpot #187691 10/10/07 08:35 PM
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
Actually, your format is valid. And, yes, that picks a random line. If you wanted a specific line, you could include that. If the lines were specific to the nicks, you could also use $readini and then get the line for that specific nick.

Of course, nicer method is using hash tables to store the information. Here's a quick example:

Code:
on *:start: {
  NickRespTable
}

alias NickRespTable {
  hmake NickResp 100
  if ($exists($scriptdir\NickResp.txt)) { hload NickResp $scriptdir\NickResp.hsh }
}

on *:join:#: {
  if (!$hget(NickResp)) { NickRespTable }
  if ($hget(NickResp,$nick)) { msg $chan $v1 }
}

alias AddNewNickResp {
  if (!$hget(NickResp)) { NickRespTable }
  hadd NickResp $$?="Enter a nickname" $$?="Enter the message"
  hsave NickResp $scriptdir\NickResp.hsh 
}

alias RemNickResp {
  if (!$hget(NickResp)) { NickRespTable }
  var %nick = $iif($1,$1,$$?="Enter Nick")
  if ($hget(NickResp,%nick)) { hdel NickResp %nick }
  hsave NickResp $scriptdir\NickResp.hsh
}

menu channel,status {
  Nick Responder
  .Add Nick:AddNewNickResp
  .Remove Nick:RemNickResp
}

menu nicklist,query {
  Nick Responder
  .Add $1:AddNewNickResp $1
  .Remove $1:RemNickResp $1
}


You can add and remove nicks/messages by right clicking in the channel, status, or query window, or in the nick list.


Invision Support
#Invision on irc.irchighway.net
Riamus2 #187694 10/10/07 09:22 PM
Joined: Apr 2007
Posts: 228
M
Mpot Offline OP
Fjord artisan
OP Offline
Fjord artisan
M
Joined: Apr 2007
Posts: 228
Er... the $nick was just an example, really.

ANYWAY.

A. What's a hash table?
B. How do you create one of those nice clicky menus? I read the help file on popups, it went straight through one ear and out the other. That could be REALLY nice for sending certain information to my bot.

EDIT:

Okay, so I played with it, and I made this up:
Code:
MsgMyself
.Food
..Cake:/msg $me You bake yourself a cake
..Ice Cream:/msg $me You serve yourself a bowl of ice cream
.Drink
..Coke:/msg $me You hand yourself a Coke
..Sprite:/msg $me You hand yourself a Sprite


I put that in the "popups" tab, which I've never touched before. The name of the file in the popups tab was "status"

So I try it in the status window, worked pretty well, except for the fact that it /msg's itself twice instead of once. Oops, nevermind, that was me sending it to myself, and me receiving. -facepalm-

And it only works in the status window.

Questions:

1.How do you make it work in any window?

2.How do you put a popup in the script?

3.How do you ask for data to be inputed in a popup?

4.How do you ask a series of questions and then perform one command with that data***

***: Example: I rightclick on the nickname "IcyBot" on the nicklist, and one of the options, below kick and ban and kickban and stuff, separated with a line (- on a line by itself, says helpfile) and the option is "Add a bar". So then, when I click that, a window comes up asking for the call up code and I input the data and press ok, then another comes up asking for the nickname and I input the data and press ok, and then another comes up asking for the bar, and when I press OK it sends a command to the bot with "!addbar $$1 $$2 $$3" or something like that.

I know, wall of text, but I kinda got excited. blush

Last edited by Mpot; 10/10/07 10:06 PM.
Mpot #187754 11/10/07 09:53 PM
Joined: Apr 2007
Posts: 228
M
Mpot Offline OP
Fjord artisan
OP Offline
Fjord artisan
M
Joined: Apr 2007
Posts: 228
Alright. Let's say I rightclick on my bot's nickname on the nicklist, and below all the options, it has "send bar"

So I click on it and I get three popup boxes, one after the other

Input data, press OK, script sets %data1 with $?, next box comes up
Input data, press OK, script sets %data2 with $?, next box comes up
Input data, press OK, script sets %data 3, messages bot with %data1 %data2 %data3

I think I know how to make the menu come up, but I'm not sure how to make it open three boxes like that...

Mpot #187765 12/10/07 12:43 AM
Joined: Apr 2003
Posts: 342
M
Fjord artisan
Offline
Fjord artisan
M
Joined: Apr 2003
Posts: 342
Can't this be done using the -s switch on the $read fuction. It finds the first line that begins w/ that string and returns it.



Beware of MeStinkBAD! He knows more than he actually does!
MeStinkBAD #187798 12/10/07 09:55 PM
Joined: Apr 2007
Posts: 228
M
Mpot Offline OP
Fjord artisan
OP Offline
Fjord artisan
M
Joined: Apr 2007
Posts: 228
Er, please read the whole thread next time. We've moved on to popups.

Speaking of popups, does anyone have ideas?

Mpot #187799 12/10/07 10:14 PM
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
Just use $input or $?=""...

Code:
alias GetInfo {
  var %data1 = $?="Enter 1"
  var %data2 = $?="Enter 2"
  var %data3 = $?="Enter 3"
  echo -a %data1 ~ %data2 ~ %data3
}


You can do the same thing with $input. Just remember that you can't put $input or $?="" in certain events unless you use a timer.


Invision Support
#Invision on irc.irchighway.net
Riamus2 #187800 12/10/07 10:30 PM
Joined: Apr 2007
Posts: 228
M
Mpot Offline OP
Fjord artisan
OP Offline
Fjord artisan
M
Joined: Apr 2007
Posts: 228
Ah! I never even considered aliases. Alright, how good is this:

(appended to the end of the Nick List popup file)

Code:
-
Send Bar:/icybotbar

alias icybotbar {
set %bardata1 $?="Callup Code?"
set %bardata2 $?="Nickname for greet?"
set %bardata3 $?="Color banner?"
msg IcyBot !addbar %bardata1 %bardata2 %bardata3
unset %bardata1
unset %bardata2
unset %bardata3
}


Will that come up with an input box, and the two buttons being either "OK" or "Cancel"? And it brings up the three boxes in succession? ANd then sends?

Perhaps, put the alias in it's own script?

Last edited by Mpot; 12/10/07 10:43 PM.
Mpot #187802 12/10/07 11:26 PM
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
Why not just test it?

And the alias doesn't need to be in a separate file.


Invision Support
#Invision on irc.irchighway.net
Riamus2 #187804 12/10/07 11:34 PM
Joined: Apr 2007
Posts: 228
M
Mpot Offline OP
Fjord artisan
OP Offline
Fjord artisan
M
Joined: Apr 2007
Posts: 228
I'm not a fan of testing things like that, because I usually feel like I'll royally bugger something up. Could you tell me if that's valid?

Mpot #187805 13/10/07 12:02 AM
Joined: Feb 2007
Posts: 75
T
Babel fish
Offline
Babel fish
T
Joined: Feb 2007
Posts: 75
From the quick glance I took, it should work fine as it is.

Royal Bugger ups happen, but it's very unlikely with a simple popup mod you are doing. If your popup isn't working because of it, just remove the bits of code you added. On the other hand you could install another copy of mIRC and use it to test code if you are afraid of breaking the one you use.


GigIRC Network Admin
irc.gigirc.com
Trixar_za #187806 13/10/07 12:06 AM
Joined: Apr 2007
Posts: 228
M
Mpot Offline OP
Fjord artisan
OP Offline
Fjord artisan
M
Joined: Apr 2007
Posts: 228
Is there a way I can set this to ONLY pop-up if the nickname right-clicked on in the nickname listbox is IcyBot? Perhaps an if $nick == IcyBot ? If so, where?

Mpot #187810 13/10/07 02:11 AM
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
Change $nick to $1 and put it into an $iif().

As for testing, run it on a test client and change things and make sure it works there. You'll have your answer more quickly than asking here and it saves us time trying to look through your code when you could have gotten your answer in 5 seconds yourself.


Invision Support
#Invision on irc.irchighway.net
Riamus2 #187811 13/10/07 02:55 AM
Joined: Apr 2007
Posts: 228
M
Mpot Offline OP
Fjord artisan
OP Offline
Fjord artisan
M
Joined: Apr 2007
Posts: 228
What is an $iif?

Mpot #187816 13/10/07 10:05 AM
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
/help $iif

If you're going to put it into a menu, you'll want to use $iif.

Code:
menu nicklist {
  $iif($1 == whatever,Show this menu option):Do this
}


Note that you can leave off the "false" part like I did if you don't need it to do something when it's not true.


Invision Support
#Invision on irc.irchighway.net
Riamus2 #187825 13/10/07 05:48 PM
Joined: Apr 2007
Posts: 228
M
Mpot Offline OP
Fjord artisan
OP Offline
Fjord artisan
M
Joined: Apr 2007
Posts: 228
I don't really understand how to integrate this into the script I scraped up.

Mpot #187906 14/10/07 11:02 PM
Joined: Apr 2007
Posts: 228
M
Mpot Offline OP
Fjord artisan
OP Offline
Fjord artisan
M
Joined: Apr 2007
Posts: 228
Anyone?

Last edited by Mpot; 14/10/07 11:46 PM.
Mpot #187908 14/10/07 11:48 PM
Joined: Apr 2007
Posts: 228
M
Mpot Offline OP
Fjord artisan
OP Offline
Fjord artisan
M
Joined: Apr 2007
Posts: 228
Furthermore:

Is there an identifier that can check the mode on a channel?

Ex:

Code:
if ($mode == +c) { msg $chan Sorry, colors are disabled on $chan $+ . You'll need to find somewhere else to play Uno. }


(Not saying that $mode exists, just sort of an idea of what I'm looking for)




FURTHERMORE:

You know the users list? Well, is there an identifier for that? Perhaps something like:

Code:
if ($user($nick) == syscon) { msg $nick You can not ban a bot operator! }


EDIT: Could it be

Code:
(if $level($address($2,2)) == syscon) { msg $nick You can not ban a bot operator! }


Last edited by Mpot; 14/10/07 11:58 PM.
Mpot #187910 15/10/07 12:21 AM
Joined: Dec 2002
Posts: 2,033
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Dec 2002
Posts: 2,033
Originally Posted By: Mpot

Is there an identifier that can check the mode on a channel?


Code:

if (c isincs $chan(#chan).mode) { msg $chan Sorry, colors are disabled on $chan $+ . You'll need to find somewhere else to play Uno. }



~ Edit ~

Corrected typo from isncs to isincs

Mpot #187920 15/10/07 03:26 AM
Joined: Nov 2006
Posts: 1,559
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Nov 2006
Posts: 1,559
Originally Posted By: Mpot

Code:
if ($user($nick) == syscon) { msg $nick You can not ban a bot operator! }


EDIT: Could it be

Code:
(if $level($address($2,2)) == syscon) { msg $nick You can not ban a bot operator! }


Try a
Code:
if ($istok($remove($level(NICK/MASK),=),YOURLEVEL,44)) { stuff }
NICK/MASK depends on how you added users to your user list
change YOURLEVEL to the level you assigned to bot operators

I used "istok" as you can assign more than one level per entry of the users list; and I used "$remove(bla,=)" to get arround forced levels. It's not airtight (named levels could contain a = char)... Anyway, I just want to point in that direction.

Last edited by Horstl; 15/10/07 03:32 AM.
Horstl #187962 15/10/07 08:15 PM
Joined: Apr 2007
Posts: 228
M
Mpot Offline OP
Fjord artisan
OP Offline
Fjord artisan
M
Joined: Apr 2007
Posts: 228
Thanks, RoCk!

Horstl, I don't understand that. Could you explain what a token is?

Mpot #187968 15/10/07 09:36 PM
Joined: Apr 2007
Posts: 228
M
Mpot Offline OP
Fjord artisan
OP Offline
Fjord artisan
M
Joined: Apr 2007
Posts: 228
Code:
;Kick
on syscon:text:!kick*:#: {
  if ($2 == $null) { msg $chan Specify a nickname. | halt }
  if ($2 !ison $chan) { msg $chan $2 is not on $chan $+ ! | halt }
  if ($level($address($2,2)) == syscon) { msg $chan You can not kick a bot operator! | halt }  
  kick $chan $2 $3-
  /write C:\IcyBot2\Scripts\op_log.txt On $date(dddd $+ $chr(44) mmmm d $+ $chr(44) yyyy) at $time(h:nn:ss TT) $nick used $$1 $$2 $3- on $chan
}


Okay. So. I'm using all IF's because if one doesn't click, I want it to go to the next one. Maybe I'm not remembering correctly, but if an elseif doesn't click, doesn't it not go to the next line? I decided to ask because the script is taking far too long to respond.

Also, right now, I'm using separate on TEXT events, one with # for channels and one with ? for msgs. I know I could just use * for everything, but I have a different logging method for channel, and query**. What could I do?

**Differnt methods:

Msg:
Code:
 /write C:\IcyBot2\Scripts\op_log.txt On $date(dddd $+ $chr(44) mmmm d $+ $chr(44) yyyy) at $time(h:nn:ss TT) $nick used $$1 $$2 $$3 $4- via msg


Channel:
Code:
/write C:\IcyBot2\Scripts\op_log.txt On $date(dddd $+ $chr(44) mmmm d $+ $chr(44) yyyy) at $time(h:nn:ss TT) $nick used $$1 $$2 $3- on $chan

Last edited by Mpot; 15/10/07 09:49 PM.
Mpot #187980 15/10/07 10:28 PM
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
ELSEIF is a better method of doing multiple IF|HALT's. As we stated many times, don't use HALT. If you actually need to halt a script, use RETURN. But for a script that you want to stop after the first IF matches, use ELSEIF. Only do multiple IFs if you want them ALL to check even if the first one(s) match. Of course, if you couldn't remember, you could have just tried it...

If you want to use # and ? together, just do a check inside the script in the part(s) that are different...

Code:
if ($chan) { do the part for channels }
else { do the part for queries }


Note that you can just stick to # and ? without using *. This keeps you from trying to respond to dcc chats and such.

Code:
on *:text:whatever:#,?: { }


Invision Support
#Invision on irc.irchighway.net
Riamus2 #187988 15/10/07 10:53 PM
Joined: Apr 2007
Posts: 228
M
Mpot Offline OP
Fjord artisan
OP Offline
Fjord artisan
M
Joined: Apr 2007
Posts: 228
I might wanna use an elseif for queries instead of else. What can we do for that?

And: https://forums.mirc.com/ubbthreads.php?ub...rt=1#Post187825

And: I'm writing a remote login script for IcyBot, is there something to mess with the users list, or do I have to /write and /read the file? Furthermore, I only want the remote access to last for an hour, so would I have to do something like find the line with read and then delete it? If so, how?

Mpot #188001 16/10/07 12:36 AM
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
/help /auser
/help /guser
/help /ruser
/help /rlevel
/help $ulevel
/help $ulist


Invision Support
#Invision on irc.irchighway.net
RoCk #188041 16/10/07 06:36 PM
Joined: Jun 2006
Posts: 508
D
Fjord artisan
Offline
Fjord artisan
D
Joined: Jun 2006
Posts: 508
Originally Posted By: RoCk
Originally Posted By: Mpot

Is there an identifier that can check the mode on a channel?


Code:

if (c isincs $chan(#chan).mode) { msg $chan Sorry, colors are disabled on $chan $+ . You'll need to find somewhere else to play Uno. }



~ Edit ~

Corrected typo from isncs to isincs


"c" may also be in a channels key, to be safe...
if (c isincs $gettok($chan(#chan).mode,1,32)) {

deegee #188052 16/10/07 09:27 PM
Joined: Apr 2007
Posts: 228
M
Mpot Offline OP
Fjord artisan
OP Offline
Fjord artisan
M
Joined: Apr 2007
Posts: 228
I took a wild guess, and I hope this is good. Tell me what you think!

Code:
on *:TEXT:!login*:?: {
  if ($2 == $null) { msg $nick Switch to the nick you registered with, and type !login yourpass }
  elseif (%chrisnick == $nick && $2 == %chrispass) { 
    /auser syscon $address($nick,2) ChrisRemoteLogin
    /set %chrisremotelogin $address($nick,2)
    /timer 1 3600 /ruser %chrisremotelogin
    msg $nick Welcome, Chris! Access at level syscon has been given to $address($nick,2) for 1 hour.
  }
  else { msg $nick Access Denied. }
}

on syscon:TEXT:!changepass*:?: {
  if (%chrisnick == $nick) {
    if ($2 == $null) { msg $nick Specify old password, Chris. }
    elseif ($2 != $null && $3 == $null) { msg $nick Specify new password, Chris. }
    elseif (%chrispass != $2) { msg $nick Incorrect old password, Chris. }
    elseif (%chrispass == $2) { /set %chrispass $3 | msg $nick New password is $$3 $+, Chris. }
    else { halt }
  }
  else { halt }
}

on syscon:TEXT:!changenick*:?: {
  if (%chrisnick == $nick) {
    if ($2 == $null) { msg $nick Specify your password, Chris. }
    elseif ($2 != $null && $3 == $null) { msg $nick Specify a new login nick, Chris. }
    elseif ($2 != %chrispass) { msg $nick Incorrect password, Chris. }
    elseif ($2 == %chrispass { /set %chrisnick $3 | msg $nick New login nick is $$3 $+ , Chris. }
    else { halt }
  }
  else { halt }
}


I think there's a problem with the /auser. I would've used /guser, but then I wouldn't know what to remove with /ruser since we wouldn't have an address.
Beta testing has since rendered this incorrect.

OKAY, also, I need to add in a line. If $address($nick,2) is on the user list, msg $nick You already have syscon access! But I don't know what identifier to use for that. How does $ulist work? Edit: Could it be: if (syscon isin $level($address($me,2))) { msg $nick You already have syscon access! } ?

And, popups help anyone?

Last edited by Mpot; 17/10/07 01:19 AM.
Mpot #188098 17/10/07 08:12 PM
Joined: Apr 2007
Posts: 228
M
Mpot Offline OP
Fjord artisan
OP Offline
Fjord artisan
M
Joined: Apr 2007
Posts: 228
Is it the $level thing?

Mpot #188175 18/10/07 10:26 PM
Joined: Jun 2006
Posts: 508
D
Fjord artisan
Offline
Fjord artisan
D
Joined: Jun 2006
Posts: 508
If you tried it you'd have known. wink


deegee #188179 18/10/07 10:59 PM
Joined: Apr 2007
Posts: 228
M
Mpot Offline OP
Fjord artisan
OP Offline
Fjord artisan
M
Joined: Apr 2007
Posts: 228
Well you could just tell me?

Mpot #188180 18/10/07 11:06 PM
Joined: Jun 2006
Posts: 508
D
Fjord artisan
Offline
Fjord artisan
D
Joined: Jun 2006
Posts: 508
Originally Posted By: Mpot
I took a wild guess, and I hope this is good. Tell me what you think!

Code:
on *:TEXT:!login*:?: {
  if ($2 == $null) { msg $nick Switch to the nick you registered with, and type !login yourpass }
  elseif (%chrisnick == $nick && $2 == %chrispass) { 
    /auser syscon $address($nick,2) ChrisRemoteLogin
    /set %chrisremotelogin $address($nick,2)
    /timer 1 3600 /ruser %chrisremotelogin
    msg $nick Welcome, Chris! Access at level syscon has been given to $address($nick,2) for 1 hour.
  }
  else { msg $nick Access Denied. }
}

on syscon:TEXT:!changepass*:?: {
  if (%chrisnick == $nick) {
    if ($2 == $null) { msg $nick Specify old password, Chris. }
    elseif ($2 != $null && $3 == $null) { msg $nick Specify new password, Chris. }
    elseif (%chrispass != $2) { msg $nick Incorrect old password, Chris. }
    elseif (%chrispass == $2) { /set %chrispass $3 | msg $nick New password is $$3 $+, Chris. }
    else { halt }
  }
  else { halt }
}

on syscon:TEXT:!changenick*:?: {
  if (%chrisnick == $nick) {
    if ($2 == $null) { msg $nick Specify your password, Chris. }
    elseif ($2 != $null && $3 == $null) { msg $nick Specify a new login nick, Chris. }
    elseif ($2 != %chrispass) { msg $nick Incorrect password, Chris. }
    elseif ($2 == %chrispass { /set %chrisnick $3 | msg $nick New login nick is $$3 $+ , Chris. }
    else { halt }
  }
  else { halt }
}

Lose the /halts
Lose the slashes
Code:
    /set %chrisremotelogin $address($nick,2)
    /timer 1 3600 /ruser %chrisremotelogin
If %chrisremotelogin is only used for that code, then replace those lines with .timer 1 3600 .ruser syscon $wildsite

Code:
    elseif ($2 != %chrispass) { }
    elseif ($2 == %chrispass { }
^^The second elseif is redundant^^
Code:
    elseif ($2 != %chrispass) { }
    else { }
$2 will match %chrispass, or not, there is no other option laugh
Same here
Code:
    if ($2 == $null) {  }
    elseif ($3 == $null) { }
No need to check if $2 != $null, if it did then it would have been caught in the first /if, besides which, if $2 was NULL then there could be no $3.

It would be better, IMHO, to hash the password and store/compare against that. (see /help $md5 [color:black]or /help $sha1[/color])

Also I think you should use $wildsite instead of $address($nick,2) in ? events. $address() relies on the IAL, if someone PMs without being on a common channel, $address() will not be valid.
Note though that $wildsite won't work outside of remote events. You can't for instance use it in a popup.

Mpot #188181 18/10/07 11:07 PM
Joined: Jun 2006
Posts: 508
D
Fjord artisan
Offline
Fjord artisan
D
Joined: Jun 2006
Posts: 508
Originally Posted By: Mpot
I don't really understand how to integrate this into the script I scraped up.
Riamus showed you how...

deegee #188183 18/10/07 11:36 PM
Joined: Apr 2007
Posts: 228
M
Mpot Offline OP
Fjord artisan
OP Offline
Fjord artisan
M
Joined: Apr 2007
Posts: 228
Originally Posted By: deegee
Originally Posted By: Mpot
I don't really understand how to integrate this into the script I scraped up.
Riamus showed you how...


I posted that after he showed me how, meaning I must still not understand.

Mpot #188184 18/10/07 11:47 PM
Joined: Jun 2006
Posts: 508
D
Fjord artisan
Offline
Fjord artisan
D
Joined: Jun 2006
Posts: 508
Originally Posted By: Mpot
Originally Posted By: deegee
Originally Posted By: Mpot
I don't really understand how to integrate this into the script I scraped up.
Riamus showed you how...
Originally Posted By: Riamus2
/help $iif

If you're going to put it into a menu, you'll want to use $iif.

Code:
menu nicklist {
  $iif($1 == whatever,Show this menu option):Do this
}


Note that you can leave off the "false" part like I did if you don't need it to do something when it's not true.


I posted that after he showed me how, meaning I must still not understand.

So what don't you understand?
  • $iif($1 == whatever,Show this menu option):Do this

Change whatever to icybot
Change Show this menu option to what you want to eppear in the popup menu.
Change Do this to the command you want to perfom if you click on that menu item.

See /help popup menus for more info and examples, and /help $iif

deegee #188185 19/10/07 12:00 AM
Joined: Apr 2007
Posts: 228
M
Mpot Offline OP
Fjord artisan
OP Offline
Fjord artisan
M
Joined: Apr 2007
Posts: 228
What's an $iif? I don't understand the help file on it.

Mpot #188186 19/10/07 12:06 AM
Joined: Jun 2006
Posts: 508
D
Fjord artisan
Offline
Fjord artisan
D
Joined: Jun 2006
Posts: 508
$iif() is pretty much the same as if (), except used 'inline'.

//echo -ag $iif(1 == 1,true,false) :: $iif(this == that,true,false) :: $iif($server,$v1,not connected)

deegee #188187 19/10/07 12:11 AM
Joined: Apr 2007
Posts: 228
M
Mpot Offline OP
Fjord artisan
OP Offline
Fjord artisan
M
Joined: Apr 2007
Posts: 228
Originally Posted By: deegee
$iif() is pretty much the same as if (), except used 'inline'.

//echo -ag $iif(1 == 1,true,false) :: $iif(this == that,true,false) :: $iif($server,$v1,not connected)


Inline? That line makes no sense to me.

Mpot #188189 19/10/07 12:41 AM
Joined: Dec 2002
Posts: 503
B
Fjord artisan
Offline
Fjord artisan
B
Joined: Dec 2002
Posts: 503
Originally Posted By: Mpot
Inline? That line makes no sense to me.

Inline-If.

If you've programmed in C or PHP or Perl, it has a thing called the ternary (or '?:') operator. $iif() is basically mIRC's version of that.

Simply put, it allows you to do actions inline based on a condition. The demonstration deegree showed shows it's usage beautifully.

Here's roughly how it would work if you did it in a normal /if structure:

Code:
var %output
if (1 == 1) {
  %output = %output true
}
else {
  %output = %output false
}
%output = %output ::
if (this == that) {
  %output = %output true
}
else {
  %output = %output false
}
%output = %output ::
if ($server) {
  %output = %output $v1
}
else {
  %output = %output not connected
}
echo -ag %output

As most of the regulars on this forum would tell you, this could be written in many ways, but this is just the simplest I could come up with.

The $server usage here is probably the most regularly used, for instance:

Code:
echo -a I am $iif($server,connected to $v1, not connected).

$iif is also heavily used in Popups, as it allows you to easily change the popup name:

Code:
menu channel,status,menubar {
  .-
  Away
  .Set Yourself $iif($away, as Here!, Away) : {
    if $away { away } | else { away $?="Type in away message" }
  }
}

So, it's extremely versitle.

Another example from one of my script files:
Code:
ON *:SIGNAL:maketitle {
  var %title
  var %count = $scon(0)
  ;
  ; Add NICK:NETWORK to titlebar
  ;
  while (%count) {
    %title = $+( [, $iif($scon(%count).status != connected, -, $scon(%count).me), :, $scon(%count).network , $iif( $scon(%count).away,  $+($chr(32), $chr(40), A, $chr(41)) ), ]) %title
    dec %count
  }
  ;
  ; Add playing MP3 if one exists
  ; 
  if ($inmp3) {
    %title = %title [Now Playing: $nopath($addtok(%title,: $insong.fname, 32)) $+ ]]
  }
  ;
  ; Show download/upload speed totals if using DCC
  ;
  var %up = 0, %down = 0
  var %count = $get(0)
  while (%count) {
    inc %down $get(%count).cps
    dec %count
  }
  var %count = $send(0)
  while (%count) {
    inc %up $send(%count).cps
    dec %count
  }
  if (%up || %down) {
    %title = %title $+([, $bytes(%up, k).suf, /, $bytes(%down, k).suf, ])
    .timerSpeedUpdate 1 1 .signal maketitle
  }
  ;
  ; Force the mIRC version infront of the rest of the title
  ; 
  .titlebar $version $iif($sslready, (SSL)) $iif($beta, ( $+ $beta $+ )) %title
}

This creates my titlebar string of:
Code:
6.3 (SSL) [Bekar:EFNet (A)] [Bekar:DarkerNet (A)] [Bekar:Rizon (A)] [Bekar:irchighway (A)] [-:ChatSpike] [Now Playing: ben_folds_five_-_army.mp3] [3.2KB/91.96KB]


Bekar #188192 19/10/07 01:03 AM
Joined: Apr 2007
Posts: 228
M
Mpot Offline OP
Fjord artisan
OP Offline
Fjord artisan
M
Joined: Apr 2007
Posts: 228
if (1 == 1)

1 is always going to equal one. $1, however...

And, what does :: represent?

Last edited by Mpot; 19/10/07 01:04 AM.
Mpot #188193 19/10/07 01:21 AM
Joined: Dec 2002
Posts: 503
B
Fjord artisan
Offline
Fjord artisan
B
Joined: Dec 2002
Posts: 503
Nothing. It should show up as:

Code:
true :: false :: <servername>

The :: was just used to separate the output a little.

Bekar #188195 19/10/07 01:51 AM
Joined: Apr 2007
Posts: 228
M
Mpot Offline OP
Fjord artisan
OP Offline
Fjord artisan
M
Joined: Apr 2007
Posts: 228
Originally Posted By: Bekar
Nothing. It should show up as:

Code:
true :: false :: <servername>

The :: was just used to separate the output a little.


Oh, okay. That was confusing me.

Page 1 of 3 1 2 3

Link Copied to Clipboard