Ajax calls without performing actions

Game development with Board Game Arena Studio
Post Reply
imralav
Posts: 44
Joined: 02 February 2024, 08:56

Ajax calls without performing actions

Post 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
User avatar
Tisaac
Posts: 2743
Joined: 26 August 2014, 21:28

Re: Ajax calls without performing actions

Post 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
User avatar
thoun
Posts: 1620
Joined: 10 December 2020, 22:25

Re: Ajax calls without performing actions

Post 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)
User avatar
robinzig
Posts: 461
Joined: 11 February 2021, 18:23

Re: Ajax calls without performing actions

Post 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).
imralav
Posts: 44
Joined: 02 February 2024, 08:56

Re: Ajax calls without performing actions

Post 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?
Last edited by imralav on 07 May 2024, 05:30, edited 1 time in total.
User avatar
Tisaac
Posts: 2743
Joined: 26 August 2014, 21:28

Re: Ajax calls without performing actions

Post 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
Post Reply

Return to “Developers”