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

Just started using Construct 2? Post your questions here

Post » Sat Apr 04, 2015 5:31 am

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
B
3
Posts: 2
Reputation: 185


Post » Sun Apr 05, 2015 2:13 pm

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
Visual Novel 'Engine' in 100 Events
if you ever have to choose between buying Construct 2 on scirra.com or on Steam, read this: Review
B
22
S
9
G
1
Posts: 787
Reputation: 3,786

Post » Wed Apr 08, 2015 6:10 am

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.
B
3
Posts: 2
Reputation: 185


Return to Beginner's Questions

Who is online

Users browsing this forum: No registered users and 0 guests