Posts

Post not yet marked as solved
2 Replies
2.2k Views
Hello, I’m new to coding and have started with swift. I‘ve got a issue with a line of code not running in, “Randomizing Lands” under the “Arrays” subtitle in Learn to Code 2. I’m trying to place water. Can anyone perhaps let me know if there is a solution to this. Line 22 & 23 is not working, I’m not sure if this could be a bug on Swift Plagrounds part because when I use “ world.removeAllBlocks(at: coordinate) in line 22, the blocks are removed and replaced with water ( the problem is when there is a item on the block like a gem or character etc., then it doesn’t work for that particular coordinate, obviously because it’s not only blocks) Please Help 🙂let allCoordinates = world.allPossibleCoordinates var heights: [Int] for i in 1 ... 20 { let localNumber = randomInt(from: 0, to: 12) heights.append(localNumber) } var index = 0 for coordinate in allCoordinates { if index == heights.count { index = 0 } var currentHeight = heights[index] if currentHeight == 0 world.place(Gem(), at: coordinate) } else { for i in 1 ... currentHeight { world.place(Block(), at: coordinate) } if currentHeight > 10 { world.place(Character(), at: coordinate) } else if coordinate.column >= 3 && coordinate.column < 6 { world.removeItems(at: coordinate) world.place(Water()at: coordinate) } index += 1 }
Posted
by ARCT.
Last updated
.