Author Topic: Trying to Hijack the eventHandler  (Read 4415 times)

0 Members and 1 Guest are viewing this topic.

Offline Cloudee1

Trying to Hijack the eventHandler
« on: December 14, 2015, 09:58:00 PM »
Ok, so seriously I am at a head scratching loss here...

My goal is to add in the skimmer arcade sequence. To start that off, I need to be able to log the keyboard input and respond accordingly. However I am beyond failing, instead I am failing and getting weird results while doing it. Anyway, where I am at right now... Basically I have an empty room and I have included an handleEvent method. My goal here was simply to start off catching the events and then move up to actually doing something with them.

Code: [Select]
//*****************************************************************************
(version 2)                                          //  Ulence Flats - Skimmer
//*****************************************************************************
(include "sci.sh")(include "game.sh")(include "94.shm")             (script 94)
//*****************************************************************************
(exports
0 rm094
)
//*****************************************************************************
(use "Cycle")(use "Feature")(use "Game")(use "Main")(use "Obj")(use "View")
(use "Print")
//*****************************************************************************
(instance public rm094 of Rm
(properties
picture scriptNumber
west 95
)
  (method (init)
  (super:init())


  )// end method
//*****************************************************************************
  (method (handleEvent pEvent)
  (var myEventType,myEventMessage)
    = myEventType (send pEvent:type)
    = myEventMessage (send pEvent:message)
  (switch ((send pEvent:message))
  (case KEY_TAB (Print:addText("Tab Key")init()))
  (case KEY_a (Print:addText("Lowercase a")init()))
  (case JOY_RIGHT (Print:addText("Right Arrow")init()))
  (default FormatPrint("%3d  %3d" myEventType myEventMessage))
)
 
  (send pEvent:claimed(1))
  )// end method
)
//*****************************************************************************
However, when I press the tab key, I still get the standard inventory response. Likewise when I press an arrow key it moves the cursor. When I press the a button, nothing happens... and here is the really weird part, when the cursor is the walk cursor and I left click anywhere on the screen, I get the "Right Arrow" response.

My ultimate goal here is to ditch the ego for this room and just control an actor by pressing the right or left arrow keys... however I seem to be further away from that than when I started lol.


Halloween Competition Brass Lantern Prop Competition Groundhog Day Competition

Offline troflip

Re: Trying to Hijack the eventHandler
« Reply #1 on: December 14, 2015, 10:18:44 PM »
This happens to me too. Interesting. I guess events are handled differently in SCI1.1. It looks like the room's handleEvent isn't automatically called. Time for some investigation.

[edit:] Looking at SQ5 code, it seems rooms with their own handle event have this in their room's init:

      (send gOldKH:addToFront(self))
      (send gOldMH:addToFront(self))

Basically, adding themselves to global keyboard handlers and mouse handlers. (you may have already renamed those global variables if you've been keeping your template game up to date).  So maybe try that?
« Last Edit: December 14, 2015, 10:20:50 PM by troflip »
Check out my website: http://icefallgames.com
Groundhog Day Competition

Offline lskovlun

Re: Trying to Hijack the eventHandler
« Reply #2 on: December 14, 2015, 10:31:36 PM »
You had to do that in SCI0 too, at least for some things. I remember writing a keypad class that did this.

Offline Cloudee1

Re: Trying to Hijack the eventHandler
« Reply #3 on: December 14, 2015, 11:17:21 PM »
Yes, that helped a lot. However, I am still struggling to get the arrow keys to do what I want them to do.

In sci0, the arrow keys were actually mapped to joystick events, and in our current environment, it looks like I would need to include   (send gOldDH:addToFront(self)) as  well to add my rooms Direction Handler in before the rest, however, using the arrow keys doesn't really control direction in our current template does it? It handles moving the cursor around... I suspect that it is the pseudomouse that is still hanging me up here and registering the event instead of letting my script.

Just for the record, here is where I am at now...
Code: [Select]
//*****************************************************************************
(version 2)                                          //  Ulence Flats - Skimmer
//*****************************************************************************
(include "sci.sh")(include "game.sh")(include "94.shm")             (script 94)
//*****************************************************************************
(exports
0 rm094
)
//*****************************************************************************
(use "Cycle")(use "Feature")(use "Game")(use "Main")(use "Obj")(use "View")
(use "Print")
//*****************************************************************************
(instance public rm094 of Rm
(properties
picture scriptNumber
)
  (method (init)
  (super:init())
  (self:setScript(RoomScript))
      (send gOldWH:addToFront(self))
      (send gOldKH:addToFront(self))
      (send gOldMH:addToFront(self))
      (send gOldDH:addToFront(self))
     
      (send gIconBar:disable())
  )// end method
)
//*****************************************************************************
(instance RoomScript of Script
(properties)
  (method (handleEvent pEvent)
  (var myEventType,myEventMessage)
 
    = myEventType (send pEvent:type)
    = myEventMessage (send pEvent:message)
   
  (switch ((send pEvent:message))
  (case KEY_TAB (Print:addText("Tab Key")init()))
  (case KEY_a (Print:addText("Lowercase a")init()))
  (case KEY_6 (Print:addText("Right Arrow, Numpad, numLock On")init()))
  (case JOY_RIGHT (Print:addText("Right Arrow")init()))
  (case KEY_SPACE (Print:addText("Space Bar")init()))
  (default FormatPrint("%3d  %3d" myEventType myEventMessage))
)

  (send pEvent:claimed(1))
  )// end method
)

I can do most things and actually get the event and message to display via my switch, but like I said, apparently the arrow keys do not fall under any of these handlers, as it is still showing the default usage rather than getting caught by my default switch statement
« Last Edit: December 14, 2015, 11:38:44 PM by Cloudee1 »
Halloween Competition Brass Lantern Prop Competition Groundhog Day Competition

Offline troflip

Re: Trying to Hijack the eventHandler
« Reply #4 on: December 14, 2015, 11:58:26 PM »
That's odd. I get the arrows keys in my handleEvent if I do that. (and set claimed to TRUE to prevent handling by PseudoMouse).
Check out my website: http://icefallgames.com
Groundhog Day Competition

Offline Cloudee1

Re: Trying to Hijack the eventHandler
« Reply #5 on: December 15, 2015, 12:08:55 AM »
I was able to finally get something to happen...

Once I added this to my init area
      (send gUser:mapKeyToDir(0))

I was able to trigger a response from my print type and message default statement.
No idea what the value I am looking for that corresponds with 197124 and 192004 but apparently the arrow keys correspond to the KEY_NUMPADx values defined in keys.sh as I can now print left arrow and right arrow to the screen...

      (case KEY_NUMPAD6 (Print:addText("Right Arrow")init()))
      (case 197124 (Print:addText("Right Arrow")init()))
      (case KEY_NUMPAD4 (Print:addText("Left Arrow")init()))
      (case 192004 (Print:addText("Left Arrow")init()))



Halloween Competition Brass Lantern Prop Competition Groundhog Day Competition

Offline troflip

Re: Trying to Hijack the eventHandler
« Reply #6 on: December 15, 2015, 12:22:20 AM »
Those numbers aren't valid 16-bit numbers (note to self: file a bug so that doesn't compile). Where did you get them from?

If it was from printing them with FormatPrint (or Printf, whatever we're calling it now), use %x to the get hex value. If you use %d to get the decimal value, and the number is higher than 32767 (highest 16-bit signed number), the interpreter behaves... badly. In fact, it can cause crashes and weird behavior.
Check out my website: http://icefallgames.com
Groundhog Day Competition

Offline Cloudee1

Re: Trying to Hijack the eventHandler
« Reply #7 on: December 15, 2015, 07:08:50 AM »
It never registered the key presses via the 197124 or 192004 cases, but using the %x in a FormatPrint instead of %d, shows that they should be $4B00 and $4D00.

Looking at the keys.sh file
  (define KEY_NUMPAD4        $4B00)
  (define KEY_NUMPAD6        $4D00)
  (define KEY_LEFT              $4B00)
  (define KEY_RIGHT           $4D00)

It explains why using the key numpad values did return a response when I pressed an arrow key, since those sets of keys are equivalent, at least after I quit mapping keys to directions. Strange though that using the Joystick Directions never triggered. Oh well, my problem is now officially solved, I can go about programming this sequence now.

So here it is, my starting point. Just marking the keypress of the left and right arrows, and marking all other events as claimed. FYI, even with handsOff, the game still registers the key presses.

Code: [Select]
//*****************************************************************************
(version 2)                                          //  Ulence Flats - Skimmer
//*****************************************************************************
(include "sci.sh")(include "game.sh")(include "94.shm")             (script 94)
//*****************************************************************************
(exports
0 rm094
)
//*****************************************************************************
(use "Cycle")(use "Feature")(use "Game")(use "Main")(use "Obj")(use "View")
(use "Print")
//*****************************************************************************
(instance public rm094 of Rm
(properties
picture scriptNumber
)
  (method (init)
  (super:init())
      (send gOldKH:addToFront(self))
      (send gOldMH:addToFront(self))
     
      (send gIconBar:disable())
      (send gUser:mapKeyToDir(FALSE))
      (send gGame:handsOff())
  )// end method
  (method (handleEvent pEvent)
  (var myEventType,myEventMessage)
 
    = myEventType (send pEvent:type)
    = myEventMessage (send pEvent:message)
   
  (switch (myEventMessage)
  (case KEY_6 (Print:addText("Right Arrow, Numpad, numLock On")init()))
  (case KEY_RIGHT (Print:addText("Right Arrow")init())) 
  (case KEY_4 (Print:addText("Left Arrow, Numpad, numLock On")init()))
  (case KEY_LEFT (Print:addText("Left Arrow")init()))
)

  (send pEvent:claimed(TRUE))
  )// end method
)
« Last Edit: December 15, 2015, 07:19:55 AM by Cloudee1 »
Halloween Competition Brass Lantern Prop Competition Groundhog Day Competition

Offline Kawa

Re: Trying to Hijack the eventHandler
« Reply #8 on: December 15, 2015, 08:06:49 AM »
Awesome.

Offline MusicallyInspired

Re: Trying to Hijack the eventHandler
« Reply #9 on: December 15, 2015, 09:22:08 AM »
Good stuff to know! It's interesting to note that few (if any) SCI1+ games use the keyboard even for arcade sequences. Even SQ1VGA uses the mouse to move the skimmer. Of course, we see here that it's still possible, but it seems like Sierra was really trying to push mouse interactivity for everything.
Brass Lantern Prop Competition

Offline Cloudee1

Re: Trying to Hijack the eventHandler
« Reply #10 on: December 15, 2015, 10:06:33 AM »
I have really been avoiding looking at the sierra source for anything other than syntax. Part of the fun of this is figuring out how to do something myself... even if I do need the bit of occasional guidance, and more often than not I take the really long way around to achieving something.
Halloween Competition Brass Lantern Prop Competition Groundhog Day Competition

Offline MusicallyInspired

Re: Trying to Hijack the eventHandler
« Reply #11 on: December 15, 2015, 10:25:49 AM »
Yeah, it was fun figuring out how to do things by yourself. A neat exercise would be to take something a little complicated that Sierra did and try to replicate, then see how they did it afterward and see how close you came, or better yet, if you came up with something that worked better than what Sierra did (thought doubtful lol).

Your LSL2 Reloaded project was an interesting experiment with this idea, Cloudee.
Brass Lantern Prop Competition


SMF 2.0.19 | SMF © 2021, Simple Machines
Simple Audio Video Embedder

Page created in 0.151 seconds with 24 queries.