# Help with Ocean Jam game

**URL:** <https://forum.makecode.com/t/help-with-ocean-jam-game/4487>\
**Category:** Help\
**Created:** [November 18, 2020, 6:00pm UTC](https://forum.makecode.com/t/help-with-ocean-jam-game/4487 "2020-11-18T18:00:45Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![UnsignedArduino](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/unsignedarduino/32/592_2.png) [@UnsignedArduino](https://forum.makecode.com/u/UnsignedArduino)\
**Post date:** [November 18, 2020, 6:00pm UTC](https://forum.makecode.com/t/help-with-ocean-jam-game/4487/1 "2020-11-18T18:00:45Z")

</div>

I’ve made a game where you could design aquariums for the Ocean Jam. (No copying please!) I’m having trouble with loading a game state. For whatever reason, the `for` loop only runs once and only spawns in the first thing created.

> **[Aquarium Simulator v0.4.1 \*\*BETA\*\*](https://arcade.makecode.com/64059-81762-80814-29518)**
>
> Made with ❤️ in Microsoft MakeCode Arcade.

Press `B` to open a menu. Hopefully, the rest is self-explanatory. If you place something down, you can select it with `A` and bring up a “right-click” menu with `B`. If you aren’t selecting anything it’s like right-clicking the background.

This is the problem part:

```typescript
function load_aquarium(name: string): boolean {
    let save_name: string = "aquarium_simulator_save_" + name + "_sprite_count"
    if (blockSettings.exists(save_name)) {
        console.logValue(save_name, blockSettings.readNumber(save_name))
        let i: number = 0
        // Here
        // Problem is that while loop exits too early
        for (let i = 0; i < blockSettings.readNumber(save_name); i++){
            save_name = "aquarium_simulator_save_" + name + "_sprite_" + i + "_"
            let index: number = blockSettings.readNumber(save_name + "index")
            console.logValue(save_name + "index", blockSettings.readNumber(save_name + "index"))
            console.logValue(save_name + "x", blockSettings.readNumber(save_name + "x"))
            console.logValue(save_name + "y", blockSettings.readNumber(save_name + "y"))
            console.logValue(save_name + "z", blockSettings.readNumber(save_name + "z"))
            let sprite_thing = summon_thing(
                blockSettings.readNumber(save_name + "x"), 
                blockSettings.readNumber(save_name + "y"), 
                blockObject.getStringProperty(shop_list[index], StrProp.name), 
                index, 
                blockObject.getImageProperty(shop_list[index], ImageProp.regular_image), 
                blockObject.getImageProperty(shop_list[index], ImageProp.selected_image)
            )
            sprite_thing.z = blockSettings.readNumber(save_name + "z")
        }
        return true
    }
    return false
}

```

Hmmm…I meant `for` loop instead of `while` loop in the comment above.

If you are confused about how it works, please tell me!

Thanks in advance!

---

<div class="post-metadata">

**Author:** ![Kat](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/kat/32/2596_2.png) [@Kat](https://forum.makecode.com/u/Kat)\
**Post date:** [November 18, 2020, 6:14pm UTC](https://forum.makecode.com/t/help-with-ocean-jam-game/4487/2 "2020-11-18T18:14:06Z")

</div>

Will you be able to put fish in the aquarium? 👀

---

<div class="post-metadata">

**Author:** ![UnsignedArduino](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/unsignedarduino/32/592_2.png) [@UnsignedArduino](https://forum.makecode.com/u/UnsignedArduino)\
**Post date:** [November 18, 2020, 6:15pm UTC](https://forum.makecode.com/t/help-with-ocean-jam-game/4487/3 "2020-11-18T18:15:45Z")

</div>

Eventually yes. I want them to move around and have the sharks occasionally eat one.

---

<div class="post-metadata">

**Author:** ![livcheerful](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/livcheerful/32/3509_2.png) [@livcheerful](https://forum.makecode.com/u/livcheerful)\
**Post date:** [November 18, 2020, 10:50pm UTC](https://forum.makecode.com/t/help-with-ocean-jam-game/4487/4 "2020-11-18T22:50:27Z")

</div>

AAAH I fixed it!

So I made two changes:

One was in load\_aquarium. I didn’t dig in too deeply as to why this is the case, but the number saved to the save\_name was being changed as you were loading in new sprites. So I fixed it by just fetching the number of sprites we wanted to load and storing it in numSprites and looping over that

 ![image](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/2X/7/7a982bbc344a4dbfb2593f87abfb06cfc76ed634.png)

The second is in save\_current\_aquarium - there was an off by one error caused by incrementing sprite\_counter an extra time outside of the for loop. Removing it looks like this:

 ![image](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/2X/f/f4f8404850ee24d81583b7db12c1e2926db9a642.png)

With these changes I was able to load in my aquarium! This looks so cool 😃
