Impact

This forum is read only and just serves as an archive. If you have any questions, please post them on github.com/phoboslab/impact

1 decade ago by faytmye

Hey guys, I've been trying to figure this one out for a while now but i've had to luck whatsoever. I'm still new to javascript and Impact so apologies if I don't fully understand.

Essentially, I'm trying to get LocalStorage working but the problem exists when I switch menu states using Director after pushing new lines into the arrays/storage. This is the gameplay flow broken down.

1. Array of 4 items are put into LocalStorage using Stringify. (These are default items that the player starts with)
2. LocalStorage parses the array and draws all four items correctly.
/><br />
3. Pressing "b" will push a new item into the array then into LocalStorage with Stringify (Player buys the character essentially to use in the game)<br />
4. LocalStorage parses the array and draws all four plus additional items correctly. <br />
<img src=http://www.youtube.com/watch?v=c53jzt8y-1c&feature=youtu.be

I've added the two main files below if someone could check them and enlighten me on the problem. I know the code is pretty sloppy but I'm still learning and using what works for me :P
https://github.com/faytmye/rpg-card

1 decade ago by Joncom

The problem occurs because when you load a level, all entities and their state are destroyed, and fresh new entities are spawned. This means, if "items" are being stored within a particular entity, they will be lost during this transition.

A fix would be to make note of what items an entity has before changing levels, and make sure to pass them along to the new entity.

Or perhaps not store items in an entity at all, but rather in your game (main.js), so that they are not lost during level transitions.

1 decade ago by faytmye

Thank you so much :)

It works when I moved the arrays to the main.js file. I think i'll keep it like this for the meantime and try the other method you mentioned in the future if I want to keep the code tidy.
Page 1 of 1
« first « previous next › last »