Community
SCI Programming => SCI Syntax Help => Topic started by: gumby on March 10, 2013, 12:23:20 PM
-
I'm attempting to create events programatically (keypresses & mouse clicks) but not having any success.
My thought is that this code should create a new mouse event where location (30,30) is left clicked which should move the ego to that location:
(if(Said('look'))
(= hEvent Event:new())
(send hEvent:
type(evMOUSEBUTTON)
x(30)
y(30)
modifiers(512) // 512 left click, 515 right click
claimed(FALSE)
)
(super:handleEvent(hEvent))
)
But it's not working, nothing seems to happen. I've got it placed in a template game in the Rm001 script.
Here's a simpler event that should fire a keyboard event (ALT-M) and trigger the easy-alt debugging that displays the available memory, but doesn't work either:
(send hEvent:
type(evKEYBOARD)
message($3200)
claimed(FALSE)
)
Is this even possible to do? I suspect that I'm creating the event properly, but maybe the handleEvent call is incorrect?
-
Well, I figured it out for mouse events:
(= myEvent Event:new())
(send myEvent:
type(evMOUSEBUTTON)
x(30)
y(30)
modifiers(512) // 512 left click, 515 right click
claimed(FALSE)
)
(send gEgo:handleEvent(myEvent))
(send myEvent:dispose())
I had to change it so that the ego event handler processed the event. Haven't got keyboard events working yet.
EDIT: Keyboard events work too, just call a different event handler.
(= myEvent Event:new())
(send myEvent:
type(evKEYBOARD)
message($3200)
claimed(FALSE)
)
(send gGame:handleEvent(myEvent))
(send myEvent:dispose())
Makes sense now, I just needed to send the events to the correct objects. Oh yeah, and we need to remember to dispose of our event when we are done
-
For simulating parser events:
(send myEvent:
type(evKEYBOARD)
message("hello") // the 'said' string you want to pass in
modifiers(999) // arbitrary modifier value, we'll check for this in user.sc
claimed(FALSE)
)
(User:handleEvent(myEvent))
(send myEvent:dispose())
And then modify the user.sc code to look like this:
...
(if(canInput and not(send pEvent:claimed))
(if( (== (send pEvent:message) echo) or (<= $20 (send pEvent:message)) and (<= (send pEvent:message) 255))
(if( (self:getInput(pEvent)) and Parse(@inputStr pEvent))
(send pEvent:type(evSAID))
(self:said(pEvent))
)
)
// add this section here
(if( (== (send pEvent:modifiers) 999))
StrCpy(@inputStr (send pEvent:message))
(if(Parse(@inputStr pEvent))
(send pEvent:type(evSAID))
(self:said(pEvent))
)
)
)
...
There may be a better way to do this. Basically, all I did was put the said string into the message property then set the modifiers to 999 (an arbitrary value). Then in the user.sc & specifically look for the 999 modifier and shove the message text into the inputStr variable & do the parse.