Advanced Said() Strings - Part 1 and Advanced Use of Control Areas: Difference between pages

From Sierra Wiki
(Difference between pages)
Jump to navigationJump to search
sierraw>Andrew Branscom
 
m 1 revision imported
 
Line 1: Line 1:
=Chapter 1 - Advanced Said() Strings - Part 1=
=Chapter 8 - Advanced use of control areas=


==More About Said Statements==
The main set of SCI tutorials shows that the way to check if the ego is on a particular control area is the following:


This chapter explains some common Said usage patterns that aren't fully explained in the other tutorials.
<blockquote>
<div class="CodeBlockHeader">Code:</div>
<syntaxhighlight lang="sci" class="cs">(instance RoomScript of Script
  (properties)
  (method (doit)
    (if(== (send gEgo:onControl()) ctlGREEN)
      (send gRoom:newRoom(1))
    )
  )
)</syntaxhighlight>
</blockquote>


==="Look" vs. "Look thing"===
If the ego is on GREEN, then he is sent to a new room.


Often, you might want to enclose all your 'look' handlers in one if statement, but still support just "look" all by itself.
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:


<blockquote>
These are defined in sci.sh:
<div class="CodeBlockHeader">Code:</div>
<div class="CodeBlockHeader">Code:</div>
<syntaxhighlight lang="sci">
<syntaxhighlight lang="sci" class="cs">(define ctlBLACK                      $0001)
(if (Said 'look>')
(define ctlNAVY                        $0002)
(if (Said '/wall') (Print {The wall is covered in paint.}))
(define ctlGREEN                      $0004)
(if (Said '/floor') (Print {The floor is covered in dust.}))
(define ctlTEAL                        $0008)
(if (Said '[/!*]') (Print {You are in a room with a floor and a wall.})) ; this will handle just "look" by itself
(define ctlMAROON                      $0010)
(if (Said '/*') (Print {You don't see anything interesting about it.})) ; this will handle "look anyword"
(define ctlPURPLE                      $0020)
)
(define ctlBROWN                      $0040)
</syntaxhighlight>
(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)</syntaxhighlight>
</blockquote>


If you wanted to handle 'look around' just like look, you could do:
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.
 
<blockquote>
To detect if the ego is ''completely'' on one color do the following:
<div class="CodeBlockHeader">Code:</div>
<div class="CodeBlockHeader">Code:</div>
<syntaxhighlight lang="sci">
<syntaxhighlight lang="sci" class="cs">       (if (== (send gEgo:onControl()) ctlGREEN)
(if (Said 'look>')
            // Ego is completely on green (no part of his footprint hits black, even).
(if (Said '/wall') (Print {The wall is covered in paint.}))
        )</syntaxhighlight>
(if (Said '/floor') (Print {The floor is covered in dust.}))
</blockquote>
(if (Said '[/around]') (Print {You are in a room with a floor and a wall.})) ; this will handle just "look" by itself, and also "look around"
(if (Said '/*') (Print {You don't see anything interesting about it.}))
)
</syntaxhighlight>


Note that more specific Said clauses should always come before more general ones.
<blockquote>
 
To detect if some part of the ego's footprint is touching a particular color:
===More complex Said strings===
<div class="CodeBlockHeader">Code:</div>
<syntaxhighlight lang="sci" class="cs">        (if (& (send gEgo:onControl()) ctlGREEN)
            // Part of ego is touching green.
        )</syntaxhighlight>
</blockquote>


Consider the following example:
<blockquote>
To detect if the ego is touching one or more of ctlGREEN and ctlCYAN, do the following:
<div class="CodeBlockHeader">Code:</div>
<div class="CodeBlockHeader">Code:</div>
<syntaxhighlight lang="sci">
<syntaxhighlight lang="sci" class="cs">       (if (& (send gEgo:onControl()) (| ctlGREEN ctlCYAN))
(if (Said 'give/food/dog')
            // Ego is touching green or cyan.
(Print {You give the food to the dog.})
        )</syntaxhighlight>
)
</blockquote>
</syntaxhighlight>


One thing to note is that the order of words in the Said string doesn't necessarily match the order that the words are typed in by the user. There is more meaning to the Said string than that. The above clause will respond positively to the user typing "Give food to the dog", or even "Give dog the food". However, surprisingly (and fortunately), it will not match "Give food the dog". Rather than the particular word order in a sentence, the three parts of the above clause correspond to sentence parts.
<blockquote>
 
To detect if the ego is touching both ctlGREEN and ctlCYAN exclusively, do the following:
Similarly:
<div class="CodeBlockHeader">Code:</div>
<div class="CodeBlockHeader">Code:</div>
<syntaxhighlight lang="sci">
<syntaxhighlight lang="sci" class="cs">       (if (& (send gEgo:onControl()) (| ctlGREEN ctlCYAN))
(if (Said 'point<up/flashlight')
            // Ego is touching green or cyan.
(Print {You point the flashlight up, and see something curious.})
        )</syntaxhighlight>
)
</syntaxhighlight>


This will respond to "point flashlight up", but not "point up flashlight". (Note: FreeSCI may have some bugs here that make it behave differently than the Sierra parser).
Basically, just remember it is a bit-mask, so the '&amp;' and '|' operators are your friends.


That sums up more about said statements.
&nbsp;


==<br /> References ==
<span style="float: left">[[Memory Management|&lt; Previous: Chapter 7 - Memory Management (advanced)]]</span><span style="float: right">[[SCI_Point_and_Click_Tutorial|Next: Cloudee1's SCI Point and Click Tutorial &gt;]]</span>
 
<references />
 
==<br /> Also See ==
 
*
 
&nbsp;


<span style="float: left">[[Advanced_SCI_Tutorials|&lt; Previous: Advanced SCI Tutorials Introductions]]</span>
<span style="float: right">[[Regions and Locales|Next: Chapter 2 - Regions and Locales &gt;]]</span>


&nbsp;
&nbsp;


[[Category:The SCI Parser]]
[[Category:Control Areas]]
[[Category:Examples]]
[[Category:SCI Examples]]
[[Category:Tutorials]]
[[Category:Tutorials]]

Revision as of 00:26, 3 June 2024

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 >