BUG: replay file cannot be played in latest svn

BUG: replay file cannot be played in latest svn

Postby acme_pjz » 07 Feb 2013, 17:25

When you click the replay button the game just start in normal mode :| :?
Some of my open source games on GitHub
User avatar
acme_pjz
 
Posts: 506
Joined: 10 Dec 2009, 15:32

Re: BUG: replay file cannot be played in latest svn

Postby acme_pjz » 07 Feb 2013, 17:31

False alarm :| It's my fault :x Bug caused in svn r568, I added an additional 'reset()' which erased the level record :| Still investigating how to fix that because in order to let script environment get reset we should call 'reset()' when record play starts or rewinds, so there will be more added 'reset()' calls later...
Some of my open source games on GitHub
User avatar
acme_pjz
 
Posts: 506
Joined: 10 Dec 2009, 15:32

Re: BUG: replay file cannot be played in latest svn

Postby Edward_Lii » 07 Feb 2013, 20:48

Hello acme_pjz,

acme_pjz {l Wrote}:I added an additional 'reset()' which erased the level record :| Still investigating how to fix that because in order to let script environment get reset we should call 'reset()' when record play starts or rewinds, so there will be more added 'reset()' calls later...

I think it would be best if we handled the onCreate scripts in the loadLevelFromNode method or after loading in the constructor along with the resetting of the ScriptExecutor.
The downside of this approach is the slight code duplication, but I like to think of it as:
load/constructor: Get the game state ready for playing the level.
reset: Get the game state back as it was after loading.

This made me realise that there will be some problems regarding scripting and checkpoints. :|
Simply storing the previous location won't work because of stored variables.
One solution would be to create onSave and onLoad events allowing scripts to save and load their state, but I'm afraid bugs can easily be made in these methods.
Levelmakers could also fiddle with these events to create unexpected behaviour.

The best solution would be IMHO to somehow save the complete lua_State and the box locations.
However, this won't work when scripts can remove/create gameobjects. :think:
From,
Edward_Lii
User avatar
Edward_Lii
MnMS Moderator
 
Posts: 770
Joined: 20 Dec 2010, 16:46

Re: BUG: replay file cannot be played in latest svn

Postby acme_pjz » 08 Feb 2013, 06:19

Hi,

Edward_Lii {l Wrote}:I think it would be best if we handled the onCreate scripts in the loadLevelFromNode method


No, it doesn't work :( At first I tried it before committing svn r568 and found that the onCreate script doesn't work properly :| because the old code 'currentState=new Game();' call the 'Game::Game()' then call 'Game::loadLevelFromNode()' then call the onCreate script, before Game::Game() returns. So 'currentState' is still NULL, and script code querying the game state won't work because it can't find the pointer point to Game object :| IMHO the best solution is yours (i.e. code before svn r568), but we shouldn't load any level or record in the constructor, we should load level after the class initialized and 'currentState' has a correct value, i.e. remove the 'loadLevel' parameter in the constructor.

Edward_Lii {l Wrote}:The best solution would be IMHO to somehow save the complete lua_State and the box locations.
However, this won't work when scripts can remove/create gameobjects. :think:


Is there any function in Lua to duplicate the complete lua_State? And we will find a way to store the information of removed/created blocks :|
Some of my open source games on GitHub
User avatar
acme_pjz
 
Posts: 506
Joined: 10 Dec 2009, 15:32

Re: BUG: replay file cannot be played in latest svn

Postby Edward_Lii » 08 Feb 2013, 16:49

Hello acme_pjz,

acme_pjz {l Wrote}:No, it doesn't work :( At first I tried it before committing svn r568 and found that the onCreate script doesn't work properly :| because the old code 'currentState=new Game();' call the 'Game::Game()' then call 'Game::loadLevelFromNode()' then call the onCreate script, before Game::Game() returns. So 'currentState' is still NULL, and script code querying the game state won't work because it can't find the pointer point to Game object :| IMHO the best solution is yours (i.e. code before svn r568), but we shouldn't load any level or record in the constructor, we should load level after the class initialized and 'currentState' has a correct value, i.e. remove the 'loadLevel' parameter in the constructor.

I have done as you suggested by moving the loading of a replay/level outside of the Game constructor.
It seems to work quite well, but the problem is that it doesn't work for the interlevel replay. :(
For the replay to work the scriptexecutor has to be reset and the onCreate scripts need to be executed.
This could be added to the replayPlay method, but that means we have the same code in three different places, which feels a bit bad. :|

acme_pjz {l Wrote}:Is there any function in Lua to duplicate the complete lua_State?

Not that I could find, that's why I added the word "somehow". :p
Still I think it's the best solution, maybe we can use environments for this?
From,
Edward_Lii
User avatar
Edward_Lii
MnMS Moderator
 
Posts: 770
Joined: 20 Dec 2010, 16:46

Re: BUG: replay file cannot be played in latest svn

Postby acme_pjz » 09 Feb 2013, 07:57

Edward_Lii {l Wrote}:[...] For the replay to work the scriptexecutor has to be reset and the onCreate scripts need to be executed.
This could be added to the replayPlay method, but that means we have the same code in three different places, which feels a bit bad. :|


Extract these codes and make a common subroutine ;)

Edward_Lii {l Wrote}:Not that I could find, that's why I added the word "somehow". :p
Still I think it's the best solution, maybe we can use environments for this?


Lua environments is a good idea, just like the sandbox code in Lua user wiki :) IMHO we should add it after non-script part is done (i.e. backup/restore the whole block array)
Some of my open source games on GitHub
User avatar
acme_pjz
 
Posts: 506
Joined: 10 Dec 2009, 15:32

Who is online

Users browsing this forum: No registered users and 1 guest