Author Topic: How to dismiss a message?  (Read 4815 times)

durnurd

  • Lead Lemming
  • Expert
  • Fanatic
  • *****
  • Posts: 1234
  • Games completed so far: 0
    • MSN Messenger - durnurd@hotmail.com
    • View Profile
    • Find My Ed
How to dismiss a message?
« on: 2008-12-14, 11:58:29 AM »
I'm trying to display a message when the player is within a plan and presses button 1.  Then, to dismiss it, they press button 1 again.  However, since the player is still in the plan, the message shows up again.  Is there a method to get around this silliness?
Edward Dassmesser

bluemonkmn

  • SGDK Author
  • Administrator
  • Fanatic
  • *****
  • Posts: 2761
    • ICQ Messenger - 2678251
    • MSN Messenger - BlueMonkMN@gmail.com
    • View Profile
    • http://sgdk2.sf.net/
    • Email
Re: How to dismiss a message?
« Reply #1 on: 2008-12-15, 09:13:28 AM »
Isn't there a "WasTouching" function that determines whether the player was touching the plan before versus just started touching it?

durnurd

  • Lead Lemming
  • Expert
  • Fanatic
  • *****
  • Posts: 1234
  • Games completed so far: 0
    • MSN Messenger - durnurd@hotmail.com
    • View Profile
    • Find My Ed
Re: How to dismiss a message?
« Reply #2 on: 2008-12-15, 01:17:35 PM »
I don't want the message to show up when they first touch the plan.  If they're inside the plan, and the message is not showing, and they press button 1, show it.  If the message IS showing, hide it.
Edward Dassmesser

SmartBoy16

  • Contributor
  • Fanatic
  • **
  • Posts: 587
  • Looking for inspiration.....
    • View Profile
    • Email
Re: How to dismiss a message?
« Reply #3 on: 2008-12-15, 01:52:39 PM »
initial touch only? (SGDK1 terms) or else only appears when you press (1)
Looking to the skies.....

dutch_619

  • Regular
  • **
  • Posts: 90
    • View Profile
    • Email
Re: How to dismiss a message?
« Reply #4 on: 2008-12-15, 05:26:34 PM »
Or add a counter set to 0 initially that increments on running of the rule, then have the message only run when the counter is = to 0.

bluemonkmn

  • SGDK Author
  • Administrator
  • Fanatic
  • *****
  • Posts: 2761
    • ICQ Messenger - 2678251
    • MSN Messenger - BlueMonkMN@gmail.com
    • View Profile
    • http://sgdk2.sf.net/
    • Email
Re: How to dismiss a message?
« Reply #5 on: 2008-12-16, 06:40:34 AM »
I don't want the message to show up when they first touch the plan.  If they're inside the plan, and the message is not showing, and they press button 1, show it.  If the message IS showing, hide it.

In that case, don't you just need to turn on the "InitialOnly" option of the "IsInputPressed" function?  Or is your problem determining that the message is already showing?  Can you use a map flag for that?

durnurd

  • Lead Lemming
  • Expert
  • Fanatic
  • *****
  • Posts: 1234
  • Games completed so far: 0
    • MSN Messenger - durnurd@hotmail.com
    • View Profile
    • Find My Ed
Re: How to dismiss a message?
« Reply #6 on: 2008-12-16, 08:40:01 AM »
My thought was that this really shouldn't need to be complicated.  My suggestion: when displaying a message that has freezeInputs selected, don't change oldInputs.  Then, when the message disappears, copy the input state as it was when the message displayed into oldInputs.  This may seem more complicated up front, but you only have to do it once.

Or, if that doesn't appeal to you, just copy the current inputs into oldInputs when the message is dismissed.  This makes sense in any case, whether the message input handling happens before or after the sprite handling.
Edward Dassmesser

durnurd

  • Lead Lemming
  • Expert
  • Fanatic
  • *****
  • Posts: 1234
  • Games completed so far: 0
    • MSN Messenger - durnurd@hotmail.com
    • View Profile
    • Find My Ed
Re: How to dismiss a message?
« Reply #7 on: 2008-12-16, 04:25:17 PM »
I just noticed that this could be a problem, because the message doesn't know what sprite, if any, it's freezing.  Still, there's got to be a simpler way.
Edward Dassmesser

bluemonkmn

  • SGDK Author
  • Administrator
  • Fanatic
  • *****
  • Posts: 2761
    • ICQ Messenger - 2678251
    • MSN Messenger - BlueMonkMN@gmail.com
    • View Profile
    • http://sgdk2.sf.net/
    • Email
Re: How to dismiss a message?
« Reply #8 on: 2008-12-16, 07:56:36 PM »
OK, I didn't fully understand the problem before, but now I do.  One solution is to use a different button to trigger the message than you use to dismiss the message :).
It also seems to work if you cut the "inputs = 0" line in SpriteBase.MapPlayerToInputs and paste it inside the if block below.  Whaddya think, is that a sound solution?

bluemonkmn

  • SGDK Author
  • Administrator
  • Fanatic
  • *****
  • Posts: 2761
    • ICQ Messenger - 2678251
    • MSN Messenger - BlueMonkMN@gmail.com
    • View Profile
    • http://sgdk2.sf.net/
    • Email
Re: How to dismiss a message?
« Reply #9 on: 2008-12-17, 07:19:06 AM »
OK, that's no good either because if you're moving while you trigger the message, you won't stop moving until you dismiss it.  Here's my "final answer" - change GeneralRules.cs:
Replace the declaration of dismissReleased with
Code: [Select]
private static byte[] dismissPhase = null;

Replace the code after dismissPressed is set and before FreezeInputs is checked in PlayerPressButton with:
Code: [Select]
// dismissPhase[x]:
// 0 = No frames have passed yet
// 1 = Frames have passed and the dismiss button was initially pressed
// 2 = Frames have passed and the dismiss button is not pressed
// 3 = Dismiss button was not pressed, but now it is.

if (dismissPhase == null)
   dismissPhase = new byte[Project.MaxPlayers];

if (dismissPressed)
{
   if ((dismissPhase[msg.player] == 0) || (dismissPhase[msg.player] == 2))
      dismissPhase[msg.player]++;
}
else
{
   if (dismissPhase[msg.player] < 2)
      dismissPhase[msg.player] = 2;
   else if (dismissPhase[msg.player] > 2)
   {
      DismissMessage(i);
      dismissPhase[msg.player] = 0;
   }
}

durnurd

  • Lead Lemming
  • Expert
  • Fanatic
  • *****
  • Posts: 1234
  • Games completed so far: 0
    • MSN Messenger - durnurd@hotmail.com
    • View Profile
    • Find My Ed
Re: How to dismiss a message?
« Reply #10 on: 2008-12-17, 08:46:56 AM »
woo, yay, and such
Edward Dassmesser