Community
SCI Programming => SCI Syntax Help => Topic started by: robbo007 on December 26, 2023, 09:09:32 PM
-
Hi guys,
Is it possible using the SCI0 template to use the right click mouse button on things to get a look description like what they did with QFG2? What code is involved? How do you link this to your handleEvents etc?
Thanks,
-
Yes, you can do this in SCI0 (it works in Codename: ICEMAN, for example). The implementation there is much simpler, too.
-
Thanks. I was looking through the source code to try and work where its declaring this. I see for example in Room 10 the Hotel lobby, the fish picture on the wall. They are using a RPicView and the handleEvent is declared there also. Does it have something to do with that? I can't see anything else that would refer to a mouse click on the view or part of screen?
(instance picturePic of RPicView
(properties
y 124
x 43
z 30
view 10
loop 2
priority 5
)
(method (handleEvent event)
(cond
((super handleEvent: event))
((Said '[/painting,(wall<left)]>')
(cond
((TurnIfSaid self event 'look/*'))
((Said 'look[<at]')
(Print 10 3) ; "There is a picture of a Humuhumunukunukuapua'a on the wall."
)
)
)
)
)
)
-
I saw this recently in Laura Bow 1.
In the starting room rm44 (https://github.com/sluicebox/sci-scripts/blob/c6fac2fa6806adb9e913f6cce8d47723a8932afc/cb-dos-1.000.046/src/Room44.sc#L566) they use a combination of the MousedOn and DoLook procedures:
(instance sofa of RPicView
(properties
y 169
x 172
view 144
cel 1
priority 13
signal 16384
)
(method (handleEvent event)
(if (MousedOn self event 3) ;3 == rightClick
(event claimed: 1)
(DoLook {couch})
)
)
)
MousedOn is defined in Interface.sc (https://github.com/sluicebox/sci-scripts/blob/c6fac2fa6806adb9e913f6cce8d47723a8932afc/cb-dos-1.000.046/src/Interface.sc#L29) (script 255):
(procedure (MousedOn obj event theMods)
(cond
((!= (event type:) 1) 0)
((and (>= argc 3) theMods (== (& (event modifiers:) theMods) 0)) 0)
((obj respondsTo: #nsLeft)
(InRect
(obj nsLeft:)
(obj nsTop:)
(obj nsRight:)
(obj nsBottom:)
event
)
)
)
)
And DoLook is defined in Main.sc (https://github.com/sluicebox/sci-scripts/blob/c6fac2fa6806adb9e913f6cce8d47723a8932afc/cb-dos-1.000.046/src/Main.sc#L753):
(procedure (DoLook param1 &tmp temp0)
(StrCpy (User inputLineAddr:) {Look })
(StrCat (User inputLineAddr:) param1)
((= temp0 (Event new:)) type: evSAID)
(Parse (User inputLineAddr:) temp0)
(User said: temp0)
(temp0 dispose:)
)
Hope that helps a little.
Edit: In case it's not obvious, this simulates the player typing LOOK COUCH, so it also requires (Said 'look/couch') to exist as well. In this specific case that exists in the region associated with rm44, insideReg.sc (https://github.com/sluicebox/sci-scripts/blob/c6fac2fa6806adb9e913f6cce8d47723a8932afc/cb-dos-1.000.046/src/insideReg.sc) (script 210), but it would be easier just to include it in the Sofa's handleEvent method before or after the MousedOn check.
Also, I might be misremembering, but I recall the difference between RPicView and the PicView in older SCI0 games is PicView doesn't respond to nsLeft. You might need to port RPicView into your project as well.
-
Here's what I do in Betrayed Alliance. It might not be the most efficient code, but it works for me well enough.
First I will make a procedure:
(procedure (checkEvent pEvent x1 x2 y1 y2)
(if
(and
(> (pEvent x?) x1)
(< (pEvent x?) x2)
(> (pEvent y?) y1)
(< (pEvent y?) y2)
)
(return TRUE)
else
(return FALSE)
)
)I will reference this procedure in the handleEvent method in this way:
(if (== (pEvent type?) evMOUSEBUTTON)
(if (& (pEvent modifiers?) emRIGHT_BUTTON)
(if (checkEvent pEvent 92 123 65 117) ; clicked within the box of these coordinates
(PrintOther 18 6)
) You can also reference the coordinates of a view this way:
(checkEvent pEvent (mapItem nsLeft?) (mapItem nsRight?) (mapItem nsTop?) (mapItem nsBottom?))
(PrintOther 18 24)
)You can also check to see if the click happened on a control color:
(if
(== ctlGREY (OnControl ocSPECIAL (pEvent x?) (pEvent y?)))
(PrintOther 18 77)
)Or on a priority color:
(if
(== ctlYELLOW (OnControl ocPRIORITY (pEvent x?) (pEvent y?)))
(PrintOther 18 78)
)This is what works for me. Perhaps when I start a new project, I'll look into having something more global, but this does the trick for now,