Convert legacy "ajaxcall" to new "bgaPerformAction" function?

Game development with Board Game Arena Studio
Post Reply
Ditto11
Posts: 121
Joined: 31 March 2023, 19:14

Convert legacy "ajaxcall" to new "bgaPerformAction" function?

Post by Ditto11 »

Ok .. so working on a game "dragonchess" .. which cloned the old "chess" program, so it's chock full of some old/legacy "ajaxcall"s ... and I'm now getting warnings to replace it with bgaPerformAction ..

Ok .. not a problem .. except the documentation seems to imply the parameter for these guys are not a straight forward translation ;)

First off, from the docs I see this:

Code: Select all

this.ajaxcall(url, parameters, obj_callback, callback, callback_anycase?, ajax_method?: string)

this.bgaPerformAction(action: string, args?: object, options: object = { lock: true, checkAction: true }): Promise<void>
Ok .. so my current ajaxcall looks like this:

Code: Select all

this.ajaxcall( "/dragonchess/dragonchess/selectCell.html", { cell_x: cell_x, cell_y: cell_y, cell_z: cell_z, selected_piece: this.gamedatas.piece_selected, lock: true }, this, function( result ) {} );
This is when a user clicks on a piece .. it triggers the logic to check if it's your piece . if your moving/capturing .. etc, etc.

Ok .. and trying to build the new bgaPerformAction .. I'm struggling a bit .. hoping for some help.

So I see these parameters for the ajaxcall (and how I suspect they are mapping ):

url (=> action: string) = "selectCell.html" it seems from the examples, I no longer need the full path to it? is this correct?

parameters (=> args?: object) = "{ cell_x: cell_x, cell_y: cell_y, cell_z: cell_z, selected_piece: this.gamedatas.piece_selected, lock: true }"
this one appears to be same setup from what I can tell ... passing in the parameters into the code that it needs ...

obj_callback (=> ?? ) = this
does this map to any of the parameters for the bgaPerformAction ??

callback (=> ?? ) =function( result ) {}
again, how does this map to the new function?

callback_anycase? (??) Seems this code doesn't use this parameter for ajax call?

ajax_method?: string (??) again, not used ??

the following parameters for the new bgaPerformAction:

action: string (from url) = "selectCell.html"

args?: object (from parameters) = "{ cell_x: cell_x, cell_y: cell_y, cell_z: cell_z, selected_piece: this.gamedatas.piece_selected }"

options: object (??) = "{ lock: true }" ??
is this correct, we move the "lock:true" to this section away from the previous argument ??

:Promise<void> ?? not sure what I'm supposed to use here? is this something do to with that "function ( result )" part in my ajaxcall?

So trying my best .. I end up with this "guess" ??

Code: Select all

 this.bgaPerformAction( "selectCell.html", { cell_x: cell_x, cell_y: cell_y, cell_z: cell_z, selected_piece: this.gamedatas.piece_selected }, { lock: true }).then(()=>{ this.function( result ) });
?? is this along the right lines?
User avatar
thoun
Posts: 1620
Joined: 10 December 2020, 22:25

Re: Convert legacy "ajaxcall" to new "bgaPerformAction" function?

Post by thoun »

Ditto11 wrote: 19 December 2024, 18:38 url (=> action: string) = "selectCell.html" it seems from the examples, I no longer need the full path to it? is this correct?
Also remove .html, action name is just "selectCell"
Ditto11 wrote: 19 December 2024, 18:38 parameters (=> args?: object) = "{ cell_x: cell_x, cell_y: cell_y, cell_z: cell_z, selected_piece: this.gamedatas.piece_selected, lock: true }"
So trying my best .. I end up with this "guess" ??
Ditto11 wrote: 19 December 2024, 18:38

Code: Select all

 this.bgaPerformAction( "selectCell.html", { cell_x: cell_x, cell_y: cell_y, cell_z: cell_z, selected_piece: this.gamedatas.piece_selected }, { lock: true }).then(()=>{ this.function( result ) });
Almost, here is the correct version :

Code: Select all

 this.bgaPerformAction( "selectCell", { cell_x: cell_x, cell_y: cell_y, cell_z: cell_z, selected_piece: this.gamedatas.piece_selected });
Don't hesitate to join the dev Discord for faster help from the community ;)
Ditto11
Posts: 121
Joined: 31 March 2023, 19:14

Re: Convert legacy "ajaxcall" to new "bgaPerformAction" function?

Post by Ditto11 »

Thanks .. I'll try that ..
so those extra parameters aren't really needed .. hmm

and right .. I have joined the discord previously . but forgot I did .. :P hehe
(hey, I'm still new to this .. :P )
Post Reply

Return to “Developers”