Advanced Use of Control Areas
Chapter 8 - Advanced use of control areas
The main set of SCI tutorials shows that the way to check if the ego is on a particular control area is the following:
Code:(instance RoomScript of Script (properties) (method (doit) (if(== (send gEgo:onControl()) ctlGREEN) (send gRoom:newRoom(1)) ) ) )
If the ego is on GREEN, then he is sent to a new room.
That's only part of the story. The value returned by onControl() is actually a bit mask, which can contain any combination of the following values:
These are defined in sci.sh:
Code:(define ctlBLACK $0001) (define ctlNAVY $0002) (define ctlGREEN $0004) (define ctlTEAL $0008) (define ctlMAROON $0010) (define ctlPURPLE $0020) (define ctlBROWN $0040) (define ctlSILVER $0080) (define ctlGREY $0100) (define ctlBLUE $0200) (define ctlLIME $0400) (define ctlCYAN $0800) (define ctlRED $1000) (define ctlFUCHSIA $2000) (define ctlYELLOW $4000) (define ctlWHITE $8000)
This makes sense, because the 'footprint' of the ego (or any Act class) is actually a two-dimensional area, not a single point. Therefore, he may be on several colors at once.
To detect if the ego is completely on one color do the following:
Code:(if (== (send gEgo:onControl()) ctlGREEN) // Ego is completely on green (no part of his footprint hits black, even). )
To detect if some part of the ego's footprint is touching a particular color:
Code:(if (& (send gEgo:onControl()) ctlGREEN) // Part of ego is touching green. )
To detect if the ego is touching one or more of ctlGREEN and ctlCYAN, do the following:
Code:(if (& (send gEgo:onControl()) (| ctlGREEN ctlCYAN)) // Ego is touching green or cyan. )
To detect if the ego is touching both ctlGREEN and ctlCYAN exclusively, do the following:
Code:(if (& (send gEgo:onControl()) (| ctlGREEN ctlCYAN)) // Ego is touching green or cyan. )Basically, just remember it is a bit-mask, so the '&' and '|' operators are your friends.
< Previous: Chapter 7 - Memory Management (advanced)Next: Cloudee1's SCI Point and Click Tutorial >