Determining location of mouse cursor

From SCI Wiki
Jump to: navigation, search

By Cloudee1

This is a question that I recently asked at Mega-Tokyo in which Troflip was good enough to write up some code illustrating that exact functionality. This is a little snippet of code which I had hoped Troflip could enter here, but as he has not signed up yet and I really didn't want to lose this snippet as I plan to find a use for it, I have moved it here.

Troflip's code to get a view to follow the cursor broken up with small explanations added by me.

We first need to create an instance of an Actor, it needs to be an actor so that it can move around the screen. An init method has been included in the instance telling the actor to do what that script says.

Code:
(instance thing of Act
   (properties
      x 100
      y 100
      view 800
   )
   (method (init)
      (super:init())
      (self:setScript(thingScript))
   )
)

Now that the instance is complete, we also need to create the script which the instances init method references.

Code:
(instance thingScript of Script
   (properties)
   (method (doit)
      (var myEvent)
      (super:doit())
      (= myEvent Event:new(evNULL))
      (send client:setMotion(MoveTo (send myEvent:x) (send myEvent:y)))
      (send myEvent:dispose())
   )
)

...and then of course do (thing:init()) in your room's init method.