ID:269812
 
I have a variable in a procedure that is a reference to an object. I then call a procedure of another object with that varialbe passed as a parameter.

I have 2 variables referenced to objects in the object that houses the procedure I just called. I set one to the parameter. How do I copy the 1st variable to the 2nd variable. And then delete the first variable. With out the 2nd variable becoming null? Note that the very first variable that is passed as the parameter is null.

Would I use the vars list? Is it even possible with byond.
Since byond references every thing but numbers. I was thinking it was.
Um, you'll have to show some sample code here, because what you just said was impossible to follow.

Lummox JR
In response to Lummox JR
Yeah, I tried awful hard to follow, but it's pretty dense.
obj/housing_object{
var{
field1 = new /datum
field2 = new /datum
}
a_method(){
var/reference_to_an_object = new /datum()
another_procedure(reference_to_an_object)
}
another_method(var/datum/the_object){
field1 = the_object
field2 = field1
dostuff()
del field1
}
}

Am I correct that this is the basic setup you have?

I set one to the parameter.
"field1 = the_object"
field1's value is set to the value of "the_object," which is a reference.

How do I copy the 1st variable to the 2nd variable.
"field2 = field1"
field2's value is set to the value of "field1," which is a reference.

...And then delete the first variable without the 2nd variable becoming null?
'Deleting' field1 will result in the deletion of it's value. In other words, the reference (data object) will be cleared from memory, and DM's reference counter will kick in and null out any references to it, including field2. Therefor the value of field2 now equals null. If you want to null out field1, you can directly set it equal to null:
field1 = null
This sets the value of field1 equal to null; the value of field2 remains a reference.
Note: DM does not have alias variables, or variables that point to other variables. This is probably where your confusion comes from. Here's an example:
mob/verb/The_Major(){
var/the_moose_says = "I speak English, I learned it from a book."
var/the_mooses_brain = the_moose_says
the_mooses_brain = null
world << the_moose_says
}
//This outputs "I speak English, I learned it from a book."


Note that the very first variable that is passed as the parameter is null.
I have no idea what this means.

Please correct me if I am wrong, Mr.JR sir.
In response to Lummox JR
Lummox JR wrote:
Um, you'll have to show some sample code here, because what you just said was impossible to follow.

Lummox JR

O.O LUMMOX JR! I thought u knew every thing *mouth hangs open*.


DragonDatum
var
atom/variableone
atom/variabletwo
proc
Procone(obj/MainObj) // This is the proc def with the main obj variable ref
variableone = MainObj // This makes variable 1 = The main obj reference
// Now how do I make variabletwo to be equal to vairableone
del(variableone) // But then variabletwo not be null after this?

proc/Main()
var/obj/MainObj = new(locate(1,1,1)) // This is the very first object variable :)
var/DragonDatum/DMAIN = new() // this is the other object housing proc's
DMAIN.Procone(MainObj) // This is the proc being passed


How is that :)
In response to Green Lime
Green Lime wrote:
Lummox JR wrote:
Um, you'll have to show some sample code here, because what you just said was impossible to follow.

Lummox JR

O.O LUMMOX JR! I thought u knew every thing *mouth hangs open*.


> DragonDatum
> var
> atom/variableone
> atom/variabletwo
> proc
> Procone(obj/MainObj) // This is the proc def with the main obj variable ref
> variableone = MainObj // This makes variable 1 = The main obj reference
> // Now how do I make variabletwo to be equal to vairableone
> del(variableone) // But then variabletwo not be null after this?
>
> proc/Main()
> var/obj/MainObj = new(locate(1,1,1)) // This is the very first object variable :)
> var/DragonDatum/DMAIN = new() // this is the other object housing proc's
> DMAIN.Procone(MainObj) // This is the proc being passed
>

How is that :)


Since variableone is an atom, when you use del() on it, it deletes the object, and sets all variables referanced to it to null (Can't reference to something that doesn't exist). IainPeregrine was right, all you need to do is change "del(variableone)" to "variableone = null".
In response to DarkCampainger
DarkCampainger wrote:
Green Lime wrote:
Lummox JR wrote:
Um, you'll have to show some sample code here, because what you just said was impossible to follow.

Lummox JR

O.O LUMMOX JR! I thought u knew every thing *mouth hangs open*.


> > DragonDatum
> > var
> > atom/variableone
> > atom/variabletwo
> > proc
> > Procone(obj/MainObj) // This is the proc def with the main obj variable ref
> > variableone = MainObj // This makes variable 1 = The main obj reference
> > // Now how do I make variabletwo to be equal to vairableone
> > del(variableone) // But then variabletwo not be null after this?
> >
> > proc/Main()
> > var/obj/MainObj = new(locate(1,1,1)) // This is the very first object variable :)
> > var/DragonDatum/DMAIN = new() // this is the other object housing proc's
> > DMAIN.Procone(MainObj) // This is the proc being passed
> >

How is that :)


Since variableone is an atom, when you use del() on it, it deletes the object, and sets all variables referanced to it to null (Can't reference to something that doesn't exist). IainPeregrine was right, all you need to do is change "del(variableone)" to "variableone = null".

But the obj will still be on the map right? Which is not what I want.
In response to Green Lime
If you delete an object, then the reference counter will null out all references to it, including 'field2' from my above post. If you just want to remove it from the map, but still have a reference to it, then you can set it's location to 'null' and variables will still point to it:
field1 = new /obj()
field1.loc = null
world << isnull(field1) //Outputs: 0