1. Hey! Guest! The 34th GMC Jam will take place between August 22nd, 12:00 UTC (Thursday noon) and August 26th, 12:00 UTC (Monday noon). Why not join in! Click here to find out more!
    Dismiss Notice

GM:S 1.4 Making a string variable different color

Discussion in 'Programming' started by Zuljaras, Feb 27, 2019.

  1. Zuljaras

    Zuljaras Member

    Joined:
    Jan 16, 2017
    Posts:
    414
    Here is the thing. I have the following code:

    Code:
    draw_text_ext(x,y,
    "Dmg: 3" + " " + string(global.compare_wep),15,280)
    I would love to set a different color for "string(global.compare_wep)".

    I have tried some things but it does not let me.

    The only solution I could find was a messy one. To have separate objects drawing the separate text variables.

    Any suggestion how this could be done with this method or others?
     
  2. Alexx

    Alexx Member

    Joined:
    Jun 21, 2016
    Posts:
    413
    Just use draw_text twice, set the colour before each.

    You can draw the second part with an offset, or use string_width to calculate this.
    If you're using such styles more than once, make a script for it. If you need an example, let me know.
     
  3. curato

    curato Member

    Joined:
    Jun 30, 2016
    Posts:
    324
    I would add it will be a lot easier to get everything to line up and match if you use a fixed font like courier.
     
  4. Zuljaras

    Zuljaras Member

    Joined:
    Jan 16, 2017
    Posts:
    414
    I could use a example.

    My code is the following:
    Code:
    draw_set_font(main_font);
    draw_set_color(c_gray);
    
    if global.weapon=1 {draw_text_ext(x,y,
    "Dmg: 3" + " " + string(global.compare_wep),15,280)}
    
    if global.weapon=2 {draw_text_ext(x,y,
    "Dmg: 6" + " " + string(global.compare_wep),15,280)}
    
    if global.weapon=3 {draw_text_ext(x,y,
    "Dmg: 12" + " " + string(global.compare_wep),15,280)}
    
    if global.weapon=4 {draw_text_ext(x,y,
    "Dmg: 10" + " " + string(global.compare_wep),15,280)}
    
    if global.weapon=5 {draw_text_ext(x,y,
    "Dmg: 8" + " " + string(global.compare_wep),15,280)}
     
    draw_set_font(-1);
    I display the stats of my weapon and when I go over other weapons I do a comparison of the power of both. I do that comparison and the result is string(global.compare_wep). I want to color this variable only as red or green. This is already done except the coloring.
    And I want to avoid overlapping both texts. With my current method when one number is longer it will expand and both will fit. If they are separate they will probably overlap if the first one gets bigger.

    I do not know if I explained it so you could understand my concerns.
     
  5. Alexx

    Alexx Member

    Joined:
    Jun 21, 2016
    Posts:
    413
    Here is a basic example:
    Code:
    ////Draw With Colour
    /*
    argument 0 = first string
    argument 1 = second sring
    argument 2 = first colour
    argument 3 = second colour
    argement 4 = x position
    arguemnt 5 = y position
    */
    draw_set_font(font_example);
    draw_set_halign(fa_left);
    draw_set_valign(fa_middle);
    draw_set_colour(argument2);
    draw_text(argument4,argument5,argument0);
    xxoffset=string_width(argument0)+font_get_size(font_example);
    draw_set_colour(argument3);
    draw_text(argument4+xxoffset,argument5,argument1);
    
    
    Example use:
    Code:
    scr_draw("Hello","World",c_red,c_green,x,y);
    
    If you want to set separation or break width, just add in two more arguments and use draw_text_ext. Though I would suggest breaking the string up yourself as needed.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice