ID:148375
 
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
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!"
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.
In response to Garthor
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()
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!"
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
view(8) << 'tr_kevlar.wav'
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
view(8) << 'tr_kevlar.wav'
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!"
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!"
In response to Wanabe
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)
In response to SuperSaiyanGokuX
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.
In response to Wanabe
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.
In response to Garthor
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...

In response to Wanabe
                switch(k)
if("kevlar")
if(usr.gp>=650)
if(usr.kev==0)
usr.Health+=25
view(8) << 'tr_kevlar.wav'
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
view(8) << 'tr_kevlar.wav'
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!"
In response to Garthor
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?..
In response to Garthor
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...
In response to Garthor
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)
switch(n)
if(1) usr << "One"
if(2) usr << "Two"
else usr << "Not one or two"


That worked fine for me.

~>Volte