|
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
|
|
|
|
Joined: Dec 2002
Posts: 1,321
Hoopy frood
|
Hoopy frood
Joined: Dec 2002
Posts: 1,321 |
Now that you have it fixed, I will explain why that else if wouldn't have worked (even if you had kept your spacing correct):
if (condition) { randattack }
else if (condition2) { attackplayer $2 }
[color:red]else { msg $chan Not found. }[/color] That red ELSE line will never ever be run because it has no matching IF. As you had it written, it would have looked like this using all the braces and separate lines to show it more clearly:
if (condition1) {
randattack
}
else {
if (condition2) {
attackplayer $2
}
}
else {
msg $chan Not found.
}
Notice that you have 2 else's, one after the other, there. The second one has no IF associated with it, therefore it can never get executed. If you wanted it to go with if (condition2) and both of them under the else, then you have to group them with { }, like this:
if (condition1) { randattack }
else {
if (condition2) { attackplayer $2) }
else { msg $chan Not found. }
} else if is NOT the same thing as elseif. - if (this condition works) { do this }
; Ok, that one didn't work, let's try a different condition elseif (a different condition works) { do that }
; Well, none of the above worked, so do this last thing in an "otherwise" condition else { do something else entirely }
Control drops out of the IF-ELSEIF-ELSE structure when it finds its first matching ($true) condition. The others are not even tested or considered at all. So, if the IF condition works, ELSEIF and ELSE are completely disregarded. If the IF fails, then the ELSEIF condition is tested and, if it is true, then the code in the ELSEIF block is executed and the ELSE section is completely disregarded. If neither the IF nor the ELSEIF match, then the ELSE code is executed. The main function of { } is to group multiple commands, either on a single line separated by | or on multiple lines; in the case of multiple commands, { } are required to group all the commands into a block. They are not required for a single command on the same line; that is why I repeatedly removed them from my example code. They are required for anything that is multi-lined, single command or multiple commands. (Note that this is not the same thing at all as $&, which is line continuation ... continuing the same line on the next line but still treating it as if it were all on one line, which is used for readability for very long script lines.)
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 i have another goodie Question for you.. :P
Can an on text go into an if?
e.g.
if (on *:text:This:#: {} ) {/msg $chan That} - i've tried this and i know its wrong, but is there anyway it is possible?
Thanks again
Coca-Bear
|
|
|
|
Joined: Dec 2002
Posts: 395
Fjord artisan
|
Fjord artisan
Joined: Dec 2002
Posts: 395 |
|
|
|
|
Joined: Dec 2002
Posts: 40
Ameglian cow
|
OP
Ameglian cow
Joined: Dec 2002
Posts: 40 |
ok i tested that.. it didn't work.. i'll show you what i have. alias buy {
/msg $chan Welcome $nick What would you like to by?
/notice $nick Blue Potion 500coins Restores 10HP
/notice $nick Crystal Blue Potion 1000coins Restores 50HP
/notice $nick Heal Potion 3000coins Restores 150HP
/notice $nick Elixer of Heal 10000coins Restores 5000HP
if (Blue_Potion isin $1-) {/msg $chan Just Testing}
}
Coca-Bear
|
|
|
|
Joined: Dec 2002
Posts: 3,138
Hoopy frood
|
Hoopy frood
Joined: Dec 2002
Posts: 3,138 |
on *:TEXT:!buy*:#:{ buy $2- } alias buy { msg $chan Welcome $nick What would you like to by? notice $nick Blue Potion 500coins Restores 10HP notice $nick Crystal Blue Potion 1000coins Restores 50HP notice $nick Heal Potion 3000coins Restores 150HP notice $nick Elixer of Heal 10000coins Restores 5000HP if ( Blue_Potion isin $1- ) { msg $chan Just Testing } }
|
|
|
|
Joined: Dec 2002
Posts: 40
Ameglian cow
|
OP
Ameglian cow
Joined: Dec 2002
Posts: 40 |
ok i don think i've explained myself here :tongue:
this is how i washoping to go..
they type !buy it /notices them the items.. then they type Blue_Potion and it says "you have just brought a Blue_Potion".. or whatever my item they brought. i dont want to have it !buy Blue_Potion because i want them to go though the !buy (like a shop).
Does this make any sense? hehe
Coca-Bear
|
|
|
|
Joined: Dec 2002
Posts: 3,138
Hoopy frood
|
Hoopy frood
Joined: Dec 2002
Posts: 3,138 |
on *:TEXT:!buy*:#:{ msg $chan Welcome $nick What would you like to by? notice $nick Blue Potion 500coins Restores 10HP notice $nick Crystal Blue Potion 1000coins Restores 50HP notice $nick Heal Potion 3000coins Restores 150HP notice $nick Elixer of Heal 10000coins Restores 5000HP } on *:TEXT:blue_potion:#:{ notice $nick You have just bought a blue_potion! }
Something like that would work..
|
|
|
|
Joined: Dec 2002
Posts: 40
Ameglian cow
|
OP
Ameglian cow
Joined: Dec 2002
Posts: 40 |
i wanted the person to be in !buy to actually buy the blue potion.. with that code.. i can just do Blue_Potion and it buys it for me.. i dont have to use !buy
e.g.
!buy Blue_Potion.
They have to do !buy before they can do Blue_Potion.
Coca-Bear
|
|
|
|
Joined: Dec 2002
Posts: 3,138
Hoopy frood
|
Hoopy frood
Joined: Dec 2002
Posts: 3,138 |
Edit: Scratch this post, I didn't read properlythey type !buy it /notices them the items.. then they type Blue_Potion and it says "you have just brought a Blue_Potion" You didn't say they had to type !buy blue_potion, but whatever. on *:TEXT:!buy*:#:{ if ( $2 == Blue_Potion ) { notice $nick You have bought a blue potion! } if ( $2 == Crystal_Blue_Potion ) { notice $nick You have bought a crystal blue potion! } if ( $2 == $null ) { msg $chan Welcome $nick What would you like to by? notice $nick Blue Potion 500coins Restores 10HP notice $nick Crystal Blue Potion 1000coins Restores 50HP notice $nick Heal Potion 3000coins Restores 150HP notice $nick Elixer of Heal 10000coins Restores 5000HP } }
|
|
|
|
Joined: Dec 2002
Posts: 40
Ameglian cow
|
OP
Ameglian cow
Joined: Dec 2002
Posts: 40 |
Ok again i dont think you understand what i'm tryint to get at...
!buy It lists the items then can buy. after they have type !buy they can purchase items. "Blue_Potion" this buys the potion.. But i only want the items to be purchased AFTER they have !buy and it lists the items.
Does this make any sense? or you still dont understand..
Coca-Bear
|
|
|
|
Joined: Dec 2002
Posts: 3,138
Hoopy frood
|
Hoopy frood
Joined: Dec 2002
Posts: 3,138 |
on *:TEXT:!buy*:#:{ set %buying $+ $nick 1 msg $chan Welcome $nick What would you like to by? notice $nick Blue Potion 500coins Restores 10HP notice $nick Crystal Blue Potion 1000coins Restores 50HP notice $nick Heal Potion 3000coins Restores 150HP notice $nick Elixer of Heal 10000coins Restores 5000HP } on *:TEXT:Blue_Potion:#:{ if ( $eval(% $+ buying $+ $nick,2) == 1 ) { notice $nick You have bought a blue potion! unset %buying $+ $nick 1 } }
When someone types !buy it sets a variable to say they are buying something.
When someone types blue_potion it unsets the variable and tells them they have bought it...if this isn't it I give up..
|
|
|
|
Joined: Dec 2002
Posts: 40
Ameglian cow
|
OP
Ameglian cow
Joined: Dec 2002
Posts: 40 |
This is EXACTLY what i wanted.. thank you VERY much.. :P :P Coca-Bear
|
|
|
|
Joined: Dec 2002
Posts: 3,138
Hoopy frood
|
Hoopy frood
Joined: Dec 2002
Posts: 3,138 |
Sorry it took me so long lol
|
|
|
|
|