ID:269717
 
Is there any short-hand way to make it so that, say an item can come in 3 different designs, but it's the same item so it will use the same code?

obj/items
red_swirl_painting
icon_state = "redswirl"
Click()
if(usr.artlevel < 1)
usr<<"You admire the painting, and get some artistic inspiration from it!"
usr.artlevel += 1
else
usr<<"You admire the painting, but get no inspiration."


This is just a sample code I typed up, what if I wanted to have a triangle and an abstract painting with the same Click() coding but different icons? Would I have to copy and paste it, or is there an easier way?
maybe rgb :).

O-matic
In response to O-matic
Well that was an example, it happened to work out that way. I'll edit the post to make it so that I want the paintings to have different designs, not colors.
You could use something like this:

obj/items
painting
Click()
if(usr.artlevel < 1)
usr<<"You admire the painting, and get some artistic inspiration from it!"
usr.artlevel += 1
else
usr<<"You admire the painting, but get no inspiration."
red_swirl_painting
icon_state = "redswirl"
blue_clow_painting
icon_state = "blueclow"
landscape_painting
icon_state = "landscape"


This creates 3 separate objects that are all of the type obj/items/painting, and all inherit the "Click()" proc from their parent. Alternatively, you could achieve a similar affect by using your existing code, and changing the icon_state of the objects from within the map editor.
In response to Igmolicious
Ah, I get it now. At the time I forgot about or didn't want to create a new 'type' such as obj/items/paintings, but now I see that this is the best and easiest way to do it. Thanks for your help, guys.

Igmolicious, I was also thinking about editing the icon_state in the map editor. This is only a "quick-fix" though, and if I wanted to use more than one of them I would have to keep changing the icon_states.
This is a simple matter of inheritance. Easy as pie.

obj/items
painting
var/artlevel
Click()
if(parent_type != /obj/items/painting) CRASH("cannot view stock /painting")
usr << "You admire the painting \..."
if(usr.artlevel < src.artlevel)
usr<<"and get some artistic inspiration from it!"
usr.artlevel = src.artlevel //changed this so you click once and you're done.
else
usr<<"but get no inspiration."
//children of /obj/items/painting inherit its characteristics
redswirl {icon_state="redswirl";name="red swirl";artlevel=1}
triangle {icon_state="triangle";artlevel=1.5} //ooh! a higher art level.
abstract {icon_state="abstract";artlevel=2} //a very inspiring painting in deed


I took a little artistic license with that code (pun intended!), but that's mostly to show you how inheritance works.
In response to PirateHead
I like what you did with it, PirateHead, it is a very good example and i'll keep it in mind. Just for your information, I wasn't really coding paintings. I was coding tables, and paintings are more interesting than tables.

I also used that as an example, because the coding for the game has stuff you wouldn't need to answer the question. The coding calls lots of pre-coded procs and such, which would probably confuse people if I posted it here, because my question isn't about that.