ID:179020
 
ok I now know how to add objects to an inventory but I have no idea how to remove objects

obj
desk
icon = 'podium.dmi'
icon_state = "desk"
verb/sit()
set src in oview(0)
if(usr.cl == 0)
usr.cp += 1
usr.cl += 1
usr << ""

if(usr.cp == 1)
new /obj/ranks (usr)

I would guess that I need a command that does the oposit of new can someone give me a clue where to find this in the reference
this is what I have so far

desktwo
icon = 'podium.dmi'
icon_state = "desktwo"
density = 0
verb/sit()
set src in oview(0)
if(usr.cl == 0)
usr << ""
if(usr.cl == 1)
usr.cp += 1
usr.cl += 1

usr << ""
if(usr.cp == 2)
new /obj/cadet3
list.Remove( /obj/cadet4)


else
usr << ""

I get an warning on my list.remove command that the statement has no effect am I aproaching this wrong?
In response to Treasurecat
why wouldnt this work?

if(usr.cp == 2)
new /obj/cadet3
del /obj/cadet4

it gives me 3 errors bad var. thats kind of frustrating because that should work
In response to Treasurecat
When creating an object, you can use an object path. This is because all the compiler needs to know is what type to create.

When you want to delete an object, you have to refer to the actual object your deleting. This is because the compiler doesn't know which /obj/whatever your talking about, as there could be none, 100, 1000, or whatever. You must use a variable to refer to the object, and delete it. Heres an example
mob/verb/create_obj()
new /obj/test_object/ // a path

mob/verb/delete_obj()
var/obj/O = locate(/obj/) in src.contents // locates the first object in your contents, and stores a reference to it in the variable 'O'
del O // now that the compiler knows exactly what /obj/ we are talking about, it can delete it


You can also create an object while creating a reference to it: var/obj/O = new

Hope that's understandable, im not the best at explaining these kinds of things.
In response to Alathon
this is what I tried but its not getting rid of rank4

if(usr.cp == 10)
new /obj/cadet3 (usr)
var/obj/rank4 = locate(/obj/) in src.contents
del rank4


what am I doing wrong?
In response to Treasurecat
Treasurecat wrote:
this is what I tried but its not getting rid of rank4

if(usr.cp == 10)
new /obj/cadet3 (usr)
var/obj/rank4 = locate(/obj/) in src.contents
del rank4


what am I doing wrong?

locate(/obj/) finds the first /obj/ in src.contents, not neccessarily /óbj/rank4/, so simply specify what object you want it to find.

Alathon
In response to Alathon
ok so now I have

if(usr.cp == 10)
new /obj/cadet3 (usr)
var/obj/rank4 = locate(/obj/rank4) in src.contents
del rank4

but im getting a bad path error fo obj/rank4 ?
In response to Treasurecat
Your missing a / at the end of rank4

Alathon
In response to Alathon
it gives me the same error

if(usr.cp == 10)
new /obj/cadet3 (usr)
var/obj/rank4 = locate (/obj/rank4/) in src.contents
del rank4
In response to Treasurecat
Er, I must be very tired. Im not sure how to formulate this, but the last attachment or word on a variable is the name of the reference. Ie in our previous example:

obj/testobj

mob/verb/create()
var/obj/testobj/O = new

The testobj we've just created with that will be referred to as 'O', but it's still a testobj

Hope that clears it up heh
Alathon
In response to Alathon
ok that was my fault I did have a wrong path down

if(usr.cp == 10)
new /obj/cadet3 (usr)
var/obj/cadet4/ = locate (/obj/cadet4/) in src.contents
del cadet4

now I dont have that error anymore however its not deleting cadet4 like I want it to. this is what cadet4 object looks like.

obj
cadet4
icon = 'ranks.dmi'
name = "cadet 4th class"
icon_state = "cadet4"

I dont really understand or know what to do with the last code you posted im assumeing that you were trying to fix my bad path error but there are no errors now just the fact that its not removing the object I want it to.
In response to Treasurecat
Treasurecat wrote:
[snip]
I dont really understand or know what to do with the last code you posted im assumeing that you were trying to fix my bad path error but there are no errors now just the fact that its not removing the object I want it to.

Alathon was trying to get you to create a var of type /obj/cadet4 instead of /obj. I don't think it should matter in this case since all you are doing is deleting the obj.

Other than that, you have an extra path operator (/) on the end of your var declaration. I'm thinking it should be either:

var/obj/cadet4 = locate (/obj/cadet4/) in src.contents

which makes an obj named cadet4 or

var/obj/cadet4/cadet4 = locate (/obj/cadet4/) in src.contents

which makes an obj/cadet4 named cadet4.

Mind you, the extra / could be ignored for all I know, but it popped out at me.
In response to ACWraith
ACWraith wrote:

Alathon was trying to get you to create a var of type /obj/cadet4 instead of /obj. I don't think it should matter in this case since all you are doing is deleting the obj.

Other than that, you have an extra path operator (/) on the end of your var declaration. I'm thinking it should be either:

var/obj/cadet4 = locate (/obj/cadet4/) in src.contents

which makes an obj named cadet4 or

var/obj/cadet4/cadet4 = locate (/obj/cadet4/) in src.contents

which makes an obj/cadet4 named cadet4.

Mind you, the extra / could be ignored for all I know, but it popped out at me.

I tried removing it bbut it still doesnt delete rank4 from the inventory I also tried obj/cadet4/cadet4

if(usr.cp == 10)
new /obj/cadet3 (usr)
var/obj/cadet4 = locate (/obj/cadet4) in src.contents
del cadet4


I dont understand it should delete but it does not
In response to Treasurecat
Treasurecat wrote:
I tried removing it bbut it still doesnt delete rank4 from the inventory I also tried obj/cadet4/cadet4

if(usr.cp == 10)
new /obj/cadet3 (usr)
var/obj/cadet4 = locate (/obj/cadet4) in src.contents
del cadet4


I dont understand it should delete but it does not

The src.contents was just an example. This is under an object, and so 'src' is the object itself. The reason it isnt deleting is because your searching the objects contents list, not the usr's

Alathon
In response to Alathon
ahhh ok there it goes thanks