GameMaker: Studio

GameMaker: Studio

View Stats:
Lemur Dec 15, 2014 @ 11:51am
Text doesn't want to be drawn together
I'm trying to draw a text showing on which level of the game the player is. Variable "lvl"(on 1st level it equals 0, that's why I add 1 later on) is stored in object "obj_enemygen". I want it to draw for example: "Level: 1".

Here's the line of code I wanted to use for this:

draw_text(5,5, "Level: " + (obj_enemygen.lvl+1));

But when I get to point when it should be drawn, I get this error:
http://scr.hu/397x/7awn6

Drawing itself works, it can draw both "Level: " and "(obj_enemygen.lvl+1)" separately, it just won't draw it together.

Does any of you know why this might be happening and how to fix it?
< >
Showing 1-4 of 4 comments
Thew Dec 15, 2014 @ 11:57am 
You're trying to draw a numeric variable while the "draw_text" function is expecting a string. You can easily convert the number to a string like so:
draw_text(5,5, "Level: " + string(obj_enemygen.lvl+1));

Edit: And I should add that it works when you separate them because gamemaker does the conversion automatically. But when you use a "+" to concatenate strings, each section -must- be a string.
Last edited by Thew; Dec 15, 2014 @ 12:00pm
Lemur Dec 15, 2014 @ 12:00pm 
Thanks for fast response, works great :)
Lemur Dec 17, 2014 @ 9:38am 
One question though, why does it work when I want to write numeric variable only?
Thew Dec 17, 2014 @ 10:28am 
I actually edited my original comment with the answer to that a few minutes after I posted it on Monday. It should be noted that most programming languages DO NOT convert variables automatically, so it's an important concept to be aware of for future projects.
< >
Showing 1-4 of 4 comments
Per page: 1530 50

Date Posted: Dec 15, 2014 @ 11:51am
Posts: 4