For/Next with changeable variable.

enonod

Well-Known Member
Licensed User
Longtime User
Is there anything wrong with using variables in For/Next because the code below only does 3 columns, the last next seems to skip? It should do columns 0 and 14 then 1 and 13
B4X:
Sub AddSprites
Lft=0
Rgt=14
'Add the master frames
   Master.New2(AppPath & "\Psprite.png",6,15,15,6)
'Add remaining sprites, 3 colours
   For i=0 To 1
      For col=Lft To Rgt Step Rgt
         For j=0 To 14
            Pawn.New4(Master.FrameBitmaps,6,15,15,6)
'Binary data for later XOR, zero not usable so start at 1
            Pawn.Data=Bin.ShiftLeft(1,j Mod 3)
            Pawn.X = (col)*16+1
            Pawn.Y = ((j+(i)*14) Mod 15)*16+1
'Zero frame not usable as binary so -1
            Pawn.CurrentFrame=Pawn.Data-1
            gw.SpriteAdd(Pawn.Value)   
         Next
      Next
      Lft=1
      Rgt=13
   Next
End Sub
 

enonod

Well-Known Member
Licensed User
Longtime User
Thank you Erel, I have been on that for ages.
 

enonod

Well-Known Member
Licensed User
Longtime User
Thank you also agraham. I am a person that suffers from fence post syndrome!
Anyway, there is also another fault having I have spotted in that line, that I wouldn't have seen but for the comments posted. In the first loop I am starting from zero (necessarily) and so what will now become step(rgt-1) still wont allow the column 14 to work but 13 will. Back to the drawing board. [Edit] so the line should read For col=Lft To Rgt Step (rgt-lft)
 
Last edited:
Top