Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.
Status
Not open for further replies.

Cokezero

macrumors newbie
Original poster
Jun 9, 2019
1
0
New Orleans
I am trying to learn how to code, using Swift.

Attached is a screenshot from the Swift playgrounds app on iPad, which demonstrates my problem.

Based on my code, why is my guy not picking up the Gem in the last square? Every time he moves, he’s supposed to check to see if there’s a gem, and then if so collectGem(), right?

This puzzle is further complicated by the fact that the only Gem on the map is in the very last square, so I have no idea if the code even works properly anywhere else.

If this is the wrong place to post this, please let me know and I will close or delete it.
 
When i first read your post before I saw your screenshot, i figured you probably just made the check before you moved, and thus didn't pick up anything after the move. But that clearly isn't the case. There's nothing that immediately springs to my eyes. Though if where your character is standing is the end of the route, you aren't ontop of a gem, and if it's the start he looks to be pointing the wrong direction and should have two turns.

I feel honestly a little embarrassed I can't spot the issue, a computer science student.... Any change you could upload the code so i can copy it into Playgrounds and examine what happens at runtime, along with information about which map that is?
Or if it's possible upload the playground here, but I don't think that's possible.
 
Status
Not open for further replies.
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.