# Chapter 13 (Apple games by tutorials) fatal error

**URL:** <https://forums.kodeco.com/t/chapter-13-apple-games-by-tutorials-fatal-error/95829>\
**Category:** 2D iOS & tvOS Games by Tutorials\
**Created:** [January 25, 2020, 10:44pm UTC](https://forums.kodeco.com/t/chapter-13-apple-games-by-tutorials-fatal-error/95829 "2020-01-25T22:44:58Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![game\_gecko](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/game_gecko/32/81494_2.png) [@game\_gecko](https://forums.kodeco.com/u/game_gecko)\
**Post date:** [January 25, 2020, 10:44pm UTC](https://forums.kodeco.com/t/chapter-13-apple-games-by-tutorials-fatal-error/95829/1 "2020-01-25T22:44:59Z")

</div>

I wrote that I won’t be posting anymore errors on this forum, but I changed my mind. I am stuck on chapter 13 page 367. I build the game to see the bugs animate with the array of animation in Bug.swift.

I copied the code exactly how it is written in the book and am getting a fatal error **PestControl[2710:687445] Fatal error: Index out of range**  
**(lldb)**.

this line is getting the RED bar with the words Thread 1:Fatal error: Index out of range :  
— run(animations[direction.rawValue], withKey: “animation”) –  
when I comment out that line, I see the bug animations after I build it, but just for the front walk animation for the bug, and not for the back or sideway walk animation.

---

<div class="post-metadata">

**Author:** ![caroline](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/caroline/32/111867_2.png) [@caroline](https://forums.kodeco.com/u/caroline)\
**Post date:** [January 26, 2020, 1:27am UTC](https://forums.kodeco.com/t/chapter-13-apple-games-by-tutorials-fatal-error/95829/2 "2020-01-26T01:27:56Z")

</div>

Hi @game_gecko - I checked out the sample code in `final`, and that works. Does it work for you?  
Perhaps you could check your code against the code in the `final` directory?

---

<div class="post-metadata">

**Author:** ![game\_gecko](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/game_gecko/32/81494_2.png) [@game\_gecko](https://forums.kodeco.com/u/game_gecko)\
**Post date:** [January 30, 2020, 4:19pm UTC](https://forums.kodeco.com/t/chapter-13-apple-games-by-tutorials-fatal-error/95829/3 "2020-01-30T16:19:59Z")

</div>

I started with the starter file from chapter 13, and I always check the final version when I run into a problem, for each chapter.

---

<div class="post-metadata">

**Author:** ![caroline](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/caroline/32/111867_2.png) [@caroline](https://forums.kodeco.com/u/caroline)\
**Post date:** [January 30, 2020, 10:51pm UTC](https://forums.kodeco.com/t/chapter-13-apple-games-by-tutorials-fatal-error/95829/4 "2020-01-30T22:51:40Z")

</div>

That’s odd then. Please could you zip up your project and post it here? And also tell me the specifications of all the devices that you’re running it on - macOS version, Mac specs, Xcode version, simulator/device version etc.  
Thanks

---

<div class="post-metadata">

**Author:** ![game\_gecko](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/game_gecko/32/81494_2.png) [@game\_gecko](https://forums.kodeco.com/u/game_gecko)\
**Post date:** [February 1, 2020, 9:04pm UTC](https://forums.kodeco.com/t/chapter-13-apple-games-by-tutorials-fatal-error/95829/5 "2020-02-01T21:04:21Z")

</div>

![xcodeFatalError](https://files.chunter.kodeco.com/original/3X/7/d/7d23ce9794149d7b42f631ba8e3c7ef7f65f1932.jpeg)

I am using a MacBook Pro 2017, 2.3 GHz Dual-Core Intel Core i5 processor,8 GB of ram, Intel Iris Plus Graphics, 120 GB hd. The operating system is Catalina 10.15.3 and Xcode 11.3.1 (11C504).

I am using a iPad Pro 10.5" 64GB drive for testing.

---

<div class="post-metadata">

**Author:** ![caroline](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/caroline/32/111867_2.png) [@caroline](https://forums.kodeco.com/u/caroline)\
**Post date:** [February 2, 2020, 1:02am UTC](https://forums.kodeco.com/t/chapter-13-apple-games-by-tutorials-fatal-error/95829/6 "2020-02-02T01:02:52Z")

</div>

I have a MacBook Pro, but it has a separate GPU as well as the Intel. I wonder if that’s the problem. Are you able to zip up the whole project and upload it here and see if I can run it? I can’t work out how to test SpriteKit using only the Intel.

---

<div class="post-metadata">

**Author:** ![game\_gecko](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/game_gecko/32/81494_2.png) [@game\_gecko](https://forums.kodeco.com/u/game_gecko)\
**Post date:** [February 2, 2020, 9:15pm UTC](https://forums.kodeco.com/t/chapter-13-apple-games-by-tutorials-fatal-error/95829/7 "2020-02-02T21:15:42Z")

</div>

[starter.zip](https://forums.kodeco.com/uploads/short-url/vdlNA78CQ7bIi18rR5vqZBheLpX.zip) (402.6 KB)

I forgot that I started with chapter 12 starter file and worked on it since. I also converted the file to swift 5 version when prompted. So, I don’t know if that had anything to do with the problem I am having?

---

<div class="post-metadata">

**Author:** ![caroline](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/caroline/32/111867_2.png) [@caroline](https://forums.kodeco.com/u/caroline)\
**Post date:** [February 4, 2020, 8:32am UTC](https://forums.kodeco.com/t/chapter-13-apple-games-by-tutorials-fatal-error/95829/8 "2020-02-04T08:32:12Z")

</div>

Sorry about the late reply - I didn’t see the notification.

In Chapter 12, Beginning Tile Maps, you create a method called `createAnimations`. You appear to have left the final line out, which appends a fourth animation.

Add this to the end of `createAnimations(character:)`:

```auto
animations.append(SKAction.repeatForever(actionLeft))

```

I debugged this by adding code before the crash to print out properties to see why it was crashing. I added this code just before the crash:

```auto
    print(animations)
    print(direction.rawValue)

```

From that I could see that `direction.rawValue` was 3, meaning it was looking for the fourth element of `animations`. But `animations` only had three elements. So then I tracked down why `animations` only had three elements instead of four.

The reason why the fourth one is repeated, is that left and right animations are the same, only right is a mirror of left. That’s taken care of with changing the sign of `xScale` when setting up the direction in `move()`.

---

<div class="post-metadata">

**Author:** ![game\_gecko](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/game_gecko/32/81494_2.png) [@game\_gecko](https://forums.kodeco.com/u/game_gecko)\
**Post date:** [February 4, 2020, 6:17pm UTC](https://forums.kodeco.com/t/chapter-13-apple-games-by-tutorials-fatal-error/95829/9 "2020-02-04T18:17:10Z")

</div>

Thanks for your help! I will change the code as soon as I get back to working on the chapter. Also, you mentioned about moving the character , I remember that when I moved him to the right the game crashed.

Hopefully, I will have no problems with your solution.👍

---

<div class="post-metadata">

**Author:** ![caroline](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/caroline/32/111867_2.png) [@caroline](https://forums.kodeco.com/u/caroline)\
**Post date:** [February 5, 2020, 12:13am UTC](https://forums.kodeco.com/t/chapter-13-apple-games-by-tutorials-fatal-error/95829/10 "2020-02-05T00:13:58Z")

</div>

I hope so! I’m really glad you’re progressing through the book. SpriteKit is a great way to get into making games 🙂

---

<div class="post-metadata">

**Author:** ![system](https://s3.amazonaws.com/cdn.raywenderlich.com/community/forum-assets/noun-game-ghost-878668.png) [@system](https://forums.kodeco.com/u/system)\
**Post date:** [July 10, 2020, 2:50pm UTC](https://forums.kodeco.com/t/chapter-13-apple-games-by-tutorials-fatal-error/95829/11 "2020-07-10T14:50:41Z")

</div>

This topic was automatically closed after 166 days. New replies are no longer allowed.
