ID:155928
 
Hello,

I've recently started on a project again which i am currently gonna work on every now and then when i've got time.

I am wondering if there is a way to make a general path for an object so that only the "last part" needs to be changed?

To elaborate:

I'm making an RPG, in this rpg you will be able to mine resources off of rocks.

Right now the whole mining aspects of the rocks are universal, with this i mean that i do not have a verb/Mine() for every type of rock. but one under the general /rock section. :
turf/Rocks
verb/Mine()
if(!src.active)
return
else
if(usr.mining >= (src.level * 10))
// and so on
if(prob(success))
usr.contents += new/obj/minerals/Clay // as an example
Clay

Iron

//etc..


Now there's a chance of getting the minerals of the rock, when you manage to do so, i made, as you can see above. that bit of code.. maybe i should make a seperate proc handle it. please comment on that too if you want.

But what i really wonder is if there is a way to make the end of the path.. in the above example named Clay changable or something dymanic. like [src.name] so the result would be:
new/obj/minerals/Clay // when mining on a clay rock

new/obj/minerals/Iron // when mining on an iron rock

etc..


Is there a way to do this?

I think that the istype() proc is what you're looking for.
http://www.byond.com/ members/?command=reference&path=proc%2Fistype
In response to Raimo
hahaha! beautifully simple! That's what i was looking for, thanks :)
You have two main options. One is more restrictive but more self-managing, and the other is more versatile but requires a bit more data entry.

The first option is to set up your mineral object paths so that they can be dynamically generated based on the name of the rock turf. For example, if your rock is named "Clay", it should give "/obj/minerals/Clay". You can create a path at runtime from a text string by using the text2path() process.

So here's how you would create the resulting mineral from a successful mining:
// Attempt to construct a path based on the rock's name
var/mineral = text2path("/obj/minerals/[name]")
if(mineral)
// Create a new object of the type stored in mineral
usr.contents += new mineral()
else
// Some basic error checking in case things get unsynced name-wise
world.log << "WARNING: Rock [name] does not have a matching mineral type!"



The other option is to simply store the path of the resulting mineral in a variable of turf/Rocks'. Then instead of constructing it with text2path(), we can just create it directly. It means the names no longer need to strictly match up, but it also means you have to manually type out all of the paths for the rocks.

turf/Rocks
// Define the variable that will hold the mineral type, and give it a default value
var/mineralType = /obj/minerals/Stone

Clay
mineralType = /obj/minerals/Clay
Iron
mineralType = /obj/minerals/Iron

// ...

if(mineralType )
// Create a new object of the type stored in mineralType
usr.contents += new mineralType()


But if you plan on setting up the paths so that their names match anyway, there's no real reason to do the extra work :)
In response to Narutostory
Any time, mate.
In response to DarkCampainger
i was abit hasty with the istype() stuff, and when trying to implement it noticed it wasn't what i was looking for after all.

You're methods are more along what i was looking for, and it works great, so thank you.

decided to use the text2path version. which was what i was looking for, even searched "path" in F1 to find something related to paths but didn't think of extending the search and stopped at path operators which didn't give me anything.

anyways :) thank you :)