ID:139954
 
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)
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 happen

alert(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

So only one warning line needed, instead of one for each choice ^_^
*/


Please read the comments I made >_>'
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)
In response to BeignetLover
BeignetLover wrote:
I disagree with some of the errors DM gave me, too..

Keep disagreeing. Things will get better.
In response to BeignetLover
It would be much more helpful if you provided a snippet of what you did.
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 happen

alert(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

In response to BeignetLover
Your indention is not correct, all the if() and else should be under the switch()
X
Y
switch(Z)
if(A)
if(B)
else

Alpha
And the whole thing should be indented within the verb
In response to GhostAnime
still not working, appreciate your attempt to help, though.
In response to tidus123
this is the only one that fixes the bug, thank you for the link :)
In response to BeignetLover
Holy ffffff. Learn to indent, man.
I'd also recommend pressing F1 and reading the majority of "topic".
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.
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
In response to BeignetLover
BeignetLover wrote:
still not working, appreciate your attempt to help, though.

It is not working because you are not properly doing what was suggested to you, then, instead of showing what you attempted and asking for help, you say "it doesn't work"

Please, when someone gives you perfectly good help and you don't understand how to apply it, don't waste everyone's time by saying "thanks, but your help is no good" as that's basically what you're doing.

Obviously, you want to create something and possibly also learn. We also want you to succeed at learning and creating. When you don't know how to apply something, help us help you.

Now, show the version of your code that has the switch and which is indented properly and hopefully someone will explain to you where your problem is, and, more importantly, why it is a problem. You have to have patience, learning this stuff has a steep learning curve, and you might have to go through several rounds of changing something and asking for more help and changing again and asking for more help.
In response to BeignetLover
BeignetLover wrote:
this is the only one that fixes the bug

No, it is NOT the only one that fixes the bug. Others showed you perfectly successful ways to fix your bug, but you do not understand the language well enough to have implemented their suggestions properly and then you blamed that on the people trying to help you by telling them "thanks but it doesn't work."

This kind of behavior really irks me, and I could go on a several-page rant about it, but I won't waste my time; you've already wasted enough of several peoples' time as it is.

Don't let this discourage you though. We want you to succeed, but please use some etiquette and brainpower when bringing other people into it, and please help us help you.
In response to Loduwijk
Loduwijk wrote:
No, it is NOT the only one that fixes the bug. Others showed you perfectly successful ways to fix your bug, but you do not understand the language well enough to have implemented their suggestions properly and then you blamed that on the people trying to help you by telling them "thanks but it doesn't work."

This kind of behavior really irks me, and I could go on a several-page rant about it, but I won't waste my time; you've already wasted enough of several peoples' time as it is.

Don't let this discourage you though. We want you to succeed, but please use some etiquette and brainpower when bringing other people into it, and please help us help you.

I'm sure you could have found a much better place to bust out that rant. BeignetLover identified his own problem and posted relevant code. He actually tried other people's suggestions and thanked people for helping. This isn't the kind of person you should be complaining about. If you get this mad about people politely asking for help, maybe code problems isn't a good forum for you.

People post in code problems because they have code problems. This means they couldn't get their own code working because they screwed something up. By posting in code problems they're admitting that they aren't perfect. Because they're not perfect, there's a chance they might take someone's advice and screw that up too! It shouldn't come as a surprise when that happens. It should be more surprising when that doesn't happen.
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
In response to Forum_account
Forum_account wrote:
I'm sure you could have found a much better place to bust out that rant.

Nope, this was a great place.

BeignetLover identified his own problem and posted relevant code. He actually tried other people's suggestions and thanked people for helping.

Nope, apparently he did not. He thought he did, but whatever he did, he did not do it properly, he did not reply with any relevant code whatsoever, and his thanks were empty since it was accompanied with "Your code did not work" when that is completely false.

This isn't the kind of person you should be complaining about.

Yes it is; he does not help people help himself, then he places the failure on the person helping him by stating that their suggestion did not work, which is entirely false.

If you get this mad about people politely asking for help,

I have no problem at all with people politely asking for help. If you look closely, you will see that I never complained about any such thing.

maybe code problems isn't a good forum for you.

Obviously it is a good place for me since I have provided hundreds, if not thousands (my post count is in the thousands, and I know lots of them are how-to/problems, not sure the ratio though) of helpful responses to people requesting help. I have posted far, far more solutions to peoples problems than I have posted complaints, but sometimes complaints are necessary since some people don't understand how to use the forum or don't understand proper etiquette.

People post in code problems because they have code problems. This means they couldn't get their own code working because they screwed something up. By posting in code problems they're admitting that they aren't perfect. Because they're not perfect, there's a chance they might take someone's advice and screw that up too! It shouldn't come as a surprise when that happens. It should be more surprising when that doesn't happen.

Which I specifically mentioned in my reply which you yourself quoted. I explained to the OP that there may be several rounds of screwing things up and asking for more help.

People post in code problems because they have code problems. This means they couldn't get their own code working because they screwed something up. By posting in code problems they<s>'re admitting that...</s> should take it upon themselves to provide as much leverage for those they seek help from as possible, then they should take suggestions, try them, provide feedback and assistance to those assisting them. They should NOT ask for help, get solutions handed to them (all but spoonfed, and then even that with one of the solutions) and then tell those who lent assistance "Your suggestion did not work." Especially when the suggestion DID work and was even accompanied by an example!

Look closer at my complaint. If you do so, you should notice that I am specifically complaining about the manner in which the OP conducted these affairs, not that he conducted them at all in the first place. If that was my complaint, I might as well complain about the existance of this section of the forum. I would be sending messages via the support form requesting "Code Problems" be removed. That makes no sense, and it is not what I had any issue with.

(edit)
And don't forget that if he had helped others help him instead of saying "that didn't work" and forcing others to pull his mouth open so they could feed him, this thread would be half the size. Those posts of his and then the required responses they brought about caused half the posts in this thread to be completely useless wastes of space.
In response to Loduwijk
Loduwijk wrote:
he did not reply with any relevant code whatsoever

The original post, [link], contains the section of code relevant to his problem. [link] contains his version of GhostAnime's suggestion. By the time you started posting he had already found a solution ([link]), so there's no reason for him to post his code again.

and his thanks were empty since it was accompanied with "Your code did not work" when that is completely false.

Even if that were true, at least he had tact and didn't say something like "Wrong answer! Bring respect and gray matter next time."

I have provided hundreds, if not thousands of helpful responses to people requesting help. I have posted far, far more solutions to peoples problems than I have posted complaints

A helpful response is only useful when it says something that nobody else was going to say. If someone has a simple problem and you don't provide a solution, someone else will. You shouldn't be proud of your post count - these problems would have been solved without you. If the questions would have been answered without you, are you really providing a service to the community? Does that justify the complaints?

You should instead take pride in the times where you solved someone's problem when nobody else could. These are the times where you are actually contributing to the community even if it doesn't feel as substantial.
In response to BeignetLover
It wasn't meant to fix your bug. I was just showing you a link on how to use lists, so that you don't have to repeatedly use switch/if statements.