ID:273065
 
Is there any possible way to change one object or turf into another. For example say you want a verb that changes a /obj/square into a /obj/triangle, how could you do this. Thanks in advance!
Donut_eater wrote:
Is there any possible way to change one object or turf into another. For example say you want a verb that changes a /obj/square into a /obj/triangle, how could you do this. Thanks in advance!

Not that I know of, not 'truely' anyway.

Two ideas:
One: Use obj/Shape as your shapey guy. Has a var that determines if it is a sqaure or a triangle at the time.

Two: Delete the square, replace it with a triangle. :)
In response to AJX
I was aware of these ideas. However I felt lazy and didn't want to code them and I was looking for an easier way to do this. But I have a question, can you delete a turf and replace it with another? and if anyone could answer my original question that would work to.
In response to Donut_eater
turf/proc/Replace(path)
if(ispath(path))
// If the path is valid, replace the turf with a
// turf of the new kind.
new path(src)

The problem is that, as the old turf was deleted, the new one will not be stored anywhere the old turf was stored (variables, lists, etc). This could similiarly be done for objs (replacing their variables as well), but is more problematic because objs are more likely to be stored for various reasons.
In response to Donut_eater
Donut_eater wrote:
I was aware of these ideas. However I felt lazy and didn't want to code them and I was looking for an easier way to do this. But I have a question, can you delete a turf and replace it with another? and if anyone could answer my original question that would work to.

If you delete a turf 2 things will happen:
1: The turf will be immediately replaced by the default world/turf

2: Anything ON that turf will be sent to 0,0,0

If you create a new turf at a loc 2 things will happen:
1: There can only ever be one turf on any given coordinates. Even if you create more than one on the same tile, there will only ever be one type (even if the icons are stacked) So the old one will be replaced, if you were to check the type at least.
2: If the icon is not completely opaque then the original icon will be left below the new turf.


Option 1:
var/turf/T=locate(x,y,z)
del T

Option 2:
var/turf/T=new(loc)
new /turf(loc)

Note that you can NOT do this:
var/turf/T=new
T.loc=moon

A turf's loc MUST be set at creation, and cannot be changed afterwards.
In response to AJX
So if you delete a turf, is there any possible way to assign a unique variable to the default turf that is coming in so that the turf can return to what it used to be. (i.e. If you delete a 'water' turf and is replaced by the default turf which is 'ground'. Could you keep track of the new ground so you could turn it back into water in the future?
In response to Donut_eater
Donut_eater wrote:
So if you delete a turf, is there any possible way to assign a unique variable to the default turf that is coming in so that the turf can return to what it used to be. (i.e. If you delete a 'water' turf and is replaced by the default turf which is 'ground'. Could you keep track of the new ground so you could turn it back into water in the future?

Unique variable... Don't know.

Try changing world/turf. lol. Never tried, it may be constant.
Hey guys I almost got it. Thanks a lot for the help!
In response to Donut_eater
I lied, I don't have it. How can I be able to change a turf back and forth? If no one has any ideas I guess I will just have to have variables to keep track of what it is, it might be easier.
In response to AJX
AJX wrote:
If you create a new turf at a loc [...]
2: If the icon is not completely opaque then the original icon will be left below the new turf.

That's only a special feature of the Map Editor itself, where it adds the previous turf graphic(s) into underlays. It doesn't automatically occur at runtime (when using new()), though you could of course easily do this yourself.
The replaced turf doesn't have anything extra set, just what was defined on it at compile-time (e.g. the icon and state).
BYOND's map display behavior is that any non-completely-opaque part in the turf's graphic shows through its area's graphic (if any), as it's on a lower layer by default, and any non-completely-opaque parts left in the tile after that are simply filled with black (which you of course usually want to prevent, as that would look ugly most of the time.
In response to Donut_eater
Well, surely it would involve some use of variables one way of another, but there are many ways to do it (depends on how exactly you want it to work). It boils down to keeping track of an identifier(s) of the object you want to recreate later, which could be just its type path if it doesn't have any properties that could have been changed since it was created (and you want to keep those changes). If it does, you could store them as well - which could even be by storing it in a savefile (temporary or not). Here's an example of the basic, recreate from type alone method:
turf/proc/TemporaryReplace(newType,time=100)
var/old_type = src.type //store the current type
new newType(src) //replace src with a new turf of the given type*
spawn(time)
//after a given delay, replace it back with the old type
new old_type(src)

*: Normally, when an object is deleted all running procs on it (meaning all procs that have a src equal to that object) are stopped, so the above wouldn't have worked. However, replacing turfs is an exception, and is pretty special (another word for that might be 'weird' ;P). When you replace a turf with another, even though Del() and New() are called in the process, the new turf still retains all the running procs (as well as the contents, too) the old turf had.
So, the above code would work. However, if you had modified it to do something like replace objs instead, it would need extra modifications to work properly.