mIRC Home    About    Download    Register    News    Help

Print Thread
#233428 13/08/11 01:09 AM
Joined: Jan 2005
Posts: 16
D
Deviant Offline OP
Pikka bird
OP Offline
Pikka bird
D
Joined: Jan 2005
Posts: 16
So I'm trying to add these to my popups (this is for a chatspace server hence the 'Services' command) but I'm not too familiar with the $ variables. I know what I have below is wrong but if you could tell me where I'm going wrong, it'd be a big help.


..Add/Delete Owners
..Add Owner in $chan: { Services SOP $chan ADD $$?="Enter Nick:" | notice $1- You are now a SOP in $chan }
..Add Owner (Other): { Services SOP #$$?="Enter Room:" ADD $$?="Enter Nick To Add:" | notice $2- You are now a SOP in $-1 }

Deviant #233429 13/08/11 02:22 AM
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
First, keep in mind that there are multiple menus you can use. You can have the channel one appear only in the channel and the "other" appear somewhere else (status, query, etc). So you don't necessarily have to put both in the same menu and you don't necessarily have to include the channel name if you're separating them. That's entirely up to you, of course.

Second, $N's are not filled from $?="" in that way. You will need to either fill $N's using /tokenize or else store the information in variables to use a second time (in the notice). For example, tokenize the two inputs and then use $1 and $2 in both the services command and the notices command. The problem with using $N with tokenize to fill them is that someone might enter invalid information in the inputs - something with spaces - and that will cause problems. You would probably be better off just storing the two inputs into variables and then you can only take the first "word" from each to avoid that kind of problem. To kind of explain what I mean, think what would happen if someone entered "this is my nick" into the nick input. You then use "/notice this is my nick you are now a SOP". That notice is going to be sent to "this" and the message will be "is my nick you are now a SOP". Definitely a potential problem. If this is just for your personal use, then you don't need to worry about that, but if you want to share it, you should try to avoid situations where a user can mess things up.

Third, your .'s represent the level of the menu/submenu. Your "title" of Add/Delete Owners is currently on the same level as the sub items. They really should be on separate levels if you use a "title" or heading.

It can also be very useful to use aliases when you are doing a similar thing more than once. Here's just an example of one way you could do this. Note that if you want to include a delete command, it can be added just like the Add command.

Code:
menu channel {
  Add/Delete Owners
  .Add Owners:AddOwner $chan $$?="Enter Nick:"
}
menu status {
  Add/Delete Owners
  .Add Owners:AddOwner $$?="Enter Room:" $$?="Enter Nick:"
}
menu nicklist {
  Add/Delete Owners
  .Add Owners:AddOwner $$?="Enter Room:" $$1
}

alias AddOwner {
  Services SOP $iif($left($1,1) == #,$1,#$1) ADD $2
  .notice $2 You are now a SOP in $iif($left($1,1) == #,$1,#$1)
}


Now, again, that doesn't consider the possibility of someone entering multiple words in the inputs and that can cause problems. But it's not too much work to avoid that if you are going to share the script with others. You would just want to decide whether you want to only use the first "word", if you want to remove spaces, or if you want to throw an error if multiple "words" are used. Based on that choice, you can prevent the potential problem with a couple minor changes.

Notice with this option that I have 3 separate menus:
  • Right clicking in the channel, where you know $chan, but do not know $nick, so you ask for it.
  • Right clicking in status, where you don't know $chan or $nick.
  • Right clicking on a nick, where you know $nick, but may or may not know $chan (depending if the nick is clicked in the channel or in query), so you play it safe and ask for the channel. $1 would be the $nick when right clicking on a nick, so that's why you see it there.


Then, all 3 send 2 pieces of information to the alias... $chan and $nick. $chan becomes $1 and $nick becomes $2 in the alias.

Notice the $iif($left($1,1) == #,$1,#$1) parts in the alias. This makes it so the user can enter the channel with and without the # character and it will end up with just one # character when done. If you force a # character (#$$?="Enter Room:") and the user enters #channel, then you end up with ##channel. And, if you don't do anything, channel remains channel. By using $iif(), we can guarantee #channel regardless of the user entering #channel or channel.

Last edited by Riamus2; 13/08/11 02:30 AM.

Invision Support
#Invision on irc.irchighway.net
Riamus2 #233430 13/08/11 03:13 AM
Joined: Jan 2005
Posts: 16
D
Deviant Offline OP
Pikka bird
OP Offline
Pikka bird
D
Joined: Jan 2005
Posts: 16
This, for the most part makes a whole lot more sense.. however I am still unsure about different variables.

So if I wanted to execute a command like /services set <nickhere> admin on would I do it like this?

menu channel {
Admin Controls
.Give/Take Admin
..Give Admin (Perm):GAdmin $$?="Enter Nick:"
..Take Admin (Perm):TAdmin $$?="Enter Nick:"

alias GAdmin {
Services set $2 admin on
.notice $2 You are now a server administrator
}

alias TAdmin {
Services set $2 admin off
.notice $2 You are no longer a server administrator
}

Deviant #233437 13/08/11 01:44 PM
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
The only problem I see there is that you're using $2. In this case, it should be $1.

When using an alias, the first "word" after the alias name will be $1. The second "word" will be $2. And so on. So, you use GAdmin nick. The first "word" is the nick, so that will be $1. In the example I gave before, the channel was the first "word" and the nick was the second. That's why the channel was $1 and the nick was $2 in that specific case. And each "word" is anything separated by a space.

Think of $N's as words. $1 is the first word, $2 is the second, and so on. If you were to write a sentence "This is a sentence.", then you have $1 through $4 there. Now, this is the case when using a space character as the separator. Space is used for aliases and is the default for events like on TEXT. However, if you had a list of items, such as "car,truck,boat", there aren't spaces there, so that is all in $1 if you use spaces to separate the "words". For this, you could use /tokenize and instead of using the space character (chhr 32), you can use the comma as a separator (chr 44). After using tokenize with a comma as the separator character, car would become $1, truck would be $2, and boat would be $3 even though there aren't spaces.

You can find out more information on how tokens work with:
/help /tokenize
/help token identifiers

Although identifiers like $gettok() use just the number without a $ before it (1 instead of $1) when selecting the "word", it is the same concept, so should be helpful in understanding what's going on.


Invision Support
#Invision on irc.irchighway.net

Link Copied to Clipboard