Author Topic: Events - Specifically first ball.  (Read 1003 times)

dave_h

  • Wizard
  • *****
  • Posts: 185
    • View Profile
Events - Specifically first ball.
« on: August 09, 2015, 01:37:45 AM »
I got stuck pretty hard on this yesterday for some reason.

Added this event from the instructions as I think this is where it should be.
Code: [Select]
def evt_ball_starting(self):
# to use the ball saver, we give it the name of a ball-saver
# method to be called when the ball is saved --that is
# defined below

I'm trying to achieve a message or whatever before the players first ball, that is a skippable intro with flippers. Just couldn't for the life of me get this, I'm going to take an even deeper look again now. Every event part I have tested does pick up
Code: [Select]
if self.game.ball == 1 but doesn't ever wait. I can get my message to show at the right time but the trough is exited without waiting. Did try the return "seconds" to make it wait too.

Code: [Select]
if self.game.ball==1:
self.game.sound.stop_music()
Time = self.game.sound.play('BookPassage')
self.delay('FirstBallDelay',delay=Time,handler=self.FirstBallDelay)
else:
self.startBallAfterDelay()

This is how I'm used to doing it from the base_game_modes "mode_started" and then cancelling "FirstBallDelaytime"with the flippers, which pops ball into shooter lane.



MOcean

  • Moderator
  • ****
  • Posts: 822
  • Michael Ocean
    • View Profile
Events - Specifically first ball.
« Reply #1 on: August 09, 2015, 02:35:17 AM »
Ah, now we're talking about parts of the framework I really like!

Does your function that handles that evt_ return a number? (Specifically the number of seconds to wait for the media to finish?)

From the docs:
Quote
Modes can also request to postpone the event propagation (i.e., the calling of the next event handler) by returning a number of seconds that the mode needs to 'finish up' (e.g., play a special animation or sound) or can delay and stop further propegation by returning a tuple of the delay in seconds and the second entry is True

Bonus mode provides an example of this in action:
https://github.com/mjocean/PyProcGameHD-SkeletonGame/blob/master/procgame/modes/bonusmode.py#L92

If you're already doing this and it's not working, that's not good. The mode does need to be in the mode_queue to get the event.

To handle the skip able part, after returning a positive number, when you detect flippers you can call notifyNextModeNow() as defined here:
https://github.com/mjocean/PyProcGameHD-SkeletonGame/blob/master/procgame/game/skeletongame.py#L439

It's called as:
Code: [Select]
self.game.notifyNextModeNow(caller_mode=self)
Good luck... :)
« Last Edit: August 09, 2015, 02:37:44 AM by MOcean »

dave_h

  • Wizard
  • *****
  • Posts: 185
    • View Profile
Re: Events - Specifically first ball.
« Reply #2 on: August 09, 2015, 02:57:44 AM »
Yes it was just returning a float at the very end of the funtion, just like:
Code: [Select]
if(shoot_again==True):
      return 0

Quote
If you're already doing this and it's not working, that's not good. The mode does need to be in the mode_queue to get the event.

So this could be a problem if I'm running event handler directly inside the base? The other events were already here , but had to add that manually.

Quote
To handle the skip able part, after returning a positive number, when you detect flippers you can call notifyNextModeNow() as defined here:
https://github.com/mjocean/PyProcGameHD-SkeletonGame/blob/master/procgame/game/skeletongame.py#L439

It's called as:
Code: [Select]

self.game.notifyNextModeNow(caller_mode=self)


Good luck...

Nice one thanks. Hopefully that's enough for me to understand it a bit better and should have a better job getting it to work.

dave_h

  • Wizard
  • *****
  • Posts: 185
    • View Profile
Re: Events - Specifically first ball.
« Reply #3 on: August 09, 2015, 03:22:48 AM »
Ok I got it, cheers!. It was only when I spotted "tuple" in your quote.

Quote
further propegation by returning a tuple of the delay in seconds and the second entry is True

So instead of
Code: [Select]
return 6.9
This
Code: [Select]
return 6.9,True

MOcean

  • Moderator
  • ****
  • Posts: 822
  • Michael Ocean
    • View Profile
Events - Specifically first ball.
« Reply #4 on: August 09, 2015, 03:25:39 AM »
The evt's only go to modes, not the game class and those modes need to be subclassed of AdvancedMode. (Or you can manually call notifyOfNewMode for your mode. Look at the AdvancedMode code for details).

I have adding an identical evt_ function handling to the game class on my todo list...

Edit:looks like you've already got it! Nice.

dave_h

  • Wizard
  • *****
  • Posts: 185
    • View Profile
Re: Events - Specifically first ball.
« Reply #5 on: August 09, 2015, 03:31:15 AM »
Code: [Select]
Edit:looks like you've already got it! Nice.
Yeah, thanks mate. I'm glad it didn't take too long to figure out but I feel I would've been stuck without the quote from your summary "SkeletonGame includes:"

I've probably skimmed over that part a few times now and maybe for future use to be added by the event function table? :) Cheers! onwards , upwards.