B
blabluxd
Guest
Hello dear community
I really need help with this peace of code. I have a Level room where there is an Object that checks, when created, how much stars (0-3) each level has saved on the ini. Then it changes the image_index of each level button to match the amout of stars. 3 stars are yellow, 1-2 stars are blue and 0 stars are grey.
My problem is that my code is very inefficient. Right now I have six levels for testing but later on I will need a lot more. How could I make an algorithm to do the same thing in less code?
CODE:
ini_open("saveData.ini");
level1 = ini_read_real("Stars", "level1", 0);
level2 = ini_read_real("Stars", "level2", 0);
level3 = ini_read_real("Stars", "level3", 0);
level4 = ini_read_real("Stars", "level4", 0);
level5 = ini_read_real("Stars", "level5", 0);
level6 = ini_read_real("Stars", "level6", 0);
global.coins = ini_read_real("Player", "Coins", 0);
ini_close();
if (level1 > 0 and level1 <3)
{
with (obj_level1) image_index = 1;
} else if (level1 == 3)
{
with(obj_level1) image_index = 0;
}
if (level2 > 0 and level2 <3)
{
with (obj_level2) image_index = 1;
} else if (level2 == 3)
{
with(obj_level2) image_index = 0;
}
I maybe thought of doing it with a repeat but it didnt work:
var i = 0;
var level = "level"+string(i);
repeat(6)
{
i += 1;
if (level+string(i) > 0 and level+string(i))
{
with (obj_level+string(i)) image_index = 1;
}
}
etc.....
but it didnt work now Im askig you if you could help me creating such an algorithm like I tried correctly? Because I dont know how
Thank you very much
I really need help with this peace of code. I have a Level room where there is an Object that checks, when created, how much stars (0-3) each level has saved on the ini. Then it changes the image_index of each level button to match the amout of stars. 3 stars are yellow, 1-2 stars are blue and 0 stars are grey.
My problem is that my code is very inefficient. Right now I have six levels for testing but later on I will need a lot more. How could I make an algorithm to do the same thing in less code?
CODE:
ini_open("saveData.ini");
level1 = ini_read_real("Stars", "level1", 0);
level2 = ini_read_real("Stars", "level2", 0);
level3 = ini_read_real("Stars", "level3", 0);
level4 = ini_read_real("Stars", "level4", 0);
level5 = ini_read_real("Stars", "level5", 0);
level6 = ini_read_real("Stars", "level6", 0);
global.coins = ini_read_real("Player", "Coins", 0);
ini_close();
if (level1 > 0 and level1 <3)
{
with (obj_level1) image_index = 1;
} else if (level1 == 3)
{
with(obj_level1) image_index = 0;
}
if (level2 > 0 and level2 <3)
{
with (obj_level2) image_index = 1;
} else if (level2 == 3)
{
with(obj_level2) image_index = 0;
}
I maybe thought of doing it with a repeat but it didnt work:
var i = 0;
var level = "level"+string(i);
repeat(6)
{
i += 1;
if (level+string(i) > 0 and level+string(i))
{
with (obj_level+string(i)) image_index = 1;
}
}
etc.....
but it didnt work now Im askig you if you could help me creating such an algorithm like I tried correctly? Because I dont know how
Thank you very much