Difference between revisions of "Determining location of mouse cursor"
Line 8: | Line 8: | ||
<div class="CodeBlockHeader">Code:</div> | <div class="CodeBlockHeader">Code:</div> | ||
− | <syntaxhighlight lang="sci | + | <syntaxhighlight lang="sci"> |
(instance thing of Act | (instance thing of Act | ||
(properties | (properties | ||
Line 24: | Line 24: | ||
<div class="CodeBlockHeader">Code:</div> | <div class="CodeBlockHeader">Code:</div> | ||
− | <syntaxhighlight lang="sci | + | <syntaxhighlight lang="sci">(instance thingScript of Script |
(properties) | (properties) | ||
(method (doit) | (method (doit) |
Revision as of 12:50, 11 August 2013
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.
(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.
(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.