mIRC Home    About    Download    Register    News    Help

Print Thread
#147780 24/04/06 01:12 AM
Joined: Apr 2006
Posts: 8
M
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
M
Joined: Apr 2006
Posts: 8
Code:
on *:TEXT:!add*:#:{ 
  if ($nick ison $chan) {
    .msg # $nick has placed $2 on the hitlist for $3.
    /write c:\hitlist.txt $nick has placed $2 on the hitlist for $3. $date
  }
}
on *:TEXT:!hitlist*:#:{ 
  /play $nick c:\hitlist.txt 1
}
on *:TEXT:!clear*:#:{ 
  if ($nick isop $chan) {
    /write -c c:\hitlist.txt ####HitList####
    .msg # $nick has cleared the hitlist. So if it gets messed up, blame $nick .
  }
}
on *:TEXT:!del*:#:{ 
  if ($nick isop $chan) {
    /write -d$2 c:\hitlist.txt
    .msg # $nick has deleted line $2 of the hitlist.
  }
}  


is there anything i can do to fix it up or make it better? i mean it works but just wondering
I know its a noob script but still its my first decent one crazy

Last edited by MisterMage; 24/04/06 01:23 AM.
#147781 24/04/06 01:26 AM
Joined: May 2005
Posts: 449
Fjord artisan
Offline
Fjord artisan
Joined: May 2005
Posts: 449
For one thing, you don't need the / at the beginning of commands in your remote file. Another thing is with this line:
Code:
/write c:\hitlist.txt $nick has placed $2 on the hitlist for $3. $date


You might not want to write all of that to the text file, to save space. You could just write $2 $+ - $+ $3 $+ - $date. Depending on how much you're going to be writing to this file, it would be best to save as much read time as possible.

#147782 24/04/06 01:28 AM
Joined: Oct 2005
Posts: 1,741
G
Hoopy frood
Offline
Hoopy frood
G
Joined: Oct 2005
Posts: 1,741
Commands in scripts don't need to have the / slash in front of them.

Also, instead of using inclusive IF style, you could use exclusive style. Example:

You have (inclusive):

Code:
if (something is true) {
  do these commands
  do more commands
}


Exclusive style would be like this:
Code:
if (something isNOT true) return
do these commands
do more commands


In your code it doesn't make much difference, but in larger code, where many *unrelated* criteria have to be true in order for the entire series of commands to execute, it eliminates many ANDs or nested IF statements.

Example (inclusive - nested IFs):
Code:
if (criteria1 is true) {
  if (criteria2 is true) {
    if (criteria3 is true) {
      if (criteria4 is true) {
        do some commands
      }
    }
  }
}


*Notice the many confusing }'s at the end

Example (inclusive - ANDs)
Code:
if ((criteria1 is true) && (criteria2 is true) && (criteria3 is true) && (criteria4 is true)) {
  do some commands
}

*Notice long, hard-to-read IF statement

Example (exclusive):
Code:
if (criteria1 isNOT true) return
if (criteria2 isNOT true) return
if (criteria3 isNOT true) return
if (criteria4 isNOT true) return
do some commands


*This style eliminates long IF statements and many confusing }s at the end.

-genius_at_work

#147783 24/04/06 01:28 AM
Joined: Aug 2005
Posts: 525
S
Fjord artisan
Offline
Fjord artisan
S
Joined: Aug 2005
Posts: 525
Code:
on *:TEXT:!add*:#:{ 
  if ($nick ison $chan) { 
    .msg # $nick has placed $2 on the hitlist for $3.
    /write c:\hitlist.txt $nick has placed $2 on the hitlist for $3. $date
  }
}


- The trigger text should be !add & (The & means that there must be a second parameter ($2) before it will attempt to execute the code)
- This isn't a problem, but the / in /write is not needed. / (for commands) is never needed in remotes.
- Since this is triggered by another user, $nick will always be on the channel so theres no reason to be checking this
- What if $2 is not currently on the channel? Or better yet, $2 is some random jibberish.
- $3, I assume is some time duration but you're not doing any checking to see if its valid or not



Code:
on *:TEXT:!clear*:#:{ 
  if ($nick isop $chan) {
    /write -c c:\hitlist.txt ####HitList####
    .msg # $nick has cleared the hitlist. So if it gets messed up, blame $nick .
  }
}


- The trigger text should be !clear
- This isn't a problem, but the / in /write is not needed. / (for commands) is never needed in remotes.



Code:
on *:TEXT:!del*:#:{ 
  if ($nick isop $chan) {
    /write -d$2 c:\hitlist.txt
    .msg # $nick has deleted line $2 of the hitlist.
  }
}  


- The trigger text should be !del &
- Again, you're not validating $2 here, what if its not in the list?
- And once more, the / is not needed.

For all
- You should make use of userlevels here, so that not everyone can use these commands
- Why post this here? You already had another topic for this same script.


Link Copied to Clipboard