Page 1 of 1

Undocumented framework behaviour

Posted: 17 May 2020, 18:18
by Lunalol
This is a long question...

In a game, I have an "activeplayer' state with an args callback (argument for your game state), let's call it argPossibleMoves.
This callback create a list of possible moves stocked in $this->possible and returned by args callback to client side.

On client side, when a move action is done, an Ajax call is made to mygame.action.php which call for example acMove in mygame.game.php.
...Hope you still follow...

Now, in acMove callback, $this->possible is not defined BUT after self::checkAction('move'); it is restored.

So, there is, in the framework, a mechanism which stores class variables somewhere and restores them.
I find my variable "possible" in database table replaysavepoint.

So, here is my question, can we have some explanations about this mechanism ?

And, which is the FASTER mechanism :
  • store datas in DB
  • store datas in class variable (which are finally stored in BD, so not really efficient ?)
Everytime I need datas, I call "sell::getSomethingFromDB", so I prefer datas stored in class variable, but with this mechanism, I doubt.
And finally, if I create my list of possible moves in a 'stSomething' state, it is not restored in args callback.

Thanks for All.
PJL

Re: Undocumented framework behaviour

Posted: 19 May 2020, 13:39
by Lunalol
up

Re: Undocumented framework behaviour

Posted: 19 May 2020, 14:17
by RicardoRix
If you need variables to persist then you need to store them in the DB.

Server programming is not like a normal program. Your class object does not persist in memory.
On a page refresh, F5, the server runs - your class is created - delivers it's page content and then disappears.

Re: Undocumented framework behaviour

Posted: 19 May 2020, 14:18
by sourisdudesert
Hi

In 99% of the case, there is no need for such a caching algorithm on server side because:
_ the game database is usually very small
_ we designed our database to be accessed very fast

So unless you found there are some really important performance issues, you don't have to worry about that.

About "args": the framework may call your function at various time. There is no really way to know when it's going to be called: it is called when needed. As you notice it may be called by your "checkAction", but you cannot rely on this. If you absolutely need this variable to be filled, then explicitly call your method which fill it.