Please login or register.

Login with username, password and session length
Advanced search  

News:

This forum provides RSS feed. To query recent posts use this url. More...


Author Topic: Load window on Keypress  (Read 5230 times)

0 Members and 1 Guest are viewing this topic.

TheDerman

  • Regular poster
  • ***
  • Karma: 0
  • Offline Offline
  • Posts: 225
    • View Profile
Load window on Keypress
« on: December 09, 2007, 05:18:37 AM »

Hey all,

How can I load a window when I press F5 at any point in the game?

I tried to add to the "Keypress" section of game.script.

I added:

if(Keyboard.KeyCode==VK_F5)
{
...
}

...after the escape key code, but it won't load my window.

Do I need to do something else?

Thanks.
Logged

TheDerman

  • Regular poster
  • ***
  • Karma: 0
  • Offline Offline
  • Posts: 225
    • View Profile
Re: Load window on Keypress
« Reply #1 on: December 09, 2007, 08:50:31 AM »

Ok - I sorted that problem - just forgot some ()   :-[

But now I want the window to close down when you press F5 for a second time, so I have this isn my window script:

Code: WME Script
  1. ////////////////////////////////////////////////////////////////////////////////
  2. on "Keypress"
  3. {
  4.   if(Keyboard.KeyCode==VK_F5) self.Close();
  5. }
  6.  

But it doesn't work. Is that wrong?

Thanks.
Logged

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: Load window on Keypress
« Reply #2 on: December 09, 2007, 09:24:57 AM »

It should work, as long as the window is exclusive.
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

TheDerman

  • Regular poster
  • ***
  • Karma: 0
  • Offline Offline
  • Posts: 225
    • View Profile
Re: Load window on Keypress
« Reply #3 on: December 09, 2007, 09:34:09 AM »

Well I have tried it, GoExclusive and GoSystemExclusive, but it still won't close the window down.  :(
Logged

TheDerman

  • Regular poster
  • ***
  • Karma: 0
  • Offline Offline
  • Posts: 225
    • View Profile
Re: Load window on Keypress
« Reply #4 on: December 09, 2007, 09:53:46 AM »

These are my scripts:

game.script

Code: WME Script
  1. ////////////////////////////////////////////////////////////////////////////////
  2. on "Keypress"
  3. {
  4. if(Keyboard.KeyCode==VK_F5)
  5.   {
  6.    var MyWindow = Game.LoadWindow("windows\MyWindow\MyWindow.window");
  7.    MyWindow.Center();
  8.    MyWindow.GoExclusive();
  9.    Game.UnloadObject(MyWindow);
  10.   }
  11. }
  12.  


MyWindow.window

Code: WME Script
  1. WINDOW
  2. {
  3.   X = 348
  4.   Y = 266
  5.   WIDTH = 328
  6.   HEIGHT = 237
  7.   NAME = "my_window"
  8.   IMAGE = "windows\MyWindow\MyWindow.jpg"
  9.   SCRIPT = "windows\MyWindow\MyWindow.script"
  10.   PAUSE_MUSIC = FALSE
  11.  
  12.   EDIT
  13.   {
  14.     NAME = "my_editor"
  15.         FONT = "fonts\sserif.font"     
  16.         CURSOR = "sprites\system\text_select_windows_mouse_cursor.sprite"
  17.     X = 68
  18.     Y = 130
  19.     WIDTH = 194
  20.     HEIGHT = 20
  21.     FRAME_WIDTH = 2
  22.         TEXT = ""
  23.         PARENT_NOTIFY = TRUE
  24.   }   
  25.  
  26.   BUTTON
  27.   {
  28.     PARENT_NOTIFY = TRUE
  29.         NAME = "ok"
  30.         IMAGE = "windows\MyWindow\MyWindow_ok_up.jpg"
  31.         IMAGE_PRESS = "windows\MyWindow\MyWindow_ok_down.jpg"
  32.     X = 125
  33.     Y = 193
  34.         WIDTH = 77
  35.     HEIGHT = 26
  36.   }
  37. }
  38.  


MyWindow.script

Code: WME Script
  1. #include "scripts\base.inc"
  2. #include "scripts\keys.inc"
  3.  
  4. var MyEditor = this.GetControl("my_editor");
  5.  
  6. ////////////////////////////////////////////////////////////////////////////////
  7. on "ok"
  8. {
  9.   do stuff
  10. }
  11.  
  12. ////////////////////////////////////////////////////////////////////////////////
  13. on "Keypress"
  14. {
  15.   if(Keyboard.KeyCode==VK_F5) self.Close();
  16. }
  17.  
Logged

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: Load window on Keypress
« Reply #5 on: December 09, 2007, 04:31:28 PM »

I don't see anything obviously wrong, IMO it should work. That's pretty much what all the windows in WME demos do, to handle the Escape key...
Try adding Game.Msg("something"); to the beginning of the script and to the Keypress handler to see if the script gets executed and if the event handler is triggered.
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

TheDerman

  • Regular poster
  • ***
  • Karma: 0
  • Offline Offline
  • Posts: 225
    • View Profile
Re: Load window on Keypress
« Reply #6 on: December 09, 2007, 08:11:33 PM »

Tried that but it still didn't work.  :(

Curously though if I just put Game.Msg("Something."), in the window script under "Keypress" and LEAVE OUT the if(Keyboard...) etc. I get the game message when I then press the Escape key.

What's that about? Is there something I don't understand about these windows?

Thanks.
Logged

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: Load window on Keypress
« Reply #7 on: December 09, 2007, 10:07:21 PM »

Ok, I know what's the problem. Your window contains an editor control, which is focused and eats the key presses. This is an issue, the editor should only eat the keys it can handle and pass the other ones back to the window. I'm adding it to my todo list.
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

TheDerman

  • Regular poster
  • ***
  • Karma: 0
  • Offline Offline
  • Posts: 225
    • View Profile
Re: Load window on Keypress
« Reply #8 on: December 09, 2007, 10:14:30 PM »

Those greedy editor controls, eating everything they want.  ;D

That's cool - the window wasn't for anything important anyway - so I just added a normal "close" button.  8)
Logged
 

Page created in 0.113 seconds with 24 queries.