A For problem
by Lee-Orr Orbach · in Torque Game Engine · 11/03/2005 (7:56 am) · 8 replies
Hello again!!!
I ran into(another) error in making my prototype. for some reason, a for loop I made doesn't work. there are no compile errors, or any other errors in the log. I'll post the needed code here:
the loops are inside each other, and I don't want to post the whole loop(it is vary long), but it still doesn't work. if anyone has ideas, or the solotion, please post it.
any help is more thatn appreciated,
Lee-Orr
I ran into(another) error in making my prototype. for some reason, a for loop I made doesn't work. there are no compile errors, or any other errors in the log. I'll post the needed code here:
%num_found = 0;
$finished_algorithem = 0;
for(%i = 1;%i<13;%i++) //--------> this loop works
{
%num_found = 0;
echo("----Loop num "@%i@" Has Started----");
if($finished_algorithem == 1)
{
break;
echo("loop wasn't broken at the begining");
}
if(%i == 1)
{
$num_lev_function[0] = 1;
echo("----%i was checked and is 1");
}else{
echo("----%i was checked and isn't 1");
}
%i2 = %i-1;
%pre_fun_lev = $num_lev_function[%i2];
echo(%pre_fun_lev);
for(%num = 1;%num < %pre_fun_lev;%num++) //----------------> this loop DOESN'T work
{
echo("----Loop num in %num"@%num@" Has Started----");the loops are inside each other, and I don't want to post the whole loop(it is vary long), but it still doesn't work. if anyone has ideas, or the solotion, please post it.
any help is more thatn appreciated,
Lee-Orr
About the author
#2
11/03/2005 (8:43 am)
What is the value of $pre_fun_lev when it's echo'd?
#3
@ Rubes - the first time $pre_fun_lev is echo'd it is "1", which is strange. in the next loop, it is nil, and it stays nil.
I tried editing it so it will be like this:
I'll continue looking,
Lee-Orr
11/03/2005 (9:28 am)
@ Jacopo De Luca - the $num_lev_function[0] is assigned inly because it is needed at the moment. inside this for loop, the rest of the $num_lev_function array is filled. @ Rubes - the first time $pre_fun_lev is echo'd it is "1", which is strange. in the next loop, it is nil, and it stays nil.
I tried editing it so it will be like this:
if(%i == 1)
{
%i2 = 0;
$num_lev_function[0] = 1;
echo("----%i was checked and is 1");
}else{
%i2 = %i-1;
echo("----%i was checked and isn't 1");
}
%pre_fun_lev = $num_lev_function[%i2];but it didn't change a thing. I do get all the echos in the posted code, except the one inside the for loop.I'll continue looking,
Lee-Orr
#4
11/03/2005 (9:29 am)
Is there a particular reason why you're starting both loops at 1? It would make for better and cleaner code to start from 0, especially since it appears all you're doing is using %i for array indexes. If you start at 0 then you can eliminate the need for that %i2 variable completely.
#5
From what you said, I still believe that the problem is the assignment of the array $num_lev_function. Are you sure that it is correctly assigned somewhere inside the first loop? In the code you posted there is no instruction that does that.
The $pre_fun_lev variable is assigned to values of the array, so this seems to confirm what I am suggesting: only the first element is assigned to something, and the rest is not assigned.
Bye,
Jacopo
11/03/2005 (9:42 am)
Hi Le-Orr.From what you said, I still believe that the problem is the assignment of the array $num_lev_function. Are you sure that it is correctly assigned somewhere inside the first loop? In the code you posted there is no instruction that does that.
The $pre_fun_lev variable is assigned to values of the array, so this seems to confirm what I am suggesting: only the first element is assigned to something, and the rest is not assigned.
Bye,
Jacopo
#6
the problem was a combination of what Scott and Jacopo said. I because I started with 1 insted of zero AND because I assigned only one part of the array. It works now!!!
THANKS!!!
Lee-Orr
11/03/2005 (9:50 am)
Hey!!! I Did It!!!the problem was a combination of what Scott and Jacopo said. I because I started with 1 insted of zero AND because I assigned only one part of the array. It works now!!!
THANKS!!!
Lee-Orr
#8
11/03/2005 (10:41 am)
Glad to help!
Torque 3D Owner Jacopo De Luca
Default Studio Name
It seems that you don't assign any value to the array $num_lev_function[].
The only value you set is $num_lev_function[0] = 1.
Hope this helps.
Bye,
Jacopo