I'm sure this has been asked before, and I appologize if it has, but I need to know, how do you change all of a certain turf into another? Like make a grass turf become a snow turf.
Thanks for the help,
Mike
ID:165509
Dec 11 2006, 5:14 pm
|
|
Dec 11 2006, 5:18 pm (Edited on Dec 12 2006, 10:24 am)
|
|
It's not actually very hard. Only one turf can inhabit a location at one time, so making a new one in that location will delete the previous one. Just do something like this:
|
In response to Popisfizzy
|
|
I see.. One thing I have to admit, is that I am a "newbie" coder. I don't have any large amount of experience with it. But from what I can tell, I replace turf_type with the name of the current turf I want to replace, the if(!turf_type)) return statement, I don't really understand. Nor the turf_type = text2path("[turf_type]") statement. I believe that if(turf_type) new turf_type(locate(x,y,z)) is saying if it is a certain turf, replace it with a new turf?
Please reply with an explanation of how it works, I like to fully understand the code I'm using. Thanks. |
In response to Michael3131
|
|
The if(!turf_type) part checks to see if turf_type is a false value ("", null, or 0). This is just to minimize processing (under normal conditions, it won't really be noticeable, but can make a difference if this is being called a lot.
The turf_type = text2path(turf_type) converts the string specified by the turf_type argument (as defined in those parantheses as the top), into a type path (a string like "/turf/grass" actually becomes somthing useable). The following if statement, if(turf_type), checks to see if it's a true value (anything not the three values above). Now, if it's a true value, we can be sure it's a valid type path because text2path will return a false value if it's not a valid type path. Finally, new type_path(locate(x,y,z)) will create the new turf in the old turf's location. |
In response to Michael3131
|
|
This may be a bit dense - just warning you.
This is a turf procedure. That is, you call 'some_turf.convert_turf(typepath)' to change some_turf into a turf of type typepath. It has some safety checks built into it. First off, the line if(!turf_type) return (There's an extra unneeded bracket in the actual snippet I've removed). Every value in DM is considered one of two things - 'true', or 'false'. 0, "" (An empty string) and null (The value all variables have unless you initialise them) are all false. Everything else is true. If you call if(some_variable), and that variable is a 'false' value - 0, "", or null - then the code under the if won't get executed. If you call if(some_variable) and some_variable is a 'true' variable, the if goes through. ! is a logical operator, like && or ||. && returns true if the two arguments on either side are true. || returns true if one of the arguments on either side are true. ! takes one value, and returns true if that value is false. That is: !0 = 1 !1 = 0 if(!turf_type) will go through if turf_type is false - that is, if the procedure is passed the value 0, "", or null, it will bail out. That's to make sure it doesn't throw a runtime if you pass a bad value to it. turf_type = text2path("[turf_type]") //This converts the text string into a type path As the comment says, this converts a text string into a type path. A string like "/turf/grass" is a type path to you - but DM just sees a string. Calling new "/turf/grass" will return a runtime error. text2path("/turf/grass") returns /turf/grass - so that line just makes sure that it's a type path you're getting. if(turf_type) new turf_type(locate(x,y,z)) //If it's an actual path, create it on that previous location. I think that's a bit iffy - I would go with if(ispath(turf_type)) new turf_type(src) The if() simply checks whether the text passed to it was a typepath - my version does the exact same thing, it's just that I think if(ispath(turf_type)) is more readable. Either will do. The next code simply creates a new turf at the turf the procedure has been called on. So, for a rough idea of how to call it: mob/verb/make_snow(turf/t in view()) That assumes you've got a type path '/turf/snow'. It will allow mobs to select a turf that they can see and turn it into a snow turf. |
In response to Popisfizzy
|
|
Wow. Thanks for helping me out. I'll fill it in and I'd appreciate it if you told me if i did it right:
turf/proc/convert_turf(Grass) if(!Grass)) return turf_type = text2path("/turfs/Grass") if(Grass) new Snow(locate(x,y,z)) I don't believe I got it correct, but I honestly tried. Ah, I just saw your post JP. Reading now. I see, I changed my coding a tad bit. |