ID:148153
 
Alright I have another problem :P, im full of them yes.

I have
var/obj/O = input("Which item do you want to trade?")in usr.contents

Now that shows all of the objects that person has in his list, unfortunately i have some things in there that i DONT want to show up that still do :( . Is there anyway to remove something from that, so they do not show up, or anyway to make it go back to the line What item do you want to trade? if its one of them I dont want to be traded? All help would be appriciated.


James
Well, if you only want Weapons to go in there change the category of obj/Spear to obj/Weapons/Spear, now theres a new 'folder' with the weapons in them, then do this var/obj/Weapons/O blah blah
In response to Crashed
Hey, That would work, thanks ;)

Now I have to edit the 300 items -.- oh well if it works its worth it ! :)

Didnt work. I applied what you said to the items I wanted to show up.. Maybe if i put the trade verb up here you can better understand why its making me mad.. -.-.

mob
verb
Trade(mob/M in oview (6))
set category = "Communication"
var/obj/weapons/O = input("Which item do you want to trade?")in usr.contents
switch(input(M,"[usr] wants to trade his [O]!","Trade","No") in list("Yes","No"))
if("Yes")
switch(input(M,"What will you trade for [usr]'s [O]?","Zenni","Item") in list("Zenni","Item"))
if("Zenni")
var/obj/Z = input(M,"How much zennie do you wish to trade for [O]?") as num|null
if(Z < 0||Z>M.zenni)
M << "You cheapskate! You need to put more than 0"
return
if(Z > 0&&Z<M.zenni)
switch(input(usr,"[M] has offered you [Z] Zenni, Do you accept?","Yes","No") in list("Yes","No"))
if("Yes")
O.loc = M
M.zenni -= Z
usr.zenni += Z
if("No")
usr << "[M] decided not to."
if("Item")
var/obj/weapons/O2 = input(M,"Which item do you want to trade?")in M.contents
switch(input(usr,"[M] wants to trade his [O2]for your [O]!","Trade","No") in list("Yes","No"))
if("Yes")
O.loc = M
O2.loc = usr
usr << "Trade finished"
M << "Trade finished"
if("No")
usr << "[M] doesnt want to trade at all."

I would think that var/obj/weapons/O = input("Which item do you want to trade?")in usr.contents would make stuff show up from weapons, or do you have to fix usr.contents.. thats what im thinking, anyhow how could i make that show up what i just put in the directory weapons.. Thanks


James
What you'd need to do here is build a list of items in your contents from scratch. Starting with an empty list, loop through everything in contents and, if you want to trade it, add it to the list.

Lummox JR
In response to Lummox JR
I suppose this is the only way to do it?? I have over 200 items. (its possible I'm misunderstanding what you are saying) but you want me to make a list on my own of all the items, then have it display the ones they have in the trade? That could take some time :/

[Edit] Alright if what you said is right, could you explain what to do better to me, it isn't often that it takes 3 people to figure out a problem like this on these forums ;) Thanks for everyones help.


James
Try this
var/obj/O = input("Blah, blah, blah...") in src.contents -= ssj

or some variation of that...I'm not quite sure on the operator you would use, but make it remove the ssj list.
In response to Dragon of Ice
Dragon of Ice wrote:
Try this
var/obj/O = input("Blah, blah, blah...") in src.contents -= ssj
or some variation of that...I'm not quite sure on the operator you would use, but make it remove the ssj list.

The -= operator would be invalid there and would cause an error in DM. Also you'd simply be removing items from the contents list period, which would change their location to null. That's not at all desired behavior.

Subtracting from the contents list is the wrong way to do it. What you need is to create a list, fill it with items you do want to show, and use that for input() instead of contents.

Lummox JR
In response to Dragon of Ice
Yeah ive tried that.. I think the problem is how to DEFINE whats in the list. Ive tried regular - ssj, - "SSJ"

if(O == "ssj")

Blahblah ect.. you get my point.

Looks like im going to have to see what Lummox meant and look into it. If anyone can explain to me what he said in better detail id be happy .. Thanks.



James
In response to Lummox JR
Alright, now I see what you mean.. Is there anyway to do an array from obj/weapons so I dont have to do all of the items on my own?? Thanks again Lummox


James
In response to SSJ2GohanDBGT
SSJ2GohanDBGT wrote:
Alright, now I see what you mean.. Is there anyway to do an array from obj/weapons so I dont have to do all of the items on my own?? Thanks again Lummox

Yes there is: Loop through all /obj/weapon items in the contents list, and add anything you want to be able to trade to the new list.

Lummox JR
In response to Lummox JR
Sorry to be annoying to everyone, im still having some trouble with this.

mob
verb
Trade(mob/M in oview (6))
set category = "Communication"
var/obj/O
for(obj/weapons(O= input("Which item do you want to trade?")in usr.contents))
Its not

In this it thinks that obj and weapons should be variables. I obviously didn't loop it right.. Any suggesitons?? Thanks.

James
In response to SSJ2GohanDBGT
SSJ2GohanDBGT wrote:
for(obj/weapons(O= input("Which item do you want to trade?")in usr.contents))

That's not even close to correct syntax. The point of the for() loop is to build a list of items before you call input(), and use that list for the input() instead of usr.contents.

Lummox JR
In response to Lummox JR
mob
verb
Trade(mob/M in oview (6))
set category = "Communication"
var/list/Wep
for(src.contents in /obj/weapons)
if(src.contents in /obj/weapons)
Wep.Add(src.contents)
var/obj/weapons/O = input("Which item do you want to trade?")in input(Wep)
switch(input(M,"[usr] wants to trade his [O]!","Trade","No") in list("Yes","No"))
if("Yes")
switch(input(M,"What will you trade for [usr]'s [O]?","Zenni","Item") in list("Zenni","Item"))
if("Zenni")
var/obj/Z = input(M,"How much zennie do you wish to trade for [O]?") as num|null
if(Z < 0||Z>M.zenni)
M << "You cheapskate! You need to put more than 0"
return
if(Z > 0&&Z<M.zenni)
switch(input(usr,"[M] has offered you [Z] Zenni, Do you accept?","Yes","No") in list("Yes","No"))
if("Yes")
O.loc = M
M.zenni -= Z
usr.zenni += Z
if("No")
usr << "[M] decided not to."
if("Item")
var/obj/weapons/O2 = input(M,"Which item do you want to trade?")in M.contents
switch(input(usr,"[M] wants to trade his [O2]for your [O]!","Trade","No") in list("Yes","No"))
if("Yes")
O.loc = M
O2.loc = usr
usr << "Trade finished"
M << "Trade finished"
if("No")
usr << "[M] doesnt want to trade at all."


Is this put together any better?

It works except that i get some sort of stack error in Dreamseeker (Maybe caused by how I call it?) Im not sure.. Thanks for everyones patience.

James
In response to SSJ2GohanDBGT
SSJ2GohanDBGT wrote:
var/list/Wep

You need to initialize the list with list() or new before you can add anything to it.

for(src.contents in /obj/weapons)

No. You need to loop through src.contents, not through a type path (which won't work--nothing will happen). Define a var of type /obj/weapons and then loop that var through src.contents.

if(src.contents in /obj/weapons)

Same bad syntax, but it's also redundant; this will be covered by the loop itself.

Wep.Add(src.contents)

Do you want to add the entire contents list to the list (as this will do), or just the one weapon you're checking in the loop?

var/obj/weapons/O = input("Which item do you want to trade?")in input(Wep)

The second input() there is wrong.

Lummox JR
In response to Lummox JR
Hm.. this is the closest thing ive had to work

mob
verb
Trade(mob/M in oview (6))
set category = "Communication"
var/add
var/list/Wep
Wep = new/list()
for(Wep in src.contents)
Wep.Add(add)
var/obj/weapons/O = input("Which item do you want to trade?")in add
switch(input(M,"[usr] wants to trade his [O]!","Trade","No") in list("Yes","No"))
if("Yes")
switch(input(M,"What will you trade for [usr]'s [O]?","Zenni","Item") in list("Zenni","Item"))
if("Zenni")
var/obj/Z = input(M,"How much zennie do you wish to trade for [O]?") as num|null
if(Z < 0||Z>M.zenni)
M << "You cheapskate! You need to put more than 0"
return
if(Z > 0&&Z<M.zenni)
switch(input(usr,"[M] has offered you [Z] Zenni, Do you accept?","Yes","No") in list("Yes","No"))
if("Yes")
O.loc = M
M.zenni -= Z
usr.zenni += Z
if("No")
usr << "[M] decided not to."
if("Item")
var/obj/weapons/O2 = input(M,"Which item do you want to trade?")in M.contents
switch(input(usr,"[M] wants to trade his [O2]for your [O]!","Trade","No") in list("Yes","No"))
if("Yes")
O.loc = M
O2.loc = usr
usr << "Trade finished"
M << "Trade finished"
if("No")
usr << "[M] doesnt want to trade at all."

I also tried adding
for(Wep in src.contents)
if(wep in /obj/weapons)
Wep.Add(add)
It goes through but doesnt give a list on what to trade, although i was sure i had it in right. Thanks for helping me to understand this Lummox


James
In response to SSJ2GohanDBGT
SSJ2GohanDBGT wrote:
var/list/Wep
Wep = new/list()

So far so good, though I'd just use new or list(), not both; the combination tends to be flaky unless you're initializing a list with a certain number of blank spaces.

for(Wep in src.contents)

WRONG!

Wep is a /list, so you're saying you want the for() loop to look for every /list in src.contents. Since the contents list contains atoms, not lists, this is incorrect.

Really you need to stop and actually think this through. You're not applying yourself to the problem, and it shows. I told you to loop through every /obj/weapon in contents, not anything else. If you look up for(), you'll see good examples of this.

Stop just putting in var names and code at random. Try to understand what you're doing.

Wep.Add(add)

The variable "add" hasn't been assigned anything yet. What you should be adding to Wep should be the same thing that's at the beginning of for(), the var you loop through in src.contents.

You don't have a valid use at all for the add var, so you should just remove it outright.

var/obj/weapons/O = input("Which item do you want to trade?")in add

The list is Wep, not add. Again, you need to think about what you're doing here. Which var is the list supposed to be? Obviously that should be Wep.

switch(input(M,"[usr] wants to trade his [O]!","Trade","No") in list("Yes","No"))

There's no error in this line, but I'd use "\his" instead of "his" for gender-awareness.

Lummox JR
In response to Lummox JR
Alright ive tried

Wep = new()
for(src.contents in /obj/weapons)
Wep.Add(Wep)


Is the (Wep) needed to add it into the list?

Also by looping though obj/weapons in contents would the above work? if i switch them around it assumes obj and weapons should be variables.

Underneath that I get what you mean by the list being Wep now. And the trade verb works correctly, except that it assumes its all the items :( .. Im still unsure how to loop it, i assume for(src.contents in /obj/weapons) means it loops through all of what src has in contents, thats also in /obj/weapons ?? Thanks for your patience..


James
In response to SSJ2GohanDBGT
SSJ2GohanDBGT wrote:
for(src.contents in /obj/weapons)

NO! Stop adding things at random!

I already told you that exact line is totally wrong. You can't loop through a type path, which is what you're doing when you should be looping through src.contents, and the thing that goes on the left should be the item you check each time, so it should be an /obj/weapon var.

Look up for(), and stop putting in things haphazardly without even thinking about what you're doing.

Wep.Add(Wep)

Why on earth would you want to add the list to itself? That's what that line will do.

The goal here is to add an item to the list, the same item from the for() loop.

Also by looping though obj/weapons in contents would the above work?

No, and I told you so before.

if i switch them around it assumes obj and weapons should be variables.

That's because the thing on the left is in fact supposed to be a var, not a type path. It should be a var of type /obj/weapons, but not the type path itself. In other words, something like the O you use in the input() line below it.

The thing on the right in the for() loop should be the list you loop through, which would be src.contents. Don't go changing that to other things just because you're having problems with other parts of the code.

Lummox JR
In response to Lummox JR
You may not be able to loop through a type path, but you CAN loop through typesof()
In response to Jon88
Jon88 wrote:
You may not be able to loop through a type path, but you CAN loop through typesof()

Yes, because that's a list--but that's kind of beside the point here. The goal in this case is to loop through atoms in a contents list.

Lummox JR
Page: 1 2