mIRC Home    About    Download    Register    News    Help

Print Thread
Page 1 of 2 1 2
#5484 08/01/03 07:31 AM
Joined: Dec 2002
Posts: 40
C
Ameglian cow
OP Offline
Ameglian cow
C
Joined: Dec 2002
Posts: 40
Hi, i've only been working with mirc scripting for a week.. and i've sorta made a Fighting Style game for mirc.. and i have this (simple problem).. i'll try to explain it the best i can..

what i want to know is can if's do this..

if %this == True { do this}
if %this == Flase {do that}

Is this possible?

Cause i have have this on !attack

on *:text:!attack:#: {
if ($2 == $null) { /randattack }
else if ($2 == $read(test.txt, w, $2)) { /attackplayer }
else { /msg $chan The character $2 is not in our database }
}

and what i was hoping was putting

else if ($read(test.txt, w, $2) == True) { /attackplayer }
else if ($read(test.txt, w, $2) == Fasle) { /msg $chan The character $2 is not in our database }

Does this make any sense?

Thanks

Coca-Bear

#5485 08/01/03 11:47 AM
Joined: Dec 2002
Posts: 1,321
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Dec 2002
Posts: 1,321
Quote:
if %this == True { do this}
if %this == Flase {do that}

Code:

  if (%this) {
    do this
    and this
    and this too
  }
  elseif (%that) {
    do this
    and that
  }
  else {
    do that
  }
  
or
  
  if (%this) { do this | and this | and this too }
  elseif (%that) { do this | and that }
  else do that 


Quote:
on *:text:!attack:#: {
if ($2 == $null) { /randattack }
else if ($2 == $read(test.txt, w, $2)) { /attackplayer }
else { /msg $chan The character $2 is not in our database }
}

Code:

on *:text:!attack:#: {
  [color:#006600];  No nick was specified[/color]
  if ($2 == $null) randattack
  
  [color:#006600];  Nick was specified and found[/color]
  elseif ($read(test.txt, w, $+(*,$2,*))) attackplayer
  
  [color:#006600];  Nick was specified but not found[/color]
  else msg $chan The character $2 is not in our database
}

In any IF, ELSEIF or WHILE (condition), you are really checking for not $false rather than anything specific. There are 3 values that mIRC treats as $false: $false, 0 and $null. Anything else is $true, as far as the condition is concerned. 1 is $true, 0 is not. Coca_Bear is $true. $true is obviously $true as well. $false is obviously not $true.

This is extremely handy in coding. You can easily check to see if a variable has been set (to something other than 0/$false/$null) using (%variable) or check for it's not having been set with (!%variable). The same thing applies to identifiers. If a value is returned that's not 0 or $false, then it's $true.

$read(test.txt,w,$+(*,$2,*)) wiill return $null if $2 is not found anywhere on any line of test.txt. If it is found, it will return the first matching line - which does not equal $false/$null/0, and so is therefore equivalent to $true.


DALnet: #HelpDesk and #m[color:#FF0000]IR[color:#EEEE00]C
#5486 08/01/03 12:57 PM
Joined: Dec 2002
Posts: 40
C
Ameglian cow
OP Offline
Ameglian cow
C
Joined: Dec 2002
Posts: 40
ok. basiclly all test.txt is a checking file to make sure that the $2 character is there if its $false... it wont attack the player.. if $2 is $true it will attack the player. So would the code looking something like this?

if ($read(test.txt,w,$+(*,$2,*) == $true) { /attackplayer }
else if ($read(test.txt,w,$+(*,$2,*) == $false) { /msg $chan The character $2 is not in our database }

edit: fixed typos :tongue:

Thanks for the help.

Coca-Bear

Last edited by Coca_Bear; 08/01/03 12:58 PM.
#5487 08/01/03 01:41 PM
Joined: Dec 2002
Posts: 1,321
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Dec 2002
Posts: 1,321
You went back to your old faulty code for some reason. You also removed the closing ) from the $read( ).

if ($read(test.txt,w,$+(*,$2,*) == $true) { /attackplayer }
This condition can ONLY, ONLY, ONLY be true if you are literally searching for "$true" in that file, not a nick or whatever else; you would be attacking someone called $true.

else if ($read(test.txt,w,$+(*,$2,*) == $false) { /msg $chan The character $2 is not in our database }
It's "elseif".
This condition can ONLY, ONLY, ONLY be true if you are literally searching for "$false" in the file, not a nick or whatever else; you would be messaging the channel that $false is not in your database.

However, if you are looking to see if $2 (which is a nick) is found in that text file, then your example will NOT work at all for the reasons given above. Read very closely the following code (which is exactly the same code I posted before, but this time without comments.
Code:

on *:text:!attack:#: {
  if ($2 == $null) randattack
  elseif ($read(test.txt, w, $+(*,$2,*))) attackplayer
  else msg $chan The character $2 is not in our database
}

This code will do exactly what you want it to do. Yours will not.


DALnet: #HelpDesk and #m[color:#FF0000]IR[color:#EEEE00]C
#5488 08/01/03 01:55 PM
Joined: Dec 2002
Posts: 40
C
Ameglian cow
OP Offline
Ameglian cow
C
Joined: Dec 2002
Posts: 40
ah ok.. Thanks for your help :tongue: i understand now hehe

Coca-Bear

#5489 08/01/03 02:01 PM
Joined: Dec 2002
Posts: 699
N
Fjord artisan
Offline
Fjord artisan
N
Joined: Dec 2002
Posts: 699
Quote:
on *:text:!attack:#: {
No it won't
There will never be a $2. "!attack" will only match "!attack", and not "!attack <name>" :tongue:

#5490 08/01/03 02:18 PM
Joined: Dec 2002
Posts: 1,321
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Dec 2002
Posts: 1,321
Code:

on *:text:!attack*:#: {
  if ($2 == $null) randattack
  elseif ($read(test.txt, w, $+(*,$2,*))) attackplayer
  else msg $chan The character $2 is not in our database
}
Oops.


DALnet: #HelpDesk and #m[color:#FF0000]IR[color:#EEEE00]C
#5491 08/01/03 02:32 PM
Joined: Dec 2002
Posts: 40
C
Ameglian cow
OP Offline
Ameglian cow
C
Joined: Dec 2002
Posts: 40
Yes i noticed that...ok i tried this it didn't work..

Code:
 on *:text:!attack*:#: {  
if ($2 == $null){ /randattack }
else if ($read(test.txt, w, $+(*,$2,*))) { /attackplayer }
else { /msg $chan The character $2 is not in our database}
}
 


i can do !attack and it does a random player. but still it attacks players that are not in test.txt.

Also i do !attack playername and it does nothing.. nothing at all

Any help is greatly appreciated :tongue:

Thanks

Coca-Bear

Coca-Bear

#5492 08/01/03 02:45 PM
Joined: Dec 2002
Posts: 1,321
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Dec 2002
Posts: 1,321
I am not going to keep re-correcting your script when you insist on switching the code I give you and breaking it. CAREFULLY re-read this entire thread and you will figure out why it does not work. (HINT: elseif). Happy hunting and good luck.


DALnet: #HelpDesk and #m[color:#FF0000]IR[color:#EEEE00]C
#5493 08/01/03 02:55 PM
Joined: Dec 2002
Posts: 699
N
Fjord artisan
Offline
Fjord artisan
N
Joined: Dec 2002
Posts: 699
Quote:
if ($2 == $null){ /randattack }

Code:
if ($2 == $null[color:red]) {[/color] randattack }

Also
Quote:
else { /msg $chan The character $2 is not in our database}
Code:
else { /msg $chan The character $2 is not in our [color:red]database }[/color]

Last edited by Nimue; 08/01/03 02:59 PM.
#5494 08/01/03 03:04 PM
Joined: Dec 2002
Posts: 699
N
Fjord artisan
Offline
Fjord artisan
N
Joined: Dec 2002
Posts: 699
Wrong smile
The lack of spaces is the problem

#5495 08/01/03 03:06 PM
Joined: Dec 2002
Posts: 3,138
C
Hoopy frood
Offline
Hoopy frood
C
Joined: Dec 2002
Posts: 3,138
Whoops, I deleted the post, was gonna make a new one, but the first space you pointed out is irrelevant smile (apart from making it look pretty)

#5496 08/01/03 03:09 PM
Joined: Dec 2002
Posts: 699
N
Fjord artisan
Offline
Fjord artisan
N
Joined: Dec 2002
Posts: 699
It totally is not irrelevant :tongue:
Paste that code without the space into mIRC editor and hit the {} button and see what happens wink

#5497 08/01/03 03:09 PM
Joined: Dec 2002
Posts: 40
C
Ameglian cow
OP Offline
Ameglian cow
C
Joined: Dec 2002
Posts: 40
well all i can see wrong is elseif else if..

I've tried it and still it doesn't !attack playername and still attacks players that are not in the list smirk ...

If i have missed something than i have no clue what it is smirk

Code:
on *:text:!attack*:#: {  
  if ($2 == $null) { /randattack }
  elseif ($read(test.txt, w, $+(*,$2,*))) { /attackplayer  }
  else { /msg $chan The character $2 is not in our database }
}
  


Thanks

Coca-Bear

#5498 08/01/03 03:12 PM
Joined: Dec 2002
Posts: 3,138
C
Hoopy frood
Offline
Hoopy frood
C
Joined: Dec 2002
Posts: 3,138
Damn, you win :'(

#5499 08/01/03 03:18 PM
Joined: Dec 2002
Posts: 699
N
Fjord artisan
Offline
Fjord artisan
N
Joined: Dec 2002
Posts: 699
I imagine you might be needing to know which player to "attackplayer"
Code:
on *:text:!attack*:#:{
  if ($2 == $null) { randattack }
  elseif ($read(test.txt, w, $+(*,$2,*))) { attackplayer $2 }
  else { msg $chan The character $2 is not in our database }
}

#5500 08/01/03 03:25 PM
Joined: Dec 2002
Posts: 40
C
Ameglian cow
OP Offline
Ameglian cow
C
Joined: Dec 2002
Posts: 40
no its not that.. because attackplayer is /attackplayer and calls a alias/function in my code i have included the "/".. i dunno why Hammer took them out?

Coca-Bear

#5501 08/01/03 03:27 PM
Joined: Dec 2002
Posts: 3,138
C
Hoopy frood
Offline
Hoopy frood
C
Joined: Dec 2002
Posts: 3,138
From the help file:

Note: I didn't prefix the above commands with the / command prefix. This is because the command prefix is really only needed when entering a command on the command line. In scripts, all lines are assumed to start with a command, so you don't need to use the / command prefix. [/color]

#5502 08/01/03 03:30 PM
Joined: Dec 2002
Posts: 699
N
Fjord artisan
Offline
Fjord artisan
N
Joined: Dec 2002
Posts: 699
Because the "/"'s are not needed in script files. smile
If it doesn't work I suggest looking to the other aliases, that code works as far it goes.

#5503 08/01/03 03:38 PM
Joined: Dec 2002
Posts: 40
C
Ameglian cow
OP Offline
Ameglian cow
C
Joined: Dec 2002
Posts: 40
i tried that... it works.. thanks for that... and thanks to everyone that has helped me.. especially Hammer :tongue:

Coca-Bear

Page 1 of 2 1 2

Link Copied to Clipboard