How do I get my array to create a checker board just once?

  • Hi, I'm trying to make a basic checkers game. My idea was to have the board and pieces all run through an 8x8 array, with different values for a blank square, a square with a red piece, and a square with a black piece. The board is created on start of layout.

    When I ran it in the debugger, I saw that the number of sprites representing board squares was growing every single tick, I'm assuming one right on top of the other as I can't see them. I've tried a lot of dumb ideas to get it to just create the board and stop with no success.

    As I'm new, I can't post a link to the capx, but the event that creates the board goes-

    Condition

    checkahs- for each xy element-

    Action

    System- create object boardSquare on layer 0 at (checkahs.CurX*boardsquare.Width+150, checkahs.CurY*boardsquare.Height+50)

    boardSquare- set animation frame to checkahs.CurValue

    boardSquare- set positionX to checkahs.CurX

    boardSquare- set positionY to checkahs.CurY

    boardSquare- set positionValue to checkahs.CurValue

    checkahs is the name of the array, boardSquare is the sprite that represents each square on the board, positionValue is an instance variable for the sprite boardSquare

    Any help would be greatly appreciated

  • You just need to set up your board creation event in a way, that it runs only when you want it.

    Different examples of how you can do it:

    1) add the trigger once while true condition

    2) use a global, local or instance variable, set it as condition to be 0, and when creating the board set this variable to 1

    3) put the generation event below a triggered event (those with the green arrow) - those only run on specific situations (i.e. on start of layout)

    4) compare two values: boardsquare.count = 0: create board; = count the number of board squares present in the layout, if there are no board squares, it creates the board

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Thank you, mindfaQ, that was very helpful. But it did expose bugs I had made further down in the event sheet, ha. I'll keep trucking, get there eventually.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)