mob/verb/Buy()
if(usr.buy==1)
var/c = input ("What category?") in list ("clips","rifles","equipment")
switch(c)
if("clips")
if(usr.gp>=35)
if(usr.clips>=3) return
else
usr<<"You buy a clip!"
usr.clips+=1
usr.gp-=35
else
if(usr.gp<=0)
usr<<"You dont have any cash to spend on this!"
else
usr<<"You dont have enough money to buy this, you have [usr.gp] and you need 35 cash!"
else
if("equipment")
var/k = input ("what will you buy?") in list ("kevlar","kev+helm")
switch(k)
if("kevlar")
if(usr.gp>=650)
if(usr.kev==0)
usr.Health+=25
usr.gp-=650
usr.kev=1
else
usr<<"You allready have armour!"
else
if(usr.gp<=0)
usr<<"You dont have any cash to spend on this!"
else
else
if("kev+helm")
if(usr.gp>=1000)
if(usr.kev==0)
usr.Health+=30
usr.gp-=1000
usr.kev=1
else
usr<<"You allready have armour!"
else
if(usr.gp<=0)
usr<<"You dont have any cash to spend on this!"
else
usr<<"You dont have enough money to buy this, you have [usr.gp] and you need 1000 cash!"
else
if("rifles")
if(usr.team=="blue")
var/l = input ("What kind of weapon would you like to buy?") in list ("colt","none")
switch(l)
if("colt")
if(usr.gp>=3500)
view(3) << 'm4a1_deploy.wav'
usr.gp-=3500
usr<<"You buy a colt!"
usr.clips=0
usr.max=30
usr.lbullets=30
else
if(usr.team=="red")
var/l = input ("What kind of weapon would you like to buy?") in list ("ak-47","none")
switch(l)
if("ak-47")
if(usr.gp>=3500)
view(3) << 'ak47_boltpull.wav'
usr<<"You buy a ak-47!"
usr.clips=0
usr.max=30
usr.gp-=3500
usr.lbullets=30
else
usr<<"Your not in the buy zone!"
ID:148375
![]() Mar 13 2003, 4:46 pm
|
|
ok i have a verb, whats bugging me is when i click on 'rifles' it goes to instead the equipment bit asking to buy kevlar and stuff, this is annoying, heres the verb
|
![]() Mar 13 2003, 6:29 pm
|
|
Take out the else's. They're removing the if()'s from the switch(), and thus reading it if("text string"), which is always true.
|
Garthor wrote:
Take out the else's. They're removing the if()'s from the switch(), and thus reading it if("text string"), which is always true. ok, now i can actully 'buy' the rifles,but i have to go to the equipment menu first, and then when i select one it 'buys' the armour, then goes to the rifle menu? :-| mob/verb/Buy() |
Heh, just a minor indentation error... Just move all of the if("rifles") part to the left by one tab... (including all of the code under that line)
|
SuperSaiyanGokuX wrote:
Heh, just a minor indentation error... Just move all of the if("rifles") part to the left by one tab... (including all of the code under that line) Man, i hate how i do mistakes like that, and its so simple to fix!, thanks. |
I told you, switch() statements are NOT supposed to have else in them. No else. Else bad. Don't have else. Since the value being switched is not going to change halfway through the proc unless if you tell it to inside the switch, there is no need for else statements.
|
Garthor, those else's aren't in his switch... They're in the chunks of code that are called from the switch... He has it like this:
switch(variable) if("choice1") if(something) dosomething else dosomethingelse if("choice2") if(something) dosomething else dosomethingelse if("choice3") if(something) dosomething else dosomethingelse That's perfectly fine... The else's aren't affecting the switch... |
switch(k) |
Garthor wrote:
I told you, switch() statements are NOT supposed to have else in them. No else. Else bad. Don't have else. Since the value being switched is not going to change halfway through the proc unless if you tell it to inside the switch, there is no need for else statements. huh, what?.. |
Oh, heh, I didn't notice the nested switch()... I was only looking at the first one...
Well, then, my apologies for my reply below...lol Garthor is right, else should not be in that switch()... Just delete that else, and move all of the if("kev_helm") stuff over one... |
Garthor wrote:
I told you, switch() statements are NOT supposed to have else in them. No else. Else bad. Don't have else. Not true. Elses work very well in switch() procedures. mob/verb/Test(n as num) That worked fine for me. ~>Volte |