ID:144564
 
Code:
mob/NPCs/shop1
name = "Shop Bloke"
icon = 'mob85.dmi'
dir = WEST
DblClick()
if(get_step_away(src,usr,1))
var/list/Inventory = list(/*usr.contents,*/"Iron","Copper","Cancel")
var/list/choices1 = list("Buy","Sell","Cancel")
var/list/forsale = list("Iron Bar","Copper Bar","Clothes","Cancel")
input("What Would You Like To Do?","Shop Guy") in choices1
if("Buy")
input("What Would You Like To Buy?","Shop Guy") in forsale
if("Iron Bar")
if(usr.cash >= 100)
usr<<"You buy the iron bar."
new /obj/Pickupable/bars/iron(usr)
usr.cash -= 100
goto end
else if (usr.cash <= 99)
goto end
else if("Copper Bar")
if(usr.cash >= 50)
usr<<"You buy the copper bar."
new /obj/Pickupable/bars/copper(usr)
usr.cash -= 50
goto end
else if (usr.cash <= 49)
goto end
else if("Clothes")
if(usr.cash >= 10)
usr<<"You buy the clothes."
new /obj/Pickupable/Clothes(usr)
usr.cash -= 10
goto end
else if (usr.cash <= 9)
goto end
else if("Cancel")
goto end
else if("Sell")
input("What Would You Like To Sell?","Shop Guy") in Inventory
if("Copper")
for(var/obj/Pickupable/bars/copper/O in usr.contents)
usr<<"You sell the Copper Bar."
del O
usr.cash += 30
for(var/obj/Pickupable/ores/copper/D in usr.contents)
usr<<"You Need to refine Copper before selling."
goto end
else if ("Iron")
for(var/obj/Pickupable/bars/iron/O in usr.contents)
usr<<"You sell the Copper Bar."
del O
usr.cash += 75
for(var/obj/Pickupable/ores/iron/D in usr.contents)
usr<<"You Need to refine iron before selling."
goto end
else if ("Cancel")
goto end
end


Problem description:
Code Ignores what I Order it to do, I beleiveit has something to do with spacing but when I atempt to sort it out it starts saying
Mine Files.dm:185:error::invalid expression
For if("Iron Bar") and tells me
Mine Files.dm:211:error:else :'else' clause without preceding 'if' statement
Here: else if("Sell")
and thn gives me warnings, I amde this code myslef whilst disconnected from internet.
Please help me.
May want to get rid of, goto end, and just add in returns.
In response to Lord of light (#1)
I did that and that didnt work, so I decided to do go to ends.. Still I need Help
In response to Lyndonarmitage1 (#2)
Lyndonarmitage1 wrote:
I did that and that didnt work, so I decided to do go to ends.. Still I need Help

Bad decision. Lord was right- turn all those "goto end"s into "return"s and never use goto again- it's bad practise.

The only time you should use goto is in situations where there is no other good alternative, which in thise case is clearly not one of them.

It'd be useful in future if you could actually point out the error line-
Mine Files.dm:185:error::invalid expression
In this case, the error is in Mine Files.dm, line 185. You can press ctrl + G in Dream Maker to go straight to a line.


Here's the reason your code is screwed up:

            input("What Would You Like To Do?","Shop Guy") in choices1
if("Buy")
input("What Would You Like To Buy?","Shop Guy") in forsale
if("Iron Bar")


You're handling input all wrong. Input *returns* whatever the player selects from the box, right? Therefore you have to have something to catch whatever input returns back to it. Currently all you're doing is posing hte question "What would you like to do?" to the player and their choice is just thrown down the drain.

var/list/choices = list("i am good thanks","not so good thanks","SHUT")
var option = input("ah ah and how willam today") as null|anything in choices


Notice how that works? The variable option equals the player's choice, so now if you want to put some if statements in you have something to actually base it on.

mob/cobbo
Click()
var/list/choices = list("i am good thanks","not so good thanks","SHUT")
var option = input("ah ah and how willam today") as null|anything in choices
if(option == "i am good thanks")
usr << "ah ah cobbo glad 2 here that news thanks"
if(option == "not so good thanks")
usr << "ah ah that make cobbo =( why willam not good ant what can cobbo do to help"
if(option == "SHUT")
del(src)


However I'm going to put my neck out on the line and assume the reason you made the mistake of not checking the input()'s results with a variable was because you were likening your code to code that uses a switch(). To be frank, you did it wrong ( >=| )- here's how to do it right. :)

mob/cobbo
Click()
var/list/choices = list("i am good thanks","not so good thanks","SHUT")
var option = input("ah ah and how willam today") as null|anything in choices
switch(option) //<-- important. Observe:
if("i am good thanks") //look, no option == bit!
usr << "ah ah cobbo glad 2 here that news thanks"
if("not so good thanks")
usr << "ah ah that make cobbo =( why willam not good ant what can cobbo do to help"
if("SHUT")
del(src)


The switch() takes whatever variable you put into it (in this case, option) and any if() statements indented after the switch() statement will automatically assume you're talking about whatever var you put into switch() - in this case, option.

Here's a bit of your code changed to start you off:

            var/list/choices1 = list("Buy","Sell","Cancel")
var/list/forsale = list("Iron Bar","Copper Bar","Clothes","Cancel")
var option = input("What Would You Like To Do?","Shop Guy") as null|anything in choices1
switch(option)
if("Buy")
var product = input("What Would You Like To Buy?","Shop Guy") as null|anything in forsale
switch(product)
if("Iron Bar")
if(usr.cash >= 100)


The cool think about switch() is that it only takes into account the if() statement group once (I think- anyone more experienced than me finds an error in this, please correct me)- what I mean is this:
mob/verb
switch_example()
var foo = 5
switch(foo)
if(5)
foo = 10
if(10)
foo = 15
world << "Switch example: [foo]"
normal_example()
var foo = 5
if(foo == 5)
foo = 10
if(foo == 10)
foo = 15
world << "Normal example: [foo]"


switch_example would output "Switch example: 10" wheras normal_example would output "Normal example: 15".
In the normal_example verb it'd go through each if() statement consecutively, so you'd have to stick in loads of if() else statements to get it to work how you might want it, whereas switch() only takes into account one if() statement. Just compile the above and see for yourself.


I think you're handling your shop system wrong. Remember last time when I showed you how to improve your mining system? You should try and do it like that.

mob/NPCs/shop1
name = "Shop Bloke"
icon = 'mob85.dmi'
var/list/choices = list("Buy","Sell")
var/list/forsale = list("Iron Bar","Copper Bar","Clothes")
dir = WEST


Like that. And have less if() statements- don't manually write out if("Copper"), if("Iron Bar") and so on. Make it more intelligent- use text2path and awesome use of the new proc and so on to make it automatically make whatever object you decide the shopkeeper to have.

I wrote more information about it here: ID:498177

I suggest putting in the extra time to use the way I described because it'll save you hours of work later on. Say you want to add a new type of rock to your game? You'd have to spend hours and hours going through your code adding loads of fiddly little if() statements to accomadate the new rock type. With the system I am suggesting, all you'd need to do is change one or two variables and volia, it works!

Last little bit- notice the:
input() as null|anything in list()

bits? More specifically, the null|anything stuff? It adds an extra "cancel" button to the input(). Make sure that you have some way of recongnising it though- after the input put a if(!option) or some such then you can return the proc and stop it running if the player chose the cancel option.

Thanks Hiead and Tiberath!

In response to Elation (#3)
Lol no offense but that was pretty silly lol
In response to Elation (#3)
Thank yuo I was unaware of the importance of switch().
This has really helped!
Honestly with this knowlage i can master the input proc.
Thanks Hiead and Tiberath!
In response to Stephen-San (#4)
SHush :P
Yes it was :D