• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GML Signpost moves hud variables around

BlueBot5000

Member
As i finally finish signposts for my game (here is the video i was learning from)


i was stumbled with only 1 HUGE problem some of my text hud variables move...EVERY SINGLE TIME...and it doesn't please me i tried finding the problem for 1 day and a half
maybe some variables were being shared it didn't seem like it maybe some LOCAL variables were being shared that still didn't seem like it maybe global variables were doing something!?

this problem has been driving me CRAZY some help WOULD BE VEEERRRYYY HELPFUL

objDataController (this carry's the players score and how much air they have left for underwater exploration)

CREATE EVENT
Code:
/// @description Keep Control of Variables

draw_set_color(c_black);
draw_set_font(SCORE_FONT);

global.Score = 0;

global.HP = 100;
global.HPmax = global.HP;

healthbar_width = 248;
healthbar_height = 36;
healthbar_x = x - 77;
healthbar_y = y - 400;
DRAW GUI
Code:
/// @description Health Bar + Score

if instance_exists(entityPlayer)
{
{
draw_sprite(sprHealthBarBaraka,0,88,50);
draw_sprite_stretched(sprHealthBarBaraka,0,88,50,(global.HP/global.HPmax) * healthbar_width,healthbar_height);
draw_sprite(sprHealthBarBorder,0,88,50);
}

draw_rectangle_color(0,108,258,133,c_black,c_black,c_black,c_black,false);

draw_set_font(SCORE_FONT);

//draw_text_outlined(x, y, outline color, string color, string)
var xx,yy;

xx = 254;
yy = 150;

//Outline
draw_set_color(c_black);
draw_text(xx+1,yy+1,string(global.Score));
draw_text(xx-1,yy-1,string(global.Score));
draw_text(xx,yy+1,string(global.Score));
draw_text(xx+1,yy,string(global.Score));
draw_text(xx,yy-1,string(global.Score));
draw_text(xx-1,yy,string(global.Score));
draw_text(xx-1,yy+1,string(global.Score));
draw_text(xx+1,yy-1,string(global.Score));
 
//Text 
draw_set_color(c_white);
draw_text(xx,yy,string(global.Score));
}
PRESS R EVENT
Code:
//Just Guess What This Does It's Just WWAAYYY Too Obvious
objText

CREATE EVENT
Code:
/// @description Variables

spd = 0.25;
letters = 0;
text = "IF YOU LOOK TO YOUR LEFT YOU CAN SEE\n WATER TO YOUR FAR RIGHT YOU\n WILL FIND A SIGN!";
length = string_length(text);
text_current = "";
w = 0;
h = 0;
border = 10;
STEP EVENT
Code:
/// @description Progress Text

letters += spd;
text_current = string_copy(text,1,(letters));

draw_set_font(SIGN_FONT);
if (h == 0) h = string_height(text);
w = string_width(text_current);

//Destory When Done
if (letters >= length) && (keyboard_check_pressed(vk_up))
{
    instance_destroy();
    with (objCamera) follow = entityPlayer;
}
DRAW EVENT
Code:
/// @description Draw Our Text And Speech Box's

var halfw = w * 0.5;

//Draw The Box
draw_set_color(c_black);
draw_set_alpha(0.5);
draw_roundrect_ext(x-halfw-border,y-h-(border*2),x+halfw+border,y,15,15,false);
draw_sprite(sprSignMarker,0,x,y);
draw_set_alpha(1);

//Draw Text
DrawSetText(c_white,SIGN_FONT,fa_center,fa_top);
draw_text(x,y-h-border,text_current);
DrawSetText THE FUNCTION!
Code:
function DrawSetText()
{
/// @desc DrawSetText(colour,font,halign,valign)
/// @arg colour
/// @arg font
/// @arg halign
/// @arg valign


// Allows one line setup of major text drawing vars.
// Requiring all prevents silly coders from forgetting one
// And therefore creating a dumb dependency on other event calls.
// (Then wondering why their text changes later in development.)


draw_set_colour(argument0);
draw_set_font(argument1);
draw_set_halign(argument2);
draw_set_valign(argument3);
}
 
All that information and all we really have to go off of is "it moves". I'm guessing that your hud relies on text being aligned from the left, but you center the alignment without ever resetting it.
 

BlueBot5000

Member
Top Left and when i say "it moves" it mean it changes it's y postion immediately and x a tiny bit probably by 2 pixel's to the right and i wanted to make sure i would've shown anyone enough code to go off of
could you show me your solution in code i'm just worried i might have to scrap the signpost and text object...
 

Nidoking

Member
You've got your solution in code right there. You wrote a function to set all of the text drawing attributes, and then you don't use it most of the time. Use that function every time instead of just the once, and the problem will probably go away on its own.
 

Yal

šŸ§ *penguin noises*
GMC Elder
If you change the text's font or alignment in the textbox code, but not in the GUI code, make sure to change it back afterwards.
 

BlueBot5000

Member
You've got your solution in code right there. You wrote a function to set all of the text drawing attributes, and then you don't use it most of the time. Use that function every time instead of just the once, and the problem will probably go away on its own.
I didn't write that function i saw it in the tutorial i was watching and i'm actually trying to keep the outline of the objDataController's HUD text the function doesn't have outlines in it

to put it simply:
Do i add outlines to the function so objDataController can use it, do i keep to objText? and if so what should i be editing i don't mean to be rude but i don't know what a center alignment is are you talking about the sprite center alignment? because it has no sprite and the Text is already a diffrent font objText uses ProtoPixel1 and objDataController has Born2bSportyv2 to be exact
 

TailBit

Member
Try add draw_set_halign(fa_left); after you have drawn text_current..

You can check what it does in the help file >here< .. it could really mess things up if you don't put it back to the default after use x3
 
Top