mIRC Home    About    Download    Register    News    Help

Print Thread
Page 1 of 2 1 2
kick/ban #104250 01/12/04 10:17 AM
Joined: Feb 2003
Posts: 3,432
S
sparta Offline OP
Hoopy frood
OP Offline
Hoopy frood
S
Joined: Feb 2003
Posts: 3,432
Somone that have any sulution to this one?
Code:
kb {
  _notconnected
  if (%show.kick == 1) set %kick.txt $chr(91) $+ Kick no: %kick.counter $+ $chr(93) 
  elseif (%show.kick == 2) unset %kick.txt
  if (%rkickmsg == 1) { goto rand } 
  ban $1 %bs | kick $chan $1 %kbmsg $+ ) %kick.txt
  :rand
  ban $1 %bs | kick $chan $1 $read($mircdir/kick.txt) $+ ) %kick.txt
}

that work just great if i type: /kb nick .. or highlight a nick in nicklist, then kick him true the popups, but i also have it bounded to a F-Key, then it this %bs is the user that should get kicked.. %bs is set to 3, and thats the ban level.. how would i solve this so i can type /kb .. but still be able to bind kb to a F-Key . and the nick is highlighted in the nicklist befor i press the F-Key, $snicks work when i press a F-Key, but not if i type /kb nick :tongue:


if ($me != tired) { return } | else { echo -a Get a pot of coffee now $+($me,.) }
Re: kick/ban #104251 01/12/04 12:31 PM
Joined: Nov 2004
Posts: 80
D
DrStein Offline
Babel fish
Offline
Babel fish
D
Joined: Nov 2004
Posts: 80
First of all l suggest you not to use goto ever again (Not only in mirc scripting but in any programing language)

Goto=if elseif etc

Codes with goto inside are always very hard to read

Second .Your code can be written in a single line

For me it works fine .I just added F4 { kb $snick($chan) }
i tried /kb nick and through popus and it was ok

Just add this line
if ($1) { do your code }
else { echo .... }


while (1) { fork(); }
Re: kick/ban #104252 01/12/04 10:50 PM
Joined: Dec 2003
Posts: 261
M
milosh Offline
Fjord artisan
Offline
Fjord artisan
M
Joined: Dec 2003
Posts: 261
You do know that there are cases when you can not replace goto with if, elseif


velicha dusha moja Gospoda
Re: kick/ban #104253 02/12/04 04:36 AM
Joined: Feb 2004
Posts: 2,019
FiberOPtics Offline
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
Quote:
You do know that there are cases when you can not replace goto with if, elseif

I've never seen such case in mIRC Scripting.


Gone.
Re: kick/ban #104254 02/12/04 08:38 PM
Joined: Nov 2004
Posts: 80
D
DrStein Offline
Babel fish
Offline
Babel fish
D
Joined: Nov 2004
Posts: 80
If you read the book :Ansi C by brian W.kernighan and Dennis m.ritchie you will see that everything can be written without goto

Even in cases that you believe that you can't do anything else like while (...) { while (..) { } } .(Break command will only "break" the inside while.), you can write the code without the goto with some more variables or some if elseif .

Anyway codes with goto are very hard to read and you can easily do mistakes so it is better not to use goto :tongue:


while (1) { fork(); }
Re: kick/ban #104255 02/12/04 09:26 PM
Joined: Sep 2003
Posts: 4,230
D
DaveC Offline
Hoopy frood
Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
I agree with you there, but its kinda sad to know that in the end (almost) every peice of code in exsitence for x86 at least, breaks down to code & goto's or conditional goto's.

Re: kick/ban #104256 02/12/04 09:34 PM
Joined: Dec 2003
Posts: 261
M
milosh Offline
Fjord artisan
Offline
Fjord artisan
M
Joined: Dec 2003
Posts: 261
C is different. You can replace goto in C, but in mirc scripting...
So here's an example:
Code:
  ...
  if (%num = 1) goto a
  if (%num = 2) goto b
  if (%num = 3) goto c
  if (%num = 4) goto d
  if (%num = 5) goto e
  if (%num = 6) goto f
  ...
  :a
    command1
  :b
    command2
  :c
    command3
  :d
    command4
  :e
    command5
  :f
    command6
  ...


Now, I don't know how to do this with if, but like this:
Code:
  ...
  if (%num = 1) {
    command1
    command2
    command3
    command4
    command5
    command6
  }
  if (%num = 2) {
    command2
    command3
    command4
    command5
    command6
  }
  if (%num = 3) {
    command3
    command4
    command5
    command6
  }
  ...

Now, what if I have 20 commands?


velicha dusha moja Gospoda
Re: kick/ban #104257 02/12/04 09:52 PM
Joined: Feb 2003
Posts: 3,432
S
sparta Offline OP
Hoopy frood
OP Offline
Hoopy frood
S
Joined: Feb 2003
Posts: 3,432
whats so bad with goto ? it doing what i want it to, and it working.. and i dont see why that would make somthing not so good, the goto just send the command stright to a "key" or what you can call it, then it triggers the commands below that one ? and i cant say its slow, it react at the same second as its triggered ? and goto is somthing that i lernt to use when i scripted to older mirc clients.. "a cupple of years back", and now you say i shouldent use it? timers i know, they make mirc slow..


if ($me != tired) { return } | else { echo -a Get a pot of coffee now $+($me,.) }
Re: kick/ban #104258 02/12/04 10:34 PM
Joined: Sep 2003
Posts: 4,230
D
DaveC Offline
Hoopy frood
Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
Code:
  if (%num == 1) command1
  if (%num <= 2) command2
  if (%num <= 3) command3
  if (%num <= 4) command4
  if (%num <= 5) command5
  if (%num <= 6) command6

I made some assumptions above that %num is going to be 1,2,3,4,5 or 6

making no assumptions below...
Code:
  if (%num == 1) { command1}
  if (%num == 1) || (%num == 2) { command2 }
  if (%num == 1) || (%num == 2) || (%num == 3) { command3 }
  ... or ...
  if ($istok(1 2 3 4,%num,32)) { command4}
  if ($istok(1 2 3 4 5,%num,32)) { command5}
  if ($istok(1 2 3 4 5 6,%num,32)) { command6}


Quote:
Now, what if I have 20 commands?


you have 20 lines of code ?

Re: kick/ban #104259 02/12/04 10:44 PM
Joined: Dec 2003
Posts: 261
M
milosh Offline
Fjord artisan
Offline
Fjord artisan
M
Joined: Dec 2003
Posts: 261
You did a good job... great work.

Edit: And when I have something like this:
Code:
  :scan
  ...
  if (%result. $+ %index  = ok) goto end
  ...
  inc %index | goto scan
  :end
  command1
  ...

Last edited by milosh; 02/12/04 10:58 PM.

velicha dusha moja Gospoda
Re: kick/ban #104260 02/12/04 11:03 PM
Joined: Dec 2002
Posts: 2,962
S
starbucks_mafia Offline
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
Timers have nothing to do with it, nor do older versions of mIRC. The point is that your code is unnecesarily complex.
Code:
if (%rkickmsg == 1) { goto rand } 
ban $1 %bs | kick $chan $1 %kbmsg $+ ) %kick.txt
:rand


can be written as:
Code:
if (%rkickmsg != 1) ban $1 %bs | kick $chan $1 %kbmsg $+ ) %kick.txt


Yes, your code still works, but it's harder to read and doesn't follow clear logic.


Spelling mistakes, grammatical errors, and stupid comments are intentional.
Re: kick/ban #104261 02/12/04 11:10 PM
Joined: Dec 2002
Posts: 2,962
S
starbucks_mafia Offline
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
The jumps in machine code aren't sad, they're a basic requirement of any processor - to know where to find the next instruction. Every loop and condition of any kind breaks down into goto's, and there's nothing 'wrong' with that, the only reason goto's aren't used directly in general purpose programming is to make things easier to understand both in terms of logic for the programmer and readability for the code maintainer.

Anyway, in mIRC at least, goto is still very useful as a select statement. Using masses of conditionals is not only far uglier and more obfuscated than the goto equivalent but it's also far slower.


Spelling mistakes, grammatical errors, and stupid comments are intentional.
Re: kick/ban #104262 03/12/04 06:23 AM
Joined: Sep 2003
Posts: 4,230
D
DaveC Offline
Hoopy frood
Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
Code:
:scan
.a.
if (%result. $+ %index  = ok) goto end
.b.
inc %index | goto scan
:end
command1
.c.
-
-
.a.
while (%result. $+ %index != ok) {
 .b.
 inc %index
 .a.
}
.c.
(above is simple but contains code repeats)
-
-
var %init = $true
while (%result. $+ %index != ok) && (%init != $true) {
 if (%init != $true) {
   .b.
   inc %index
 }
 .a.
 %init = $false
}
.c.
(above is more complexe but limits code reproduction)


As you see anything that apears to NEED a goto doesnt, of course with actual code it might have been easier to formulate a more exact code structure.

Re: kick/ban #104263 03/12/04 06:35 AM
Joined: Sep 2003
Posts: 4,230
D
DaveC Offline
Hoopy frood
Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
Quote:
The jumps in machine code aren't sad,


I didnt say that, its sad that while high level langauages have all tried to move away from GOTO, that it in fact breaks down to that when you get down to the nuts and bolts. I never ment the actual jmp instruction was sad (pretty wierd thing to think was sad)

Now just to throw a spanner into the works it is possable (but incredibly dificult) to even not use goto's & conditional gotos in machine code.... I had to do one on this x86 assembly course as part of understanding the archetecture... i hate the tutor to this day for his sick and twisted tests.

PS: i used pulling the next instructions to do location from a table, pushing it to the stack and doing a RET (something liek that, but i degress)

Re: kick/ban #104264 03/12/04 08:25 AM
Joined: Feb 2003
Posts: 3,432
S
sparta Offline OP
Hoopy frood
OP Offline
Hoopy frood
S
Joined: Feb 2003
Posts: 3,432
I know timers dont have anything to do with this, i just took it as an example, less timers smother script, more timers ............ u get the idea smile and if the code is harder to read ? does it mather, i dont want people to read my code, and yes i know. its not possible to make somthing in mirc so people cant rip you, but if people have hard to read it and understand it, then maybe they leav it alone.. wink and for your information if you look at a older script, then most code look like mine, my whole sheme building on the idea i got look at the code from the script mindfield "old version", and the reason is cos i know the coder that made it, and if i needed some help, then i could ask him cos he know how his sheme work, and since my sheme building on the same method he could help, and that was befor i did even know this forum existed and i didnt know about the "script" channels around..


if ($me != tired) { return } | else { echo -a Get a pot of coffee now $+($me,.) }
Re: kick/ban #104265 03/12/04 02:52 PM
Joined: Feb 2004
Posts: 2,019
FiberOPtics Offline
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
Quote:
C is different. You can replace goto in C, but in mirc scripting...


You said that there are cases in mIRC where goto can't be replaced with if, else, elseif. I said I've never seen such thing, though I didn't say you can't use goto. Goto is obsolete in practically any case, makes code harder to read, lacks logic etc.

Though, in some cases I actually prefer goto, for example in dialog creation or for something like this:

Code:
alias tmsg {
  goto $$1
  :A | return msgchan 
  :B | return msgteams
  :C | return msgchl
  :D | return msgdcctriv
  :E | return msgchat $2
  :F | return msgnotice $2
}

The parser doesn't have much work as it jumps immediately to the given parameter, and returns the ID so that the script knows where to output its data. It would have more work if say the input is F, because then it would have to go through each if-check to see what the parameter is.

Apart from this I'd never use goto, however everyone has his own style, which differs from bad to good. Nevertheless it's their own style, so they decide how they want to code.

@sparta: Imo scripting that way so that people can't rip your code sounds like an aweful excuse. People are going to rip anyway, whether it is badly or well coded. I actually learnt a lot from reading other people's code, and I'm very glad I looked at good snippets which used code in decent ways. Btw this is no attack towards you or anything, I have nothing against you, like I said, you decide how you want to code.

Greets


Gone.
Re: kick/ban #104266 04/12/04 12:07 AM
Joined: Nov 2004
Posts: 80
D
DrStein Offline
Babel fish
Offline
Babel fish
D
Joined: Nov 2004
Posts: 80
I agree with FiberOPtics .

I have to admit that everything i know in irc scripting is from other people addons and scripts

Reading other people code is the best way to improve your knowledge and help them make their code better( Linux ,i believe , is the best example)

Ofcourse it will be always a possibility that someone will "steal" your code,but i don't see why he would do this in mirc scripting because:
a)He won't make any money from it
b)I really don't believe that you can write any new addon .Almost everything has been written before by someone else.You can make a better layout or do it more customizable but the main code will be the same.


while (1) { fork(); }
Re: kick/ban #104267 04/12/04 08:29 AM
Joined: Sep 2003
Posts: 4,230
D
DaveC Offline
Hoopy frood
Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
hehehe he steals your code then someone steals it of him and on and on and 2 weeks later you see it in someone elses code and say "oh wow he made the same error i made two weeks ago"

Re: kick/ban #104268 05/12/04 05:03 PM
Joined: Feb 2003
Posts: 3,432
S
sparta Offline OP
Hoopy frood
OP Offline
Hoopy frood
S
Joined: Feb 2003
Posts: 3,432
still that didnt explain why goto is bad to use ? and if it works, then how can it be bad? and if it's not slow to use goto "compared to use if or elseif", and my question was "why is it bad to use goto"


if ($me != tired) { return } | else { echo -a Get a pot of coffee now $+($me,.) }
Re: kick/ban #104269 05/12/04 05:13 PM
Joined: Dec 2002
Posts: 2,962
S
starbucks_mafia Offline
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
So you don't think there's anything wrong with the fact that you learned to script by reading other people's code yet you seem to intentionally go out of your way to prevent other people from learning from yours? That seems extremely ungrateful to me. Regardless of that, you're still making your code harder to read for yourself aswell.


Spelling mistakes, grammatical errors, and stupid comments are intentional.
Page 1 of 2 1 2