Do...Until Not?
#1
Posted 06 April 2012 - 12:38 AM
it kind of looks like this:
ini_open("gxy_setup.ini");
a = 0;
do
{star = instance_create(x,y,obj_star);
star.star_adr = ini_read_string("star_adr","star"+string(a),"error");
if star.star_adr == "error"
{a+=1;
do
{star.star_adr = ini_read_string("star_adr","star"+string(a),"error");
a+=1;}
until(star.star_adr!="error");}
a+=1;}
until(a == star_count);
Everything works fine until I added the 2nd do...until in there. My question is how do you use do{something} until(something does not = something)? Did I place the exclamation point in the wrong area? It didn't give me an error. Instead, it went into a never-ending loop, freezing the application. I hope to have an answer soon. Thanks in advance.
#2
Posted 06 April 2012 - 12:53 AM
#3
Posted 06 April 2012 - 12:53 AM
#4
Posted 06 April 2012 - 01:03 AM
#5
Posted 06 April 2012 - 01:18 AM
Create Event:
__________________________________________________________________
ini_open("gxy_setup.ini");
star_count = ini_read_real("main","star_count",1);
i = 0;
do
{star = instance_create(x,y,obj_star);
star.star_adr = ini_read_string("star_adr","star"+string(i),"error");
if star.star_adr == "error"
{i+=1;
do
{star.star_adr = ini_read_string("star_adr","star"+string(i),"error");
i+=1;}
until(star.star_adr != "error");}
i+=1;}
until(i == star_count);
__________________________________________________________________
"gxy_setup.ini":
__________________________________________________________________
[main]
star_count=8
[star_adr]
star0="save/Andromeda Galaxy/star0/star0.ini"
star1="save/Andromeda Galaxy/star1/star1.ini"
star2="save/Andromeda Galaxy/star2/star2.ini"
star3="save/Andromeda Galaxy/star3/star3.ini"
star4="save/Andromeda Galaxy/star4/star4.ini"
star9="save/Andromeda Galaxy/star9/star9.ini"
star10="save/Andromeda Galaxy/star10/star10.ini"
star11="save/Andromeda Galaxy/star11/star11.ini"
__________________________________________________________________
I read them through. Everything should work. No variables end up with "error" unless the starX does not exists and defaults to "error". In that case, the 2nd do/until should find the next existing starX. As each star is found i is added up. Once equal to star_count, it should stop. Now I once again pulled out the 2nd do/until, and it works. Proving the star_count function works. I don't get how the 2nd part shouldn't work. I would appreciate your reply. Thanks in advance.
Edited by andykuo1, 06 April 2012 - 01:19 AM.
#6
Posted 06 April 2012 - 01:25 AM
#7
Posted 06 April 2012 - 01:33 AM
The problem is your INSIDE do loop does not have the star_count condition to stop! So add an || i == star count to your != "error"
It still goes into a continual loop....I still don't get what's causing this. Thanks for helping though.
#8
Posted 06 April 2012 - 01:35 AM
You should instead use one variable for the key indexes and a separate one for the number of created stars, since clearly they don't always match up.
ini_open("gxy_setup.ini");
star_count = ini_read_real("main", "star_count", 1);
i = 0;
count = 0;
do {
star = instance_create(x,y,obj_star);
star.star_adr = ini_read_string("star_adr", "star" + string(i), "error");
if (star.star_adr == "error") {
i += 1;
do {
star.star_adr = ini_read_string("star_adr", "star" + string(i), "error");
i += 1;
}
until(star.star_adr != "error");
}
i += 1;
count += 1;
}
until(count >= star_count);Here, "i" is still the key index, but "count" is a measure of the actual number of entries you've read.
-IMP
#9
Posted 06 April 2012 - 01:38 AM
Edit: Bah, or use IMP's method
Edited by greep, 06 April 2012 - 01:39 AM.
#10
Posted 06 April 2012 - 01:47 AM
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users











