Wintermute Engine Forum

Wintermute Engine => Technical forum => Topic started by: Kaz on March 20, 2012, 02:45:41 PM

Title: Can't get AfterLoad to trigger
Post by: Kaz on March 20, 2012, 02:45:41 PM
Hi All

I can't get AfterLoad to trigger and was wondering if anybody could suggest why. In my Main Menu window, I have this:
on "PlayButton"
  {
  Game.GoForIt = true;
  if(Game.IsSaveSlotUsed(CurrentPlayerSlot) == true)
    {
   Game.LoadGame(CurrentPlayerSlot);
   Game.Msg("Load game executed");
   }
  CloseThis();
  }

I have this in game.script:
on "AfterLoad"
  {
  for(var ddd = 1; ddd<11; ddd=ddd+1)
    {
    Game.Msg("Afterload reached");
   }
  if(MainMenu.State != null)
    {
   Game.Msg("MainMenu Detected");
   var mmwin = MainMenu.State;
   mmwin.Close();
   MainMenu.State = null;
   MainMenu.Showing = false;
   Game.UnloadObject(mmwin);
   }
  }

The AfterLoad is never reached and the menu window doesn't close. Any ideas?

Thanks
Title: Re: Can't get AfterLoad to trigger
Post by: Kaz on March 20, 2012, 04:48:58 PM
I should add that I've looked at all the other mentions of AfterLoad here, and I've made sure these are clean saves.
Title: Re: Can't get AfterLoad to trigger
Post by: Spellbreaker on March 20, 2012, 05:43:33 PM
Strange. Actually I copied that reach-loop. My afterload works perfectly, but for some reason the Game.Msg does not seem to work. The rest in my case works ( plugin gets started and music gets loaded ).

I dunno why the game.msg does not work. Break Points in the debugger doesn't seem to work either.
Title: Re: Can't get AfterLoad to trigger
Post by: Kaz on March 20, 2012, 06:12:50 PM
So is it me or is it a (gulp) bug, do you think? :-(
Title: Re: Can't get AfterLoad to trigger
Post by: Spellbreaker on March 20, 2012, 07:00:25 PM
I think it's a bug. But as I said, other code gets executed, except that game.msg stuff.
Title: Re: Can't get AfterLoad to trigger
Post by: Kaz on March 20, 2012, 07:06:19 PM
What I don't get is why Afterload works for you, using my code, but not in the context I took it from ????
Title: Re: Can't get AfterLoad to trigger
Post by: Spellbreaker on March 20, 2012, 07:29:43 PM
I really don't know.
Title: Re: Can't get AfterLoad to trigger
Post by: Kaz on March 20, 2012, 07:36:53 PM
Thanks for the input. If I can't get this to work, I'm going to be really stuck. God, I hope it's not a bug.
Title: Re: Can't get AfterLoad to trigger
Post by: Mnemonic on March 21, 2012, 07:55:01 AM
If I put this to game.script, I get the message with no problems:

Code: WME Script
  1. on "AfterLoad"
  2. {
  3.   Game.Msg("after load");
  4. }
  5.  

Even if I use Kaz' loop, I get lots of messages.

Kaz, you should start with something simple (just the message) and then keep adding your more complex code to see when/if it breaks. But make sure to always save the game with the modified scripts first.

Also, Game.LOG() is perhaps more appropriate for testing, because the log file doesn't disappear after a few seconds ;)
Title: Re: Can't get AfterLoad to trigger
Post by: Kaz on March 21, 2012, 09:41:22 AM
Thanks Mnemonic, I'll give it a try. But I'm a bit concerned about committing code to a function, that may be selective about what instructions it obeys  ;D

However, I think I may also have figured out alternative way of doing it, via the Registry.

Cheers
Title: Re: Can't get AfterLoad to trigger
Post by: metamorphium on March 22, 2012, 10:36:24 PM
AfterLoad works. I use it all the time. Keep in mind that the after load code must be present in your savegame. If you are loading savegame from the time before you've implemented AfterLoad, it will not work.
Title: Re: Can't get AfterLoad to trigger
Post by: Azrael on March 23, 2012, 09:26:29 AM
AfterLoad works also for us, never had problem with that.
Title: Re: Can't get AfterLoad to trigger
Post by: Kaz on March 25, 2012, 05:21:09 PM
Thanks to all - I did as suggested and stripped the code down until I could convince myself my code was at fault, on the presumption that it's usually me, :-[ not Mnemonic. It's working now. 8)

I'm using this for the classic "Large Aquatic" style of Autosave. Exit from In-Game menu window saves game, then loads main menu window, to allow to quit altogether, etc. The problem is, the loaded save then takes up from that point, so loads the main menu again. To get round this, I use AfterLoad to set a global Game.PostLoad=true, then test for that every time I load the main menu from the ingame menu. If you've *not* just loaded a game, go to the main menu; else, carry on playing; either way, turn PostLoad off or you'll never be able to go to the main menu. That's just my way of doing it, thanks to you guys. I'm sure others have more sophisticated ways. If you do, I'd love to read/study/steal them.  >:D
Cheers,