|
Joined: Dec 2002
Posts: 40
Ameglian cow
|
OP
Ameglian cow
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
|
|
|
|
Joined: Dec 2002
Posts: 1,321
Hoopy frood
|
Hoopy frood
Joined: Dec 2002
Posts: 1,321 |
if %this == True { do this} if %this == Flase {do that}
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 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 } }
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
|
|
|
|
Joined: Dec 2002
Posts: 40
Ameglian cow
|
OP
Ameglian cow
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.
|
|
|
|
Joined: Dec 2002
Posts: 1,321
Hoopy frood
|
Hoopy frood
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.
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
|
|
|
|
Joined: Dec 2002
Posts: 40
Ameglian cow
|
OP
Ameglian cow
Joined: Dec 2002
Posts: 40 |
ah ok.. Thanks for your help :tongue: i understand now hehe
Coca-Bear
|
|
|
|
Joined: Dec 2002
Posts: 699
Fjord artisan
|
Fjord artisan
Joined: Dec 2002
Posts: 699 |
No it won't There will never be a $2. "!attack" will only match "!attack", and not "!attack <name>" :tongue:
|
|
|
|
Joined: Dec 2002
Posts: 1,321
Hoopy frood
|
Hoopy frood
Joined: Dec 2002
Posts: 1,321 |
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
|
|
|
|
Joined: Dec 2002
Posts: 40
Ameglian cow
|
OP
Ameglian cow
Joined: Dec 2002
Posts: 40 |
Yes i noticed that...ok i tried this it didn't work.. 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
|
|
|
|
Joined: Dec 2002
Posts: 1,321
Hoopy frood
|
Hoopy frood
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
|
|
|
|
Joined: Dec 2002
Posts: 699
Fjord artisan
|
Fjord artisan
Joined: Dec 2002
Posts: 699 |
if ($2 == $null){ /randattack } if ($2 == $null[color:red]) {[/color] randattack } Also else { /msg $chan The character $2 is not in our database} else { /msg $chan The character $2 is not in our [color:red]database }[/color]
Last edited by Nimue; 08/01/03 02:59 PM.
|
|
|
|
Joined: Dec 2002
Posts: 699
Fjord artisan
|
Fjord artisan
Joined: Dec 2002
Posts: 699 |
Wrong The lack of spaces is the problem
|
|
|
|
Joined: Dec 2002
Posts: 3,138
Hoopy frood
|
Hoopy frood
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 (apart from making it look pretty)
|
|
|
|
Joined: Dec 2002
Posts: 699
Fjord artisan
|
Fjord artisan
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
|
|
|
|
Joined: Dec 2002
Posts: 40
Ameglian cow
|
OP
Ameglian cow
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 ... If i have missed something than i have no clue what it is
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
|
|
|
|
Joined: Dec 2002
Posts: 3,138
Hoopy frood
|
Hoopy frood
Joined: Dec 2002
Posts: 3,138 |
|
|
|
|
Joined: Dec 2002
Posts: 699
Fjord artisan
|
Fjord artisan
Joined: Dec 2002
Posts: 699 |
I imagine you might be needing to know which player to "attackplayer" 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 }
}
|
|
|
|
Joined: Dec 2002
Posts: 40
Ameglian cow
|
OP
Ameglian cow
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
|
|
|
|
Joined: Dec 2002
Posts: 3,138
Hoopy frood
|
Hoopy frood
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]
|
|
|
|
Joined: Dec 2002
Posts: 699
Fjord artisan
|
Fjord artisan
Joined: Dec 2002
Posts: 699 |
Because the "/"'s are not needed in script files. If it doesn't work I suggest looking to the other aliases, that code works as far it goes.
|
|
|
|
Joined: Dec 2002
Posts: 40
Ameglian cow
|
OP
Ameglian cow
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
|
|
|
|
|