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

"for" doesn't seem to work for me pls help

M

m4meteor

Guest
I am trying to do a system that detects the largest string in an array so that I can calculate the width of my menu. (if i have an obvious mistake pls don't bully im new)

Code:
menu[2] = "New Game"
menu[1] = "Continue"
menu[0] = "Quit"

// Find the largest string in the array to calculate width of menu.
var largest_string = ""
for (var str_n = 0; str_n > array_length_1d(menu); str_n = str_n + 1)
{
    if string_length(menu[str_n]) > string_length(largest_string)
    {
        menu[str_n] = largest_string
    }
}

draw_set_font(fnt_menu)
menu_width = string_length(largest_string)+(gui_margin * 2)
It doesn't seem to work as menu_width gives out a value of gui_margin*2 (which is 100).

This code is placed in the create event.
 

TsukaYuriko

☄️
Forum Staff
Moderator
Re-check your signs. (< vs. >)
The loop isn't running because you're instantly canceling it out.
 
M

m4meteor

Guest
Re-check your signs. (< vs. >)
The loop isn't running because you're instantly canceling it out.
I don't understand how i am instantly cancelling it out if I set str_n to be 0 and 0 < 3(array length)
 

TsukaYuriko

☄️
Forum Staff
Moderator
You're checking whether 0 is greater than 3. The condition is for continuing, not for breaking out. 0 is not greater than 3, so it instantly ends.
 
Top