Jump to content


Photo

How do I change a string value into a color?


  • Please log in to reply
9 replies to this topic

#1 xXNeoREXx

xXNeoREXx

    GMC Member

  • GMC Member
  • 41 posts
  • Version:GM8.1

Posted 11 April 2012 - 08:28 AM

I have made a splitting string ("c_red|c_black|c_blue").
The split array script will split it into 3 arrays...
But the problem is that the values are strings and not colors...
how can I convert them into color constants? (the real from string doesn't work)

Many thanks.
  • 0

#2 Chronic

Chronic

    Administrator

  • Global Moderators
  • 2713 posts
  • Version:GM:Studio

Posted 11 April 2012 - 08:32 AM

Not 100% sure of your question, but i think you're probably looking for make_color_rgb() or make_color_hsv()
  • 0

#3 xXNeoREXx

xXNeoREXx

    GMC Member

  • GMC Member
  • 41 posts
  • Version:GM8.1

Posted 11 April 2012 - 09:22 AM

Not 100% sure of your question, but i think you're probably looking for make_color_rgb() or make_color_hsv()

make_color functions create color database depending on 3 colors (red,blue,green) and then create another combined color.
Game maker has precombined colors like c_red for example that already has the rgb combination.
I have a string precombined color "c_red" and I want the system to recognize it and use it as a regular c_red.

This question can be applied to a lot of constant types, like sprites, sounds and objects.
meaning, you have a sprite name in a string and you want it to be recognized as a image name.
  • 0

#4 jo-thijs

jo-thijs

    GMC Member

  • GMC Member
  • 1455 posts
  • Version:GM8.1

Posted 11 April 2012 - 11:14 AM

found a way, use this code:
string_execute("return "+color_string);
  • 1

#5 xXNeoREXx

xXNeoREXx

    GMC Member

  • GMC Member
  • 41 posts
  • Version:GM8.1

Posted 11 April 2012 - 05:40 PM

found a way, use this code:
string_execute("return "+color_string);

THANKS MAN<!
Worked wonderfully, I never thought about using execute_string.

And yeah, its execute_string and not string_execute...
I used it like this: execute_string("return "+color[0]);

Many thanks.
  • 0

#6 xXNeoREXx

xXNeoREXx

    GMC Member

  • GMC Member
  • 41 posts
  • Version:GM8.1

Posted 24 April 2012 - 04:51 PM

found a way, use this code:
string_execute("return "+color_string);


[Reopening Topic]
is there a way to do this without using "string_execute"?
because that particular function was scrapped for being "obsolete" in Game Maker Studio+
  • 0

#7 icuurd12b42

icuurd12b42

    Self Formed Sentient

  • Global Moderators
  • 14385 posts
  • Version:GM:Studio

Posted 24 April 2012 - 06:15 PM

make a ds_map and add all your constants in it

colors = ds_map_create();
//fill with string and actual values
ds_map_add(colors,"c_white",c_white);
ds_map_add(colors,"c_red",c_red);
...

to get the color

ds_map_find_value(colors,"c_white")
  • 1

#8 jo-thijs

jo-thijs

    GMC Member

  • GMC Member
  • 1455 posts
  • Version:GM8.1

Posted 24 April 2012 - 06:18 PM

I guess it would be better then to use:
if strcolor=="c_white"
rlcolor=c_white;else
if strcolor=="c_black"
rlcolor=c_black;else
...
  • 0

#9 xXNeoREXx

xXNeoREXx

    GMC Member

  • GMC Member
  • 41 posts
  • Version:GM8.1

Posted 26 April 2012 - 07:23 AM

make a ds_map and add all your constants in it

colors = ds_map_create();
//fill with string and actual values
ds_map_add(colors,"c_white",c_white);
ds_map_add(colors,"c_red",c_red);
...

to get the color

ds_map_find_value(colors,"c_white")


I think its a good way to do it, although I never used ds_map functions.
I'll give it a try, many thanks.

I guess it would be better then to use:
if strcolor=="c_white"
rlcolor=c_white;else
if strcolor=="c_black"
rlcolor=c_black;else
...


Its a good way to go also, It does give a quicker solution, it is probably better than creating an entire database of colors like the ds_map.

Both of the ways are suitable and ill try them both, many thanks.

Edited by xXNeoREXx, 26 April 2012 - 07:28 AM.

  • 0

#10 icuurd12b42

icuurd12b42

    Self Formed Sentient

  • Global Moderators
  • 14385 posts
  • Version:GM:Studio

Posted 26 April 2012 - 07:52 AM

you can also make a huge case statement.
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users