mIRC Home    About    Download    Register    News    Help

Print Thread
Page 2 of 2 1 2
#5504 08/01/03 04:15 PM
Joined: Dec 2002
Posts: 1,321
H
Hoopy frood
Offline
Hoopy frood
H
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):
Code:

  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:
Code:

  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:
Code:

  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
#5505 10/01/03 11:27 AM
Joined: Dec 2002
Posts: 40
C
Ameglian cow
OP Offline
Ameglian cow
C
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

#5506 10/01/03 11:34 AM
Joined: Dec 2002
Posts: 395
M
Fjord artisan
Offline
Fjord artisan
M
Joined: Dec 2002
Posts: 395
if (<text> isin $1-) { }

#5507 10/01/03 12:57 PM
Joined: Dec 2002
Posts: 40
C
Ameglian cow
OP Offline
Ameglian cow
C
Joined: Dec 2002
Posts: 40
ok i tested that.. it didn't work.. i'll show you what i have.

Code:
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

#5508 10/01/03 01:01 PM
Joined: Dec 2002
Posts: 3,138
C
Hoopy frood
Offline
Hoopy frood
C
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 }
}

#5509 10/01/03 01:10 PM
Joined: Dec 2002
Posts: 40
C
Ameglian cow
OP Offline
Ameglian cow
C
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

#5510 10/01/03 01:18 PM
Joined: Dec 2002
Posts: 3,138
C
Hoopy frood
Offline
Hoopy frood
C
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..

#5511 10/01/03 01:48 PM
Joined: Dec 2002
Posts: 40
C
Ameglian cow
OP Offline
Ameglian cow
C
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

#5512 10/01/03 01:52 PM
Joined: Dec 2002
Posts: 3,138
C
Hoopy frood
Offline
Hoopy frood
C
Joined: Dec 2002
Posts: 3,138
Edit: Scratch this post, I didn't read properly

Quote:
they 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
}
}


#5513 10/01/03 02:08 PM
Joined: Dec 2002
Posts: 40
C
Ameglian cow
OP Offline
Ameglian cow
C
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

#5514 10/01/03 02:14 PM
Joined: Dec 2002
Posts: 3,138
C
Hoopy frood
Offline
Hoopy frood
C
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..

#5515 10/01/03 02:21 PM
Joined: Dec 2002
Posts: 40
C
Ameglian cow
OP Offline
Ameglian cow
C
Joined: Dec 2002
Posts: 40
This is EXACTLY what i wanted.. thank you VERY much.. :P :P blush

Coca-Bear

#5516 10/01/03 02:23 PM
Joined: Dec 2002
Posts: 3,138
C
Hoopy frood
Offline
Hoopy frood
C
Joined: Dec 2002
Posts: 3,138
Sorry it took me so long lol

Page 2 of 2 1 2

Link Copied to Clipboard