GithubHelp home page GithubHelp logo

Comments (3)

sohomsahaun avatar sohomsahaun commented on June 9, 2024

Sounds like the code logic needs fixing. Why is the state getting changed twice in one step?
If you want a workaround, queue the states for the objects to "lock" the change in the Step event, and execute the changes in the End Step event.

from snowstate.

Juiin avatar Juiin commented on June 9, 2024

I have for example, 3 States in my Player Object, Idle, Move and Stunned. When the Player presses the move Buttons it switches from Idle to Move or if he stops pressing them, back to Idle, now an enemy could make an attack which when it hits the Player he would need to switch to Stunned, which has priority over all the other states, but if the code from the Enemy happens before(within the same step) the Move Idle state switching, it would not happen(or happen only very briefly and get switched back to Idle or Move).

from snowstate.

sohomsahaun avatar sohomsahaun commented on June 9, 2024

Understood. Then again, this feature shouldn't be included in Snowstate itself. What if the enemy hits 5-6 steps later instead of the same step? There could be a "state lock" buffer, but that would involve Snowstate constantly checking for that in the background, which is not very intuitive.

There are two solutions without any modification to Snowstate.

  1. Use a state priority queue to determine which state to switch to.
  2. [This is what I do]
    Use a variable to track if the player has been hit this step, and check for that variable in the states you want the player to get hit in. This keeps checking states for the player contained in the player itself, which is very useful when dealing with complex behavior and reduces code spaghetti.

Hope this helps.

from snowstate.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.