ID:169586
 
I'm working on a Text Based game set in a Mafia Theme.
I have a problem with a piece of code that handles the buying of weapons for your mafia.

verb Weapon_Shop() input("Welcome to Bulletnation. You have $[Money], [Htmen] hitmen, and [Sniper] snipers. What would you like to buy?") in list("9mm Glock $100","SOCOM Pistol $500","MP5 $850","XM8 Assault Rifle $1250","AK-47 $1450","Spas-12 Shotgun $1600","Beurrila M1 Twin-Barrel Shotgun $1750","FM Minimi Chaingun $4500","XM8714 Minigun $7000","Killer-Seven Sniper Rifle $6650","Payne-Killer Rocket Launcher $6650","Inferno Rage Flamethrower $15000","Leave") var/bulk = input("How many to you wanna buy?") as num if("9mm Glock $100") if(Money > 100*bulk) Money -= 100*bulk Glock += bulk Gangpower +=1 else usr << "You can't afford this!" return if("SOCOM Pistol $500") if(Money > 500*bulk) Money -= 500*bulk Pistol += bulk Gangpower +=2 else usr << "You can't afford this!" return if("MP5 $850") if(Money > 850*bulk) Money -= 850*bulk MP5 += bulk Gangpower +=4 else usr << "You can't afford this!" return
Notice the returns at the ends of the weapons. THOSE are the problem. Because of them, no matter what weapon I buy PERIOD it always buys the first weapon in the list:the 9mm Glock Handgun. If I remove them, which I have tried and tested, then when I buy any weapon, it buys ALL of them, meaning I get spammed with "You can't buy this" messages.
At first I found this funny, but after trying to fix it for a week now, I went here asking for help. I'm actually a noobish coder trying to make his first game, so any help would be really great.
try tabbing your returns once eh ;)
tab the returns in to look like this
else
usr << "msg"
return
In response to Mexus
Mexus wrote:
try tabbing your returns once eh ;)

Well...I replied....and guess what? It still only buys the glock. It was a good try but the tabbing effect was minimal.Any more help?
Okay, I'm not try to be mean, or anything like that I'm just trying to help you out.

Okay, if you post code that has something wrong with it put it in code problems, because as the name suggest it's for problems with your code.

If, you want to know how to do something, and don't post code for it, or if it has to do with mapping/icon ect. It goes here in Developer How-To.

Third, please when you post code put it in dm tags it makes it so much easier to read, but don't make a new post in a new area just because it's in the wrong one most of the time a mod will do that.

Just thought I'd say that, because sometimes it is kind of hard to help someone when they have long lines of code without tags, and is often annoying to see people posting how-to questions in code problems.

People are going to probably hate me now....<_<

-Digital Samurai


In response to Digital Samurai
Digital Samurai wrote:
Okay, I'm not try to be mean, or anything like that I'm just trying to help you out.

Okay, if you post code that has something wrong with it put it in code problems, because as the name suggest it's for problems with your code.

If, you want to know how to do something, and don't post code for it, or if it has to do with mapping/icon ect. It goes here in Developer How-To.

Third, please when you post code put it in dm tags it makes it so much easier to read, but don't make a new post in a new area just because it's in the wrong one most of the time a mod will do that.

Just thought I'd say that, because sometimes it is kind of hard to help someone when they have long lines of code without tags, and is often annoying to see people posting how-to questions in code problems.

People are going to probably hate me now....<_<

-Digital Samurai


As for that, sadly I couldn't figure out how to post in DM tags u_u;;;
In response to Paynekiller
you put a < D M > at the begining of the code, (no spaces)
This is the fixed code.
Note: as a verb, usr is fine here.

> verb
> Weapon_Shop()
> var/R = input("Welcome to Bulletnation. You have $[Money], [Htmen] hitmen, and [Sniper] snipers. What would you like to buy?") in list("9mm Glock $100","SOCOM Pistol $500","MP5 $850","XM8 Assault Rifle $1250","AK-47 $1450","Spas-12 Shotgun $1600","Beurrila M1 Twin-Barrel Shotgun $1750","FM Minimi Chaingun $4500","XM8714 Minigun $7000","Killer-Seven Sniper Rifle $6650","Payne-Killer Rocket Launcher $6650","Inferno Rage Flamethrower $15000","Leave")
> var/bulk = input("How many to you wanna buy?") as num
>
>
> if(R=="9mm Glock $100")
> if(Money > 100*bulk)
> Money -= 100*bulk
> Glock += bulk
> Gangpower +=1
> else
> usr << "You can't afford this!"
>
> if(R=="SOCOM Pistol $500")
> if(Money > 500*bulk)
> Money -= 500*bulk
> Pistol += bulk
> Gangpower +=2
> else
> usr << "You can't afford this!"
> if(R=="MP5 $850")
> if(Money > 850*bulk)
> Money -= 850*bulk
> MP5 += bulk
> Gangpower +=4
> else
> usr << "You can't afford this!"

What you were doing before, was giving the user a useless input, basicly saying, just ask this input, but don't define it as anything (meaning it wouldn't have any real purpose)
when doing
var/R = input("What is your name")
if(R == "Bob") src<<"You are bob."

that is the correct way of doing inputs.

when you were doing it the other way..
if("Gun")

that is basicly telling the program
if gun is true,
in more simpler terms, if apple is apple.
(which would always return true)

It does not link it to anything, rather as
var/R = input("What you wana buy?")in list("Gun")
if(R == "Gun")

That is saying, if R, the previous input you defined, equals to Gun, to run whats below.


Hope this explained what was wrong, if yuo need any help contact me.

AIM: chris062689
- Freelance code helper.
In response to DarkMystic182
to be correct
"<dm> starts it and if wanna type somthing after it you put "
"</dm> like the fellow said no spaces
In response to Paynekiller
Thanks Flame Sage, that fixed it allright! :D
And thanks to everyone who tried to help.I'll be sure to check back at the forums when I have any other problems that I can't solve on my own.
I bid you adieu.