Sooda
Diversity enchants
- Reaction score
- 318
I did two identical functions, one without loop where I copy pasted code and it works as planned and another function where I used loop and it actually halts execution of program.
I am using Firefox canvas to create my electricity learning object.
This is function that works:
This one is supposed to use loop to do same thing though it fails:
I suspect loop runs in separate thread and it can't get variables in time. Pros maybe some tips?
I am using Firefox canvas to create my electricity learning object.
This is function that works:
Code:
function mysteryFunction(messageLayer)
{
isArrowOneVisible = arrowIndexVisible[0]
isArrowTwoVisible = arrowIndexVisible[1]
isArrowThreeVisible = arrowIndexVisible[2]
isArrowFourVisible = arrowIndexVisible[3]
udv_rangeStart[0] = 0
udv_rangeEnd[0] = 3
justDoIt(messageLayer, udv_rangeStart[0], udv_rangeEnd[0])
arrowIndexVisible[0] = isArrowOneVisible
arrowIndexVisible[1] = isArrowTwoVisible
arrowIndexVisible[2] = isArrowThreeVisible
arrowIndexVisible[3] = isArrowFourVisible
udv_rangeStart[1] = 4
udv_rangeEnd[1] = 7
justDoIt(messageLayer, udv_rangeStart[1], udv_rangeEnd[1])
arrowIndexVisible[0] = isArrowOneVisible
arrowIndexVisible[1] = isArrowTwoVisible
arrowIndexVisible[2] = isArrowThreeVisible
arrowIndexVisible[3] = isArrowFourVisible
udv_rangeStart[2] = 8
udv_rangeEnd[2] = 11
justDoIt(messageLayer, udv_rangeStart[2], udv_rangeEnd[2])
// With next function execution display new sprite
// there are 4 sprites total, with indexes from 0 to 3
if (arrowIndex == 3)
{
arrowIndex = 0
}
else
{
arrowIndex++
}
}
This one is supposed to use loop to do same thing though it fails:
Code:
function UpdateValidSprites(messageLayer)
{
isArrowOneVisible = arrowIndexVisible[0]
isArrowTwoVisible = arrowIndexVisible[1]
isArrowThreeVisible = arrowIndexVisible[2]
isArrowFourVisible = arrowIndexVisible[3]
udv_rangeStart[0] = 0
udv_rangeEnd[0] = 3
udv_rangeStart[1] = 4
udv_rangeEnd[1] = 7
udv_rangeStart[2] = 8
udv_rangeEnd[2] = 11
for (index=0; index<=2; index++)
{
justDoIt(messageLayer, udv_rangeStart[index], udv_rangeEnd[index])
arrowIndexVisible[0] = isArrowOneVisible
arrowIndexVisible[1] = isArrowTwoVisible
arrowIndexVisible[2] = isArrowThreeVisible
arrowIndexVisible[3] = isArrowFourVisible
}
// With next function execution display new sprite
// there are 4 sprites total, with indexes from 0 to 3
if (arrowIndex == 3)
{
arrowIndex = 0
}
else
{
arrowIndex++
}
}
I suspect loop runs in separate thread and it can't get variables in time. Pros maybe some tips?