ID:262280
 
Code:
mob
icon = 'player.dmi'
turf
grass
icon = 'grass.dmi'
mob/verb/swapcolor()
switch(alert("what color do you want",,"red","blue"))
if("red")
I.SwapColor(rgb(255,255,255),rgb(255,0,0))
if("blue")
I.SwapColor(rgb(255,255,255),rgb(0,0,255))


var/icon/I


What am i doing wrong it compiles but i get runtime errors

I'd be willing to bet you never initialized a proper icon object.

try putting this above your switch statement:

I = icon('player.dmi')


then below the switch, put this:

src.icon = I
In response to Ter13
i just started coding. thanks
In response to The Black Dragon
No problem, don't quit.
In response to Ter13
im having trouble getting it to work, can you please show me.
In response to The Black Dragon
mob/verb/swapcolor()
var/icon/I = icon('player.dmi')
switch(alert("what color do you want",,"red","blue"))
if("red")
I.SwapColor(rgb(255,255,255),rgb(255,0,0))
if("blue")
I.SwapColor(rgb(255,255,255),rgb(0,0,255))
src.icon = I
In response to Ter13
I myself think switch(alert is ok, but i perfer the imput list style becasue u can get more than 3 colors on the list lol, so i would use this.

I tested it out so i know it works fine. and i added a couple more to the list
mob/verb/Change_Color()
set name="Change Color"
set desc="Change your character's color"
var/icon/I = icon('player.dmi')
switch(input("what color do you want","Color?")in list("White","Black","Red","Blue"))
if("White")
I.SwapColor(rgb(255,255,255),rgb(255,255,255))
if("Black")
I.SwapColor(rgb(255,255,255),rgb(0,0,0))
if("Red")
I.SwapColor(rgb(255,255,255),rgb(255,0,0))
if("Blue")
I.SwapColor(rgb(255,255,255),rgb(0,0,255))
src.icon = I
In response to ElderKain
Since he has only two teams, I think it's okay.
In response to Ter13
Ter13 wrote:
Since he has only two teams, I think it's okay.
well i didn't know that it was for teams *I just figured it was like for one of thoes DBZ games, lol i have heard people ask similar questions before like, "How do i get my hair to change color without having to make an extra icon for the color for my DBZ character hair color choice." lol well i might be reading into things too much, lol I like to help out now and them and sometimes my mind goes off topic, lol. well i'm rambling right now, so peace out ^.^
In response to ElderKain
ok i have another problem. I made 2 swapcolor verbs one for changing clothes color and another for changing accessroies color. here is the code.

turf
grass
icon = 'grass.dmi'
mob/verb/Change_Clothes_Color()
set desc = "Swap Color"

var/icon/I = icon('Sage.dmi')
switch(input("What color do you want","Swap Color") in list("Red","Green","Blue","Black","White","Purple","Orange","Brown","Grey","Yellow"))
if("Red")
I.SwapColor(rgb(255,255,255),rgb(255,0,0))
if("Green")
I.SwapColor(rgb(255,255,255),rgb(0,255,0))
if("Blue")
I.SwapColor(rgb(255,255,255),rgb(0,0,255))
if("Black")
I.SwapColor(rgb(255,255,255),rgb(0,0,0))
if("White")
I.SwapColor(rgb(255,255,255),rgb(255,255,255))
if("Purple")
I.SwapColor(rgb(255,255,255),rgb(102,0,102))
if("Orange")
I.SwapColor(rgb(255,255,255),rgb(255,127,0))
if("Brown")
I.SwapColor(rgb(255,255,255),rgb(102,51,0))
if("Grey")
I.SwapColor(rgb(255,255,255),rgb(125,125,125))
if("Yellow")
I.SwapColor(rgb(255,255,255),rgb(255,255,0))
src.icon = I
mob
icon = 'Sage.dmi'

mob/verb/Change_Accessories_Color()
set desc = "Swap Color"

var/icon/I = icon('Sage.dmi')
switch(input("What color do you want","Swap Color") in list("Red","Green","Blue","Black","White","Purple","Orange","Brown","Grey","Yellow"))
if("Red")
I.SwapColor(rgb(0,171,71),rgb(255,0,0))
if("Green")
I.SwapColor(rgb(0,171,71),rgb(0,255,0))
if("Blue")
I.SwapColor(rgb(0,171,71),rgb(0,0,255))
if("Black")
I.SwapColor(rgb(0,171,71),rgb(0,0,0))
if("White")
I.SwapColor(rgb(0,171,71),rgb(255,255,255))
if("Purple")
I.SwapColor(rgb(0,171,71),rgb(102,0,102))
if("Orange")
I.SwapColor(rgb(0,171,71),rgb(255,127,0))
if("Brown")
I.SwapColor(rgb(0,171,71),rgb(102,51,0))
if("Grey")
I.SwapColor(rgb(0,171,71),rgb(125,125,125))
if("Yellow")
I.SwapColor(rgb(0,171,71),rgb(255,255,0))
src.icon = I



The problem is that when i use clothes the accessroies go back to the original color. Can someone help me.
In response to The Black Dragon
Think about it. You are setting the player's icon to a new icon object in both. You are never switching both in one procedure, just seperately.

mob
var
clothing_color
accessory_color
verb
change_clothing_color()
var/list/colors = list("red"=rgb(255,0,0),"Green"=rgb(0,255,0))
src.clothing_color = colors[input("Clothing color?","clothes") in colors]
seticon()
//do the same under accessory color.
proc
seticon()
var/icon/I = icon('Sage.dmi')
I.SwapColor(rgb(255,255,255),src.clothing_color)
I.SwapColor(rgb(0,171,71),src.accessory_color)
src.icon = I


Enjoy!
I have a suggestion to add. Since you're doing this for character customization, save the color choice for each part of the icon as a string, like clothes_color="#f00" for red, accessory_color="#ff0" for yellow. Then when you load the character you can redo this customization easily, and you never have to save the icon (which leads to large savefiles). And all you need to expand your list of colors easily is an associative list.

var/colorlist = list(\
"Red" = "#f00",
"Green" = "#0f0",
"Blue" = "#00f",
"Black" = "#000",
"White" = "#fff",
"Purple" = "#660066",
"Orange" = "#ff7f00",
"Brown" = "#663300",
"Grey" = "#7d7d7d",
"Yellow" = "#ff0")

mob/proc/Choose_Color()
if(!client) return
var/cc,ac
cc = input(src, "What clothing color do you want?","Clothes Color") as null|anything in colorlist
if(!cc || !client) return
ac = input(src, "What accessory color do you want?","Accessory Color") as null|anything in colorlist
if(!ac || !client) return
clothes_color = colorlist[cc]
accessory_color = colorlist[ac]
BuildIcon()

mob/proc/BuildIcon()
var/icon/I = new('player.dmi')
I.SwapColor("#fff",clothes_color)
I.SwapColor("#00ab47",accessory_color)
icon = I


This code is much cleaner, much easier to expand, and even lets you avoid huge savefiles by never having to save the icon.

Lummox JR
In response to Lummox JR
thanks.
Does anybody know how to let me select them at login. So when I login i can pick either clothes or accessories then choose the colors. And is it possible to set an R,G,B var as the old color so i can use it with different icons.
In response to Lummox JR
Lummox JR wrote:
mob/proc/BuildIcon()
var/icon/I = new('player.dmi')
I.SwapColor("#fff",clothes_color)
I.SwapColor("#00ab47",accessory_color)
icon = I</dm>

This code is much cleaner, much easier to expand, and even lets you avoid huge savefiles by never having to save the icon.

Lummox JR

Don't you have to be specific when using swap color?
I.SwapColor("#fff",clothes_color) that's doing "#fff".
rgb(253,253,253) wouldn't = "#fff"
In response to Zaltron
In DM, "#fff" is shorthand for "#ffffff", which is rgb(255,255,255). Note that it doesn't work in ordinary HTML; just in BYOND.