Share via

Small basic array loop problem

Kevin Clark 1 Reputation point
2021-12-30T15:54:46.873+00:00

I am trying to create a card game in Small Basic. I create an array of cards with images and then try to move the cards by looping through 1 to 52. However, index counters 1 and 2 don't do anything, and then index 3 moves array item 1. This keeps happening until index 52 moves card 50 and leaves the last two cards unmoved. I've checked the underlying array data and the data is correct. Here's the loop:

for i=1 to 52
imgID=cards[i]["imgID"]
Shapes.ShowShape(imgID)
Shapes.Move(imgID,300,300)
EndFor

I tried this as well:

for i=1 to 2
      imgID=cards[i]["imgID"]
      Shapes.ShowShape(imgID)
      Shapes.Move(imgID,300,300)
  EndFor

    for i=1 to 52
      imgID=cards[i]["imgID"]
      Shapes.ShowShape(imgID)
      Shapes.Move(imgID,300,300)
    EndFor

The first loop does nothing, but it does cause the second loop to properly start at the first card. However, in the second loop when i gets to 3 the loop does nothing for indexes of 3 and 4 and then starts up again at 5 showing card 3. I'm really at a loss to understand what is going on.

Developer technologies | Small BASIC
Developer technologies | Small BASIC

A programming language created by Microsoft that serves a stepping stone for beginners from block-based coding languages to more complex text-based languages.

0 comments No comments

1 answer

Sort by: Most helpful
  1. JR 126 Reputation points
    2021-12-30T21:01:16.467+00:00

    Here is how I did it:

    For x=1To 52
    Cards[x]=ImageList.LoadImage("C:\Temp\Cards\" + x + ".png")
    'GraphicsWindow.DrawImage(Cards[x],0,0)
    image=Shapes.addimage(Cards[x])
    Shapes.Move(image,300,300)
    Program.Delay(1000)
    endfor

    At first I used the GraphicsWindow.DrawImage which is commented out and then used Shapes.AddImage.
    The cards I numbered from 1.png to 52.png.This appears to work OK. I do see all 52 cards displayed.

    JR

    Was this answer helpful?

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.