Coronium Ace - timers on server side

Hello,

the game timeout event is automatically sent to clients based on ‘game_timeout’ property defined in default configuration.

is it possible to trigger an event from the server side to connected clients after a certain time (as it is done with the game_timeout?

How can this be done ?

Thank you for your help.

Lourenço.

Hi,

The game timeout is actually a Corona based timer that is reset each time the player state is synced between both clients. So it’s not technically being triggered from the server side.

You could emulate this by setting a timeout of some sort on the state object. I don’t know what your intended use case is, but if you are just wanting to limit the amount of time a player must make a move by you could do something like this:

Server-side

function game.myFunction( params, gameCtx ) --send p1 a 30 sec timeout and p2 no timeout gameCtx:setStateProps("mytimeout", 30000, 0) --swap turn if needed gameCtx:swapTurn() --sync player state gameCtx:gameSync() end function game.onMyTimeout( params, gameCtx ) -- do whatever needs to be done on a timeout end

Client-side

local myTimer local function onGameState() local mytimeout = ace.getStateProp("mytimeout") if mytimeout == 0 then if myTimer then timer.cancel(myTimer) end else myTimer = timer.performWithDelay(mytimeout, function() --call server side timeout ace.game.onMyTimeout() --you probably want to force a player lock here ace.lockPlayer() end) end end --game handler here

This code is just off the top of my head and untested. I will put together a test project and post it a little later today.

Hope that helps.

-dev

Hi,

Based on your use case I am going to be adding a config setting for a move timeout event for time based games which will trigger an informational event on the client side.

I think that would be a nice feature to have for time based games. I should have it implemented by later today. I’ll post again when it is ready and documented.

Thanks for testing and providing feedback.

-dev

Dev,

The screencasts were great!  Are you able to give a brief explanation of ‘hooks’?

Regarding your example above, do you think it better to call the ace.lockPlayer() on the client, or let the function game.onMyTimeout on the server side … lock the player?   Or does it make no difference?

On the text editor on the server side, is it possible to add a ‘search’ feature?

Thanks

Bob

Hi,

Because of the inherent network latency of a server call it is best to lock the player on the client side. If not, another call might make it through before a “lock” state was established.

Right now there is really only one game hook. I will add that to my next set of videos. But you can get a general overview here https://develephant.github.io/coronium-ace-docs/server/guide/hooks/

I will look into adding a search function on the code editor. I am also experimenting with a tool that will allow you to push from your desktop, that way you can use your preferred code editor.

Thank you both so much for taking the time to experiment with Coronium Ace. 

-dev

Hi,

@cyberparkstudios find/replace/etc. functionality should be available now in the code editor for version 1.0.2, you’ll probably need to refresh the browser cache, and possibly re-log in.

Make sure the cursor is in the editor and use the keystrokes  command-f for macOS and control-f for Windows.

Tip: If you press the " All"  button it will perform a multi-select allowing you to edit multiple results in-line.

-dev

Thanks dev … works great!

Hi,

The game timeout is actually a Corona based timer that is reset each time the player state is synced between both clients. So it’s not technically being triggered from the server side.

You could emulate this by setting a timeout of some sort on the state object. I don’t know what your intended use case is, but if you are just wanting to limit the amount of time a player must make a move by you could do something like this:

Server-side

function game.myFunction( params, gameCtx ) --send p1 a 30 sec timeout and p2 no timeout gameCtx:setStateProps("mytimeout", 30000, 0) --swap turn if needed gameCtx:swapTurn() --sync player state gameCtx:gameSync() end function game.onMyTimeout( params, gameCtx ) -- do whatever needs to be done on a timeout end

Client-side

local myTimer local function onGameState() local mytimeout = ace.getStateProp("mytimeout") if mytimeout == 0 then if myTimer then timer.cancel(myTimer) end else myTimer = timer.performWithDelay(mytimeout, function() --call server side timeout ace.game.onMyTimeout() --you probably want to force a player lock here ace.lockPlayer() end) end end --game handler here

This code is just off the top of my head and untested. I will put together a test project and post it a little later today.

Hope that helps.

-dev

Hi,

Based on your use case I am going to be adding a config setting for a move timeout event for time based games which will trigger an informational event on the client side.

I think that would be a nice feature to have for time based games. I should have it implemented by later today. I’ll post again when it is ready and documented.

Thanks for testing and providing feedback.

-dev

Dev,

The screencasts were great!  Are you able to give a brief explanation of ‘hooks’?

Regarding your example above, do you think it better to call the ace.lockPlayer() on the client, or let the function game.onMyTimeout on the server side … lock the player?   Or does it make no difference?

On the text editor on the server side, is it possible to add a ‘search’ feature?

Thanks

Bob

Hi,

Because of the inherent network latency of a server call it is best to lock the player on the client side. If not, another call might make it through before a “lock” state was established.

Right now there is really only one game hook. I will add that to my next set of videos. But you can get a general overview here https://develephant.github.io/coronium-ace-docs/server/guide/hooks/

I will look into adding a search function on the code editor. I am also experimenting with a tool that will allow you to push from your desktop, that way you can use your preferred code editor.

Thank you both so much for taking the time to experiment with Coronium Ace. 

-dev

Hi,

@cyberparkstudios find/replace/etc. functionality should be available now in the code editor for version 1.0.2, you’ll probably need to refresh the browser cache, and possibly re-log in.

Make sure the cursor is in the editor and use the keystrokes  command-f for macOS and control-f for Windows.

Tip: If you press the " All"  button it will perform a multi-select allowing you to edit multiple results in-line.

-dev

Thanks dev … works great!