How do I change a string value into a color?
#1
Posted 11 April 2012 - 08:28 AM
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.
#2
Posted 11 April 2012 - 08:32 AM
#3
Posted 11 April 2012 - 09:22 AM
make_color functions create color database depending on 3 colors (red,blue,green) and then create another combined color.Not 100% sure of your question, but i think you're probably looking for make_color_rgb() or make_color_hsv()
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.
#4
Posted 11 April 2012 - 11:14 AM
string_execute("return "+color_string);
#5
Posted 11 April 2012 - 05:40 PM
THANKS MAN<!found a way, use this code:
string_execute("return "+color_string);
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.
#6
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+
#7
Posted 24 April 2012 - 06:15 PM
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")
#8
Posted 24 April 2012 - 06:18 PM
if strcolor=="c_white"
rlcolor=c_white;else
if strcolor=="c_black"
rlcolor=c_black;else
...
#9
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.
#10
Posted 26 April 2012 - 07:52 AM
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users











