ID:139954   Jul 6 2010, 5:01 am Code: ```mob/NPC/ShopOwner icon = 'npcs.dmi' icon_state = "tat" verb Buy() set src in oview(3) var/clothe = input("What do you wish to buy? 1.Male Black Robe","Buy") as num if (clothe == 1) new/obj/blackrobe(usr) usr << "You got some clothes" usr.Gold -= 13 if (usr.Gold < 13) alert("You can't afford that!", "Buy") return() ``` Problem description: I don't get an error, however, when I test it, with only 10 gold, the shop owner says "You can't afford that!" and takes away 13 gold anyway (physically impossible, mathematically possible)
 <-> Jul 6 2010, 5:33 am Look at what you are doing: ```- if(select #1) + Give item + Take away money- if(Does not have money) + Give a message + return is useless here since it is at the end ``` The - and + represents the tabs. You are giving the person the item, taking away what it costs THEN check if they actually had enough. What you want to do is: - Check the person's choice (using switch() is HIGHLY recommended) - Check if the person has enough + Give item if enough, otherwise deny ```switch(input(...) as num|null) // |null adds the cancel button if(1) // if 1 was entered if(has 13 gold) give item, take money // You can put the else here and say you do not have enough, but look at what I will do. return // Reason for this if(2) // Note no else if in switch(). Else = terminates rest of the switch (else should be the very last option) if(has 25 gold) take money, give item return if(3) if(has 25000 gold) give item, take money return else // If the choice entered is NOT 1-3, ex: 4 or pressing cancel (which gives null) return // Says nothing, rest doesn't happenalert(usr,"You can't afford that!", "Buy")/*Only people who tried to buy something and did not have enough gets this.How? Look at what happened:- if person bought something, return stops the rest of the procedure from happening- if someone did not enter a correct choice, the return (via else in the switch()) stops the rest of the proc from happening- those who tried to buy something and did not have enough did not encounter any return, taking it to the very last statement, which is the messageSo only one warning line needed, instead of one for each choice ^_^*/ ``` Please read the comments I made >_>'
 <-> Jul 6 2010, 6:11 am In response to GhostAnime I tried your correction, it didn't work.. I disagree with some of the errors DM gave me, too.. loading Explore Hogwarts.dme npcs.dm:102:warning: empty 'else' clause (how?) npcs.dm:95:warning: : empty switch statement (...no) npcs.dm:95:error: : expected "if" or "else" (Why? it didn't NEED it" npcs.dm:95:error: if: invalid proc definition (if isn't a proc, DM is probably F'ed up or still in beta) npcs.dm:96:error: : invalid proc definition (once again If is not a proc) npcs.dm:97:error: : invalid proc definition( how so? this is a built in feature..) npcs.dm:105:error: usr: duplicate definition ( usr should be used quite a lot, thank you very much) npcs.dm:105:error: "You can't afford that!": duplicate definition(elaborate) npcs.dm:105:error: "Buy": duplicate definition(... I only use buy once,and it was for this NPC, stupid) Explore Hogwarts.dmb - 7 errors, 2 warnings (double-click on an error to jump to it)
 <-> Jul 6 2010, 6:13 am In response to BeignetLover BeignetLover wrote: I disagree with some of the errors DM gave me, too.. Keep disagreeing. Things will get better.
 <-> Jul 6 2010, 6:23 am In response to BeignetLover It would be much more helpful if you provided a snippet of what you did.
 <-> Jul 6 2010, 6:29 am In response to GhostAnime I copied and paste your code and edited it to work like my old version (without the scam) ```mob/NPC/ShopOwner icon = 'npcs.dmi' icon_state = "tat" verb Buy() set src in oview(3) switch(input("What would you like to Buy? 1. Male Black Robe") as num|null) // |null adds the cancel button if(1) // if 1 was entered if(usr.Gold < 13) new/obj/wand(usr) usr.Gold -= 13 // You can put the else here and say you do not have enough, but look at what I will do. return // Reason for this else // If the choice entered is NOT 1-3, ex: 4 or pressing cancel (which gives null) return // Says nothing, rest doesn't happenalert(usr,"You can't afford that!", "Buy")/*Only people who tried to buy something and did not have enough gets this.How? Look at what happened:- if person bought something, return stops the rest of the procedure from happening- if someone did not enter a correct choice, the return (via else in the switch()) stops the rest of the proc from happening- those who tried to buy something and did not have enough did not encounter any return, taking it to the very last statement, which is the message ```
 <-> Jul 6 2010, 6:35 am In response to BeignetLover Your indention is not correct, all the if() and else should be under the switch() ```XYswitch(Z) if(A) if(B) elseAlpha ``` And the whole thing should be indented within the verb
 <-> Jul 6 2010, 7:13 am In response to GhostAnime still not working, appreciate your attempt to help, though.
 <-> Jul 6 2010, 7:40 am
 <-> Jul 6 2010, 8:07 am In response to tidus123 this is the only one that fixes the bug, thank you for the link :)
 <-> Jul 6 2010, 8:36 am In response to BeignetLover Holy ffffff. Learn to indent, man. I'd also recommend pressing F1 and reading the majority of "topic".
 <-> Jul 6 2010, 7:10 pm stop teasing him and give him the answer already lol ```mob/NPC/ShopOwner icon = 'npcs.dmi' icon_state = "tat" verb Buy() set src in oview(3) var/clothe = input("What do you wish to buy? 1.Male Black Robe","Buy") as num if (usr.Gold < 13) alert("You can't afford that!", "Buy") return() else if (clothe == 1) new/obj/blackrobe(usr) usr << "You got some clothes" usr.Gold -= 13 ``` just put the checker ontop and ur done.
 <-> Jul 6 2010, 11:53 pm In response to Fast ball0 It's best to let people learn themselves. Also () isn't needed for a blank return.(Or for most returns, it just seperates things to be calculated differently) (1+2)*3
 <-> Jul 7 2010, 2:05 am In response to Fast ball0 Fast ball0 wrote: stop teasing him and give him the answer already lol ```> ...> if (usr.Gold < 13)> alert("You can't afford that!", "Buy")> return()> else> if (clothe == 1)> new/obj/blackrobe(usr)> usr << "You got some clothes"> usr.Gold -= 13> ``` just put the checker ontop and ur done. You're checking if the player has enough money before checking what item they selected. It doesn't make a difference in this case because there is only one item in this shop, but I'd make the change anyway: ```mob/NPC/ShopOwner icon = 'npcs.dmi' icon_state = "tat" verb Buy() set src in oview(3) var/clothe = input("What do you wish to buy? 1.Male Black Robe","Buy") as num if (clothe == 1) if (usr.Gold < 13) alert("You can't afford that!", "Buy") return new/obj/blackrobe(usr) usr << "You got some clothes" usr.Gold -= 13 ```