Page 1 of 1
Ajax calls without performing actions
Posted: 06 May 2024, 13:18
by imralav
Hello,
my question for today is if it is possible to make ajax calls to our backend without it being an action from our state machine?
For example, in one of the states I want the user to select some cards. Then, after the cards are selected, I just want to ask the backend for something, for example: what are possible places to put those cards now. But it's not a new state just yet. I just need to check something using ajax call.
Are additional ajax calls outside of ajax-call-to-feed-into-state-machine possible?
Best regards
Tomasz
Re: Ajax calls without performing actions
Posted: 06 May 2024, 13:27
by Tisaac
imralav wrote: ↑06 May 2024, 13:18
Hello,
my question for today is if it is possible to make ajax calls to our backend without it being an action from our state machine?
For example, in one of the states I want the user to select some cards. Then, after the cards are selected, I just want to ask the backend for something, for example: what are possible places to put those cards now. But it's not a new state just yet. I just need to check something using ajax call.
Are additional ajax calls outside of ajax-call-to-feed-into-state-machine possible?
Best regards
Tomasz
Yep, just do a call and send a notification to that specific player to send them the new informations. Just dont call any nextState
Re: Ajax calls without performing actions
Posted: 06 May 2024, 13:50
by thoun
You can.
Or you make a state for selecting a card, and another to place it, to keep a standard flow. In this case, if a user refresh between selecting and placing, the state will be consistent.
(You can check Pixies code, it's almost just those 2 actions)
Re: Ajax calls without performing actions
Posted: 06 May 2024, 14:04
by robinzig
Yet another option is to send all the information about the playable states of all the player's cards as part of the "args" of the state where the player selects the card. (This will obviously need to be kept private to that player lest other players have the potential to see what cards they have in hand.)
This has an obvious downside that you have to potentially calculate lots of things on the server that might not even be needed, which may or may not be a big problem depending on the game and what needs to be calculated. But the upsides are that you avoid the need for both an additional Ajax call in the middle of a state (as you are proposing), or for an additional state (which thoun is proposing, and which will mean you need to specifically code an undo for the selection if the player changes their mind, or risk a potentially frustrating UI if this isn't possible).
Re: Ajax calls without performing actions
Posted: 06 May 2024, 17:05
by imralav
Everyone, thanks for sharing your experience with me. I will definitely figure something out when testing your approaches.
Tisaac wrote: ↑06 May 2024, 13:27
Yep, just do a call and send a notification to that specific player to send them the new informations. Just dont call any nextState
If I understand the state engine correctly, it still requires me to have some actions defined for the state that I need this capability in, I just am allowed to skip any transitions?
Re: Ajax calls without performing actions
Posted: 06 May 2024, 18:40
by Tisaac
imralav wrote: ↑06 May 2024, 17:05
Everyone, thanks for sharing your experience with you. I will definitely figure something out when testing your approaches.
Tisaac wrote: ↑06 May 2024, 13:27
Yep, just do a call and send a notification to that specific player to send them the new informations. Just dont call any nextState
If I understand the state engine correctly, it still requires me to have some actions defined for the state that I need this capability in, I just am allowed to skip any transitions?
Actions and transitions are independent stuff, so you can just call an action without triggering any transition, just make sure to send a notif.
That being said, i am more of a server guy so i would go with what robin said as much as possible