Help with Ocean Jam game

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.

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:

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!

Will you be able to put fish in the aquarium? :eyes:

1 Like

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

2 Likes

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

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:

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

1 Like