• 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!

How to check if a string has been drawn at a certain place already?

Godelinde

Member
Dear community,

How can I let the program check if a string (not a specific one) has been drawn at a certain position in my game room?
If a string has been drawn on 'position 1' I want the next string to be drawn at 'position 2' etc.

Thanks in advance for your time and effort.
 

NightFrost

Member
Since you need to draw the strings every step, you would be storing their draw positions somewhere, for example an array. When you need to add another string, you'd loop through this storage and check whether the position is in use already. Of course, if the strings are positioned through some linear formula, for example their y-position steps 20 pixels every time starting from some specific position, you only need to know how many strings there are already. If there are for example four strings being displayed and yo need to add fifth, you can calculate where it should be positioned.
 

Godelinde

Member
Thanks so much for your reply @NightFrost.
In my case it's the latter (a linear formula). But I don't really know how to count the nummer of strings.

At the moment I have this bit of code in my 'draw event' but it doesn't work.
What would be a better (more elegant) way to go about this?:

var string_number = 0
var yy = (140 + (string_number*100))

if(draw_text_transformed(
xx,
yy,
Fact_1,
1,
1,
356))
{string_number =+1}
 

saffeine

Member
could you not just do something like one of the following?

GML:
for( var i=0; i<string_number; i++ ){
    var _xx        = 32;
    var _yy        = 140 + ( i * 100 );
    var _text = "";
 
    switch( i ){
        case 0: _text = Fact_1; break;
        case 1: _text = Fact_2; break;
        /* etc */
    }
 
    draw_text_transformed( _xx, _yy, _text, 1, 1, 356 );
}
GML:
var _xx        = 32;
var _yy        = 140;

draw_text_transformed( _xx, _yy, Fact_1, 1, 1, 356 ); _yy += 100;
draw_text_transformed( _xx, _yy, Fact_2, 1, 1, 356 ); _yy += 100;
/* etc */
the former is a lot more elegant if you store the values into an array instead and refer to those using i as the index, but both should work.

on an added note, your code probably isn't working because { string_number=+1 } is not the same as { string_number+=1 }.
the first will set it to a positive 1, the second will add 1 to the current value.
on top of that, i'm not sure if there's any functionality with using the draw_text_transformed function inside a statement like that.
 
Last edited:

Godelinde

Member
As you might have guessed I'm very new tot GMS and its community but in a short time I'm simply astounded by all the helpful people here.
Thank you very much @saffeine. Not only is this a working solution to my problem, I'm also learning a lot from it.

Hope you have a wonderful day.
 
Top