ID:1225250
 
                    if("Sell")
var/tmp/itemslist = list()
for(var/mob/Player/obj/item in src.contents)
itemslist+= "[item.name] ([item.value])"
switch(input("What would you like to sell?","Weapons Shop")in list(itemslist))
for(var/mob/Player/obj/selling in src.contents)
if("[selling.name] ([selling.value])")
switch(alert("Would you like to sell your [selling.name] for [selling.value]?","Confirmation","Yes","No"))
if("Yes")
retry
if(selling.equipped)
switch(alert("You have [selling] equipped. Please unequip it.","Warning!","Retry","Cancel")
if("Retry")
goto retry
if("Cancel")
return
else
src.xal+=selling.value
src.contents-=selling

edit: I updated the code


I've gotten this far. My only problem is I need to get this to be recognized as an if statement by the switch statement. I'm brain dead at the moment and apparently can't do that myself o______o... #TeamCodingForDaysStraight lol. I'd greatly appreciate someones help so I can finally add a shop system to my game. :)
Did you really just use a hash tag ....
Yes. For the lol's. :o.. Please don't hurt me, Daniel. q_q
I'm confused. What's the problem?

By the way, you have a switch statement with no if() statements after it. You just go straight to for().
You can't use a for() loop inside of a switch() statement. You're trying to do the job of an actual interface inside of an input() statement which obviously causes more problems than it's worth. But in your case, since you don't want to actually change the name of the object, just try adding a suffix.

Like this:
if("Sell")
var/tmp/itemlist = list(src.contents) //Creates a temporary copy of the src's contents
for(var/obj/o in itemlist) //Loop through the items in the TEMP list.
o.suffix += " ([o.price])" //Add a suffix onto the name for show.
var/item = input("What would you like to sell?", "Vendor") in list(itemlist) //Now you should see the names how you want them. Your choice is attached to the var "item"
for(var/obj/o in src.contents) //Loops through the items in src.contents
if(item == o) //If the object parsed is the object you're looking for...
var/bool = alert("Are you sure you would like to sell your [o.name] for [o.price]?", "Confirm", "Yes", "No") // Confirm the choice
if(bool == "Yes")
src.contents -= o //Remove the item
src.money += o.price //Add the money
... //Dialogue here
else
// Do what the hell ever.
break //Always break from a loop


This isn't tested, but it compiles just fine. The var itemlist is a list of actual objects, not just their names, which makes it 100,000,000x more efficient at matching two objects up than what you were trying to do.
I know. But how will I do that. That's the main problem. Lol.. I "need" that if statement. I'm basically making an option for players to sell what's in their inventory.
Just read through my code, I think that I've commented it thoroughly enough to understand what I'm doing. Unless Ive missed something, this code does exactly what you're wanting it to do.
It doesn't work apparently. Doesn't show anything at all. I presume because the alert is in a for loop.
No the if() before it defeats a loop it's checking to see if item selected is in the users contents if it is then it'll alert you and ask if you want to sell.

Otherwise it'll just break [EDIT] the loop...
So I guess I knew that subconsciously since I did it in my code already kinda. Still, nothing pops up:

                    if("Sell")
sell
var/tmp/itemlist = list(usr.contents) //Creates a temporary copy of the src's contents
if(!itemlist)
usr << "You have nothing to sell."
return
for(var/mob/Player/obj/items in itemlist) //Loop through the items in the TEMP list.
items.suffix += " ([items.value])" //Add a suffix onto the name for show.
var/item = input("What would you like to sell?", "Weapons Shop") in list(itemlist,"Cancel") //Now you should see the names how you want them. Your choice is attached to the var "item"
for(var/mob/Player/obj/selling in usr.contents) //Loops through the items in src.contents
if(item == selling) //If the object parsed is the object you're looking for...
var/bool = alert("Are you sure you would like to sell your [selling.name] for [selling.value]?", "Confirm", "Yes", "No") // Confirm the choice
if(bool == "Yes")
usr.xal += selling.value //Add the money
usr.contents -= selling //Remove the item
goto sell
if("Cancel")
return


Anything done wrong?
What? No. The alert() call pauses the function until an option is selected.
Why on earth are you using goto?

And what is this?
for(var/mob/Player/obj/items in itemlist)
I'm using goto so it'll repeat it. Some people don't like having to click the vendor again. So at some spots where users would like it to repeat I'll do it for them.

Idk.. I forgot.. xD Dude you don't understand how fried my brain is. I'm so determined to get this done before I get off. But if you can find out what it does then by all means, tell me.

Edit: The for loop is made so that each item in the loop will receive a suffix that will tell the user what price they have. In this case, items.suffix += " ([items.value])". "value" is already preset when the object was made as well.

I swear.. making a sell function has got to be easier than this. I know it.. -_-
There's usually always a better way to do things than using goto.

I was hoping that I'd nudged you into seeing the issue.
for(var/mob/Player/obj/items in itemlist)
//this is checking for mob/Player/obj/items in your inventory

for(var/obj/items in itemlist)
//This is the actual path to your items.

In response to Danny Roe
Danny Roe wrote:
There's usually always a better way to do things than using goto.

I was hoping that I'd nudged you into seeing the issue.
for(var/mob/Player/obj/items in itemlist)
> //this is checking for mob/Player/obj/items in your inventory
>
> for(var/obj/items in itemlist)
> //I assume this is the actual path to your items.


Uhm.. Nope.

mob/var
sword = 0
shield = 0
armor = 0
boots = 0
value = 0
equipped = 0

mob/Player/obj
Wooden
icon='Items.dmi'
Sword
name = "Wooden Sword"
value = 175
icon_state = "Wooden Sword"
equipped = 0
Click()
if(!usr.sword)
usr.overlays+= /mob/Player/obj/Wooden/Sword
usr.str+= 5
usr.sword=1
src.equipped = 1
src.suffix = "Equipped"
else
if(usr.sword)
usr.overlays-= /mob/Player/obj/Wooden/Sword
usr.str-= 5
usr.sword = 0
src.equipped = 0
src.suffix = null


It's not.
Why are you defining your items as mobs instead of objects?
At first I wondered the same thing.. But I kept thinking about CPU Usage and crap and "every penny counts".. So I set it for only those who'll actually be using the object. Players. It works fine when equipping and etc. The inventory actually lists it also. So I would guess that the path itself is fine also. I just left it.
loading Legend of Another World Alternative.dme
loading skins.dmf
Version 2.2 NPCs.dm:82:error: items.value: undefined var
Version 2.2 NPCs.dm:86:error: selling.value: undefined var
Version 2.2 NPCs.dm:88:error: selling.value: undefined var
Version 2.2 NPCs.dm:89:error: selling.value: undefined var

Legend of Another World Alternative.dmb - 4 errors, 0 warnings (double-click on an error to jump to it)

Oh, and this is what happens when you change the paths. Thia also led me to using mob/Player/obj
As a mob is a movable atom, it can be added to contents yes. However what you've done is create a mob that will hold all the variables of it's parents. Instead of creating an object with a half dozen defined variables, you now have a mob with the variables it needs, the variables you've set for all mobs and the variables set for mob/Players.
mob/var
sword = 0
shield = 0
armor = 0
boots = 0
value = 0
equipped = 0
//etc.

mob/Player/var
Level
Health
MaxHealth
Experience
ExperienceNeeded
Mana
MaxMana
//etc

mob/Player/obj
Wooden
icon='Items.dmi'
Sword
//This now has all those variables above


As opposed to:
obj/Item
icon='Items.dmi'
var
sword = 0
shield = 0
armor = 0
boots = 0
value = 0
equipped = 0
Wooden
Sword
icon_state="Wooden Sword"
//etc.

I did what you said and got the exact samee errors.

mob/var
sword = 0
shield = 0
armor = 0
boots = 0

obj/Wooden/var
value = 0
equipped = 0

obj
Wooden
icon='Items.dmi'
Sword
name = "Wooden Sword"
value = 175
icon_state = "Wooden Sword"
equipped = 0
Click()
if(!usr.sword)
usr.overlays+= /obj/Wooden/Sword
usr.str+= 5
usr.sword=1
src.equipped = 1
src.suffix = "Equipped"
else
if(usr.sword)
usr.overlays-= /obj/Wooden/Sword
usr.str-= 5
usr.sword = 0
src.equipped = 0
src.suffix = null


and

                    if("Sell")
sell
var/tmp/itemlist = list(usr.contents) //Creates a temporary copy of the src's contents
if(!itemlist)
usr << "You have nothing to sell."
return
else
usr << "k"
for(var/obj/items in itemlist) //Loop through the items in the TEMP list.
usr <<"pass"
src << "passed"
items.suffix += " ([items.value])" //Add a suffix onto the name for show.
var/item = input("What would you like to sell?", "Weapons Shop") in list(itemlist,"Cancel") //Now you should see the names how you want them. Your choice is attached to the var "item"
for(var/obj/selling in usr.contents) //Loops through the items in src.contents
if(item == selling) //If the object parsed is the object you're looking for...
var/bool = alert("Are you sure you would like to sell your [selling.name] for [selling.value]?", "Confirm", "Yes", "No") // Confirm the choice
if(bool == "Yes")
usr.xal += selling.value //Add the money
usr << "You have sold your [selling.name] for [selling.value]."
usr.contents -= selling //Remove the item
goto sell
if("Cancel")
return
Page: 1 2