<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>http://sciwiki.sierrahelp.com/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Rob+Craig</id>
	<title>SCI Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="http://sciwiki.sierrahelp.com/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Rob+Craig"/>
	<link rel="alternate" type="text/html" href="http://sciwiki.sierrahelp.com/index.php/Special:Contributions/Rob_Craig"/>
	<updated>2026-11-04T11:13:07Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.35.9</generator>
	<entry>
		<id>http://sciwiki.sierrahelp.com/index.php?title=Custom_Slider_Controls&amp;diff=16030</id>
		<title>Custom Slider Controls</title>
		<link rel="alternate" type="text/html" href="http://sciwiki.sierrahelp.com/index.php?title=Custom_Slider_Controls&amp;diff=16030"/>
		<updated>2023-06-01T08:47:57Z</updated>

		<summary type="html">&lt;p&gt;Rob Craig: /* The Slider View */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Chapter 9 - Creating Custom Slider Controls=&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div align=&amp;quot;right&amp;quot;&amp;gt;&amp;#039;&amp;#039;&amp;lt;nowiki&amp;gt;*&amp;lt;/nowiki&amp;gt; Requires SCI Studio 2.12 or higher&amp;#039;&amp;#039;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
By default, the slider control is drawn with a simple DText control. It draws character 6 for the filled in area, and character 7 for the white area. However, with some creative coding, they can be easily customized. This tutorial continues the &amp;quot;[[Custom Buttons|Creating Custom Windows]]&amp;quot; chapter and will teach you how to create gauges with views!&lt;br /&gt;
&lt;br /&gt;
===Load The Game===&lt;br /&gt;
&lt;br /&gt;
First you need to open your game in SCI Studio, loading the Resource Explorer.&lt;br /&gt;
&lt;br /&gt;
===The Slider View===&lt;br /&gt;
&lt;br /&gt;
First the gauge will need a view so there&amp;#039;s something to draw. I&amp;#039;ve set up one up to save you time, but it can be easily customized to create your own custom theme.&lt;br /&gt;
&lt;br /&gt;
The cels are 8x16 pixels. This is a perfect size. If they were any wider, the window would fill the screen.&lt;br /&gt;
&lt;br /&gt;
To save time, [http://sierrahelp.com/Files/SCI/view.902 click here] and download it for Studio Script. For Sierra Script please use: &lt;br /&gt;
&lt;br /&gt;
Add the view to the game. I chose to number it view.902, but it can be numbered anything you like.&lt;br /&gt;
&lt;br /&gt;
===Scripting The Custom Slider Control===&lt;br /&gt;
&lt;br /&gt;
Basically, all you need to do is remove the DText txtGauge from the script, adjust the positioning of the DButton btnHigher, and create a custom draw handler. However, since there is a lot that needs to be changed, [http://sierrahelp.com/Files/SCI/gauge.sc click here] to download the script.&lt;br /&gt;
&lt;br /&gt;
Overwrite the existing gauge.sc script in your /src directory, open in in the script editor and then compile it. When done, you will have a custom gauge! You can modify the view to your liking.&lt;br /&gt;
&lt;br /&gt;
&amp;amp;nbsp;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p align=&amp;quot;center&amp;quot;&amp;gt;Run the game all you&amp;#039;ll see your brand new custom slider control!&amp;lt;br /&amp;gt;[[Image:Controls-Slider.png|Custom Control Slider]]&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
That sums it up!&lt;br /&gt;
&lt;br /&gt;
&amp;amp;nbsp;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;float: left&amp;quot;&amp;gt;[[Custom Windows|&amp;amp;lt; Previous: Chapter 8 - Creating Custom Windows]]&amp;lt;/span&amp;gt;&amp;lt;span style=&amp;quot;float: right&amp;quot;&amp;gt;[[Advanced_SCI_Tutorials|Next: Phil Fortier&amp;#039;s Advanced SCI Tutorials &amp;amp;gt;]]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;amp;nbsp;&lt;br /&gt;
&lt;br /&gt;
[[Category:Controls]]&lt;br /&gt;
[[Category:Tutorials]]&lt;/div&gt;</summary>
		<author><name>Rob Craig</name></author>
	</entry>
	<entry>
		<id>http://sciwiki.sierrahelp.com/index.php?title=Custom_Buttons&amp;diff=16029</id>
		<title>Custom Buttons</title>
		<link rel="alternate" type="text/html" href="http://sciwiki.sierrahelp.com/index.php?title=Custom_Buttons&amp;diff=16029"/>
		<updated>2023-06-01T08:46:23Z</updated>

		<summary type="html">&lt;p&gt;Rob Craig: /* Scripting The Button */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Chapter 7 - Creating Custom Buttons=&lt;br /&gt;
&lt;br /&gt;
By default, the interpreter draws all the windows and controls for the game&amp;#039;s GUI. However, with some creative coding, they can be easily customized. This tutorial will teach you how to create custom buttons with views.&lt;br /&gt;
&lt;br /&gt;
===Load The Game===&lt;br /&gt;
&lt;br /&gt;
First you need to open your game in SCI Studio, loading the Resource Explorer.&lt;br /&gt;
&lt;br /&gt;
===The Button View===&lt;br /&gt;
&lt;br /&gt;
First the buttons will need a view so there&amp;#039;s something to draw. I&amp;#039;ve set up the view so that cels 0-3 are for the button&amp;#039;s edges, and 4-7 are for the left, top, right and bottom borders. It can be easily customized to create your own custom button.&lt;br /&gt;
&lt;br /&gt;
The cels are 8x8 pixels. Though they really would only need to be 4x4, they should be no less than 8x8. If they are too small, it will take too long to draw the buttons.&lt;br /&gt;
&lt;br /&gt;
To save time, [http://sierrahelp.com/Files/SCI/view.900 click here] and download it.&lt;br /&gt;
&lt;br /&gt;
Add the view to the game. I chose to number it view.900, but it can be numbered anything you like.&lt;br /&gt;
&lt;br /&gt;
===Scripting The Button===&lt;br /&gt;
&lt;br /&gt;
In the resource explorer, select &amp;#039;&amp;#039;&amp;#039;Script&amp;#039;&amp;#039;&amp;#039; from the left resource tree. This will bring up the list of scripts in your game on the right. Double click on the &amp;quot;&amp;#039;&amp;#039;&amp;#039;Controls.sc&amp;#039;&amp;#039;&amp;#039;&amp;quot; script. It will load it up in the script editor.&lt;br /&gt;
&lt;br /&gt;
Though customizing a button is generally simple, there are many extra steps which must be taken to give it optimum performance and prevent interference.&lt;br /&gt;
&lt;br /&gt;
{| width=&amp;quot;100%&amp;quot;&lt;br /&gt;
| width=&amp;quot;216&amp;quot; | [[Image:Controls-DButton.png|DButton class]]&lt;br /&gt;
| width=&amp;quot;100%&amp;quot; valign=&amp;quot;top&amp;quot; | First, scroll down controls.sc to the DButton class.&lt;br /&gt;
|-&lt;br /&gt;
| width=&amp;quot;216&amp;quot; | [[Image:Controls-SetSize.png|setSize() method]]&lt;br /&gt;
| width=&amp;quot;100%&amp;quot; valign=&amp;quot;top&amp;quot; | Next, scroll down to the setSize() method.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&lt;br /&gt;
(Studio Script).&lt;br /&gt;
Change:&lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;= nsBottom (+ nsTop rect[rtBOTTOM])&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
(Studio Script) to:&lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;= nsBottom (+ nsTop(| (&amp;amp; rect[rtBOTTOM] $FFFC) 7))&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
(Sierra Script)&lt;br /&gt;
Change:&lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;(= nsBottom (+ nsTop [rect rtBOTTOM]))&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
(Sierra Script)&lt;br /&gt;
To:&lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;(= nsBottom (+ nsTop (| (&amp;amp; [rect rtBOTTOM] $FFFC) 7)))&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
(Studio Script) &lt;br /&gt;
Change: &lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;(= nsBottom (+ nsTop (| (&amp;amp; [rect rtBOTTOM] $FFFC) 7)))&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
(Studio Script) to:&lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;= nsRight (+ (| (&amp;amp; rect[rtRIGHT] $FFFC) 7) nsLeft)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
(Sierra Script)&lt;br /&gt;
Change:&lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;(= nsRight (+ [rect rtRIGHT] nsLeft))&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
(Sierra Script)&lt;br /&gt;
To:&lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;(= nsRight (+ (| (&amp;amp; [rect rtRIGHT] $FFFC) 7) nsLeft))&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This makes the control always in dimensions divisible by eight (i.e. 8,16,24,32,etc.). This is needed because we are using 8x8 cels.&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Next, we&amp;#039;ll need to add a draw method to the DButton class to override the default one.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&lt;br /&gt;
(Studio Script) Add the following code to the DButton class.&lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;  (method (draw)&lt;br /&gt;
    (var x, y, x2, y2, w, h, rect[4])&lt;br /&gt;
    &lt;br /&gt;
    // Calculate the areas&lt;br /&gt;
    = x2 (- nsRight 8)&lt;br /&gt;
    = y2 (- nsBottom 8)&lt;br /&gt;
    = w (- nsRight nsLeft)&lt;br /&gt;
    = h (- nsBottom nsTop)&lt;br /&gt;
    TextSize(@rect text font)&lt;br /&gt;
&lt;br /&gt;
    // Draw the side borders&lt;br /&gt;
    (for(= y(+ nsTop 8)) (&amp;lt; y y2) (= y + y 8)&lt;br /&gt;
      DrawCel(900 0 4 nsLeft y -1)&lt;br /&gt;
      DrawCel(900 0 6 x2   y -1)&lt;br /&gt;
    )&lt;br /&gt;
    // Draw the top and bottom borders&lt;br /&gt;
    (for(= x(+ nsLeft 8)) (&amp;lt; x x2) (= x + x 8)&lt;br /&gt;
      DrawCel(900 0 5 x nsTop -1)&lt;br /&gt;
      DrawCel(900 0 7 x y2   -1)&lt;br /&gt;
    )&lt;br /&gt;
    // Draw the corners&lt;br /&gt;
    DrawCel(900 0 0 nsLeft nsTop -1)&lt;br /&gt;
    DrawCel(900 0 1 x2   nsTop -1)&lt;br /&gt;
    DrawCel(900 0 2 nsLeft y2  -1)&lt;br /&gt;
    DrawCel(900 0 3 x2   y2  -1)&lt;br /&gt;
    // Draw the text&lt;br /&gt;
    Display(text&lt;br /&gt;
      dsCOORD&lt;br /&gt;
        + nsLeft (&amp;gt;&amp;gt; (- w rect[rtRIGHT]) 1)&lt;br /&gt;
        + (+ nsTop (&amp;gt;&amp;gt; (- h rect[rtBOTTOM]) 1) 1)&lt;br /&gt;
      dsCOLOR&lt;br /&gt;
        gWndColor&lt;br /&gt;
      dsBACKGROUND&lt;br /&gt;
        clTRANSPARENT&lt;br /&gt;
      dsFONT&lt;br /&gt;
        font&lt;br /&gt;
      dsWIDTH&lt;br /&gt;
        rect[rtRIGHT]&lt;br /&gt;
    )&lt;br /&gt;
  )&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
(Sierra Script) Add a draw method to the DButton class to override the default one. (Please note this code needs to be added before the method (method (setSize &amp;amp;tmp [rect 4]).&lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;  (method (draw &amp;amp;tmp x y x2 y2 w h [rect 4])&lt;br /&gt;
		; Calculate the areas&lt;br /&gt;
		(= x2 (- nsRight 8))&lt;br /&gt;
		(= y2 (- nsBottom 8))&lt;br /&gt;
		(= w (- nsRight nsLeft))&lt;br /&gt;
		(= h (- nsBottom nsTop))&lt;br /&gt;
		(TextSize @rect text font)&lt;br /&gt;
		; Draw the side borders&lt;br /&gt;
		(for ( (= y (+ nsTop 8))) (&amp;lt; y y2)  ( (= y (+ y 8))) (DrawCel 902 0 4 nsLeft y -1) (DrawCel 902 0 6 x2 y -1))&lt;br /&gt;
		; Draw the top and bottom borders&lt;br /&gt;
		(for ( (= x (+ nsLeft 8))) (&amp;lt; x x2)  ( (= x (+ x 8))) (DrawCel 902 0 5 x nsTop -1) (DrawCel 902 0 7 x y2 -1))&lt;br /&gt;
		; Draw the corners&lt;br /&gt;
		(DrawCel 902 0 0 nsLeft nsTop -1)&lt;br /&gt;
		(DrawCel 902 0 1 x2 nsTop -1)&lt;br /&gt;
		(DrawCel 902 0 2 nsLeft y2 -1)&lt;br /&gt;
		(DrawCel 902 0 3 x2 y2 -1)&lt;br /&gt;
		; Draw the text&lt;br /&gt;
		(Display&lt;br /&gt;
			text&lt;br /&gt;
			dsCOORD&lt;br /&gt;
				(+ nsLeft (&amp;gt;&amp;gt; (- w [rect rtRIGHT]) 1))&lt;br /&gt;
				(+ (+ nsTop (&amp;gt;&amp;gt; (- h [rect rtBOTTOM]) 1)) 1)&lt;br /&gt;
			dsCOLOR gWndColor&lt;br /&gt;
			dsBACKGROUND clTRANSPARENT&lt;br /&gt;
			dsFONT font&lt;br /&gt;
			dsWIDTH [rect rtRIGHT]&lt;br /&gt;
		)&lt;br /&gt;
	)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Needless to say, that code draws the button. It draws the border and edges, then centers and draws the text. It doesn&amp;#039;t bother drawing the inside of the button and just leaves it transparent for speed. It would be a lot slower if it filled in the button with cels.&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| width=&amp;quot;100%&amp;quot;&lt;br /&gt;
| width=&amp;quot;113&amp;quot; | [[Image:Script-Main.png|Main Script]]&lt;br /&gt;
| width=&amp;quot;100%&amp;quot; | Chances are, you&amp;#039;ll want to customize the window colors to go with the button, right? If that&amp;#039;s the case, open up the &amp;quot;&amp;#039;&amp;#039;&amp;#039;Main.sc&amp;#039;&amp;#039;&amp;#039;&amp;quot; script.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
{| width=&amp;quot;100%&amp;quot;&lt;br /&gt;
| width=&amp;quot;216&amp;quot; | [[Image:Script-GameInstance.png|Game Instance]]&lt;br /&gt;
| width=&amp;quot;100%&amp;quot; | Next, scroll down main.sc to the Game instance.&lt;br /&gt;
&lt;br /&gt;
At the very top of the init() method, you will see the window color initialization.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* The gWndColor is the color for the text and borders of of the non-custom controls.&lt;br /&gt;
* The gWndBack is the color of the actual window.&lt;br /&gt;
&lt;br /&gt;
Studio/Sierra Script:&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&lt;br /&gt;
To go with the default custom button, we&amp;#039;ll make the window silver. Change: &lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;= gWndBack clWHITE&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Studio/Sierra Script:&lt;br /&gt;
To:&lt;br /&gt;
To go with the default custom button, we&amp;#039;ll make the window silver. Change: &lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;= gWndBack clSILVER&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p align=&amp;quot;center&amp;quot;&amp;gt;Run the game all you&amp;#039;ll see your brand new custom buttons!&amp;lt;br /&amp;gt;[[Image:Controls-QuitDialog.png|Quit Button]]&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
That sums it up! Be sure to check out how to make custom windows and gauges!&lt;br /&gt;
&lt;br /&gt;
&amp;amp;nbsp;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;float: left&amp;quot;&amp;gt;[[Checking a Door&amp;#039;s State|&amp;amp;lt; Previous: Chapter 6 - Checking a Door&amp;#039;s State]]&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;span style=&amp;quot;float: right&amp;quot;&amp;gt;[[Custom Windows|Chapter 8 - Creating Custom Windows &amp;amp;gt;]]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;amp;nbsp;&lt;br /&gt;
&lt;br /&gt;
[[Category:Controls]]&lt;br /&gt;
[[Category:Tutorials]]&lt;/div&gt;</summary>
		<author><name>Rob Craig</name></author>
	</entry>
	<entry>
		<id>http://sciwiki.sierrahelp.com/index.php?title=Custom_Buttons&amp;diff=16028</id>
		<title>Custom Buttons</title>
		<link rel="alternate" type="text/html" href="http://sciwiki.sierrahelp.com/index.php?title=Custom_Buttons&amp;diff=16028"/>
		<updated>2023-06-01T08:44:18Z</updated>

		<summary type="html">&lt;p&gt;Rob Craig: /* Scripting The Button */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Chapter 7 - Creating Custom Buttons=&lt;br /&gt;
&lt;br /&gt;
By default, the interpreter draws all the windows and controls for the game&amp;#039;s GUI. However, with some creative coding, they can be easily customized. This tutorial will teach you how to create custom buttons with views.&lt;br /&gt;
&lt;br /&gt;
===Load The Game===&lt;br /&gt;
&lt;br /&gt;
First you need to open your game in SCI Studio, loading the Resource Explorer.&lt;br /&gt;
&lt;br /&gt;
===The Button View===&lt;br /&gt;
&lt;br /&gt;
First the buttons will need a view so there&amp;#039;s something to draw. I&amp;#039;ve set up the view so that cels 0-3 are for the button&amp;#039;s edges, and 4-7 are for the left, top, right and bottom borders. It can be easily customized to create your own custom button.&lt;br /&gt;
&lt;br /&gt;
The cels are 8x8 pixels. Though they really would only need to be 4x4, they should be no less than 8x8. If they are too small, it will take too long to draw the buttons.&lt;br /&gt;
&lt;br /&gt;
To save time, [http://sierrahelp.com/Files/SCI/view.900 click here] and download it.&lt;br /&gt;
&lt;br /&gt;
Add the view to the game. I chose to number it view.900, but it can be numbered anything you like.&lt;br /&gt;
&lt;br /&gt;
===Scripting The Button===&lt;br /&gt;
&lt;br /&gt;
In the resource explorer, select &amp;#039;&amp;#039;&amp;#039;Script&amp;#039;&amp;#039;&amp;#039; from the left resource tree. This will bring up the list of scripts in your game on the right. Double click on the &amp;quot;&amp;#039;&amp;#039;&amp;#039;Controls.sc&amp;#039;&amp;#039;&amp;#039;&amp;quot; script. It will load it up in the script editor.&lt;br /&gt;
&lt;br /&gt;
Though customizing a button is generally simple, there are many extra steps which must be taken to give it optimum performance and prevent interference.&lt;br /&gt;
&lt;br /&gt;
{| width=&amp;quot;100%&amp;quot;&lt;br /&gt;
| width=&amp;quot;216&amp;quot; | [[Image:Controls-DButton.png|DButton class]]&lt;br /&gt;
| width=&amp;quot;100%&amp;quot; valign=&amp;quot;top&amp;quot; | First, scroll down controls.sc to the DButton class.&lt;br /&gt;
|-&lt;br /&gt;
| width=&amp;quot;216&amp;quot; | [[Image:Controls-SetSize.png|setSize() method]]&lt;br /&gt;
| width=&amp;quot;100%&amp;quot; valign=&amp;quot;top&amp;quot; | Next, scroll down to the setSize() method.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&lt;br /&gt;
(Studio Script).&lt;br /&gt;
Change:&lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;= nsBottom (+ nsTop rect[rtBOTTOM])&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
(Studio Script) to:&lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;= nsBottom (+ nsTop(| (&amp;amp; rect[rtBOTTOM] $FFFC) 7))&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
(Sierra Script)&lt;br /&gt;
Change:&lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;(= nsBottom (+ nsTop [rect rtBOTTOM]))&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
(Sierra Script)&lt;br /&gt;
To:&lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;(= nsBottom (+ nsTop (| (&amp;amp; [rect rtBOTTOM] $FFFC) 7)))&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
(Studio Script) &lt;br /&gt;
Change: &lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;(= nsBottom (+ nsTop (| (&amp;amp; [rect rtBOTTOM] $FFFC) 7)))&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
(Studio Script) to:&lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;= nsRight (+ (| (&amp;amp; rect[rtRIGHT] $FFFC) 7) nsLeft)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
(Sierra Script)&lt;br /&gt;
Change:&lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;(= nsRight (+ [rect rtRIGHT] nsLeft))&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
(Sierra Script)&lt;br /&gt;
To:&lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;(= nsRight (+ (| (&amp;amp; [rect rtRIGHT] $FFFC) 7) nsLeft))&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This makes the control always in dimensions divisible by eight (i.e. 8,16,24,32,etc.). This is needed because we are using 8x8 cels.&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Next, we&amp;#039;ll need to add a draw method to the DButton class to override the default one.&lt;br /&gt;
(Studio Script)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&lt;br /&gt;
Add the following code to the DButton class. &lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;  (method (draw)&lt;br /&gt;
    (var x, y, x2, y2, w, h, rect[4])&lt;br /&gt;
    &lt;br /&gt;
    // Calculate the areas&lt;br /&gt;
    = x2 (- nsRight 8)&lt;br /&gt;
    = y2 (- nsBottom 8)&lt;br /&gt;
    = w (- nsRight nsLeft)&lt;br /&gt;
    = h (- nsBottom nsTop)&lt;br /&gt;
    TextSize(@rect text font)&lt;br /&gt;
&lt;br /&gt;
    // Draw the side borders&lt;br /&gt;
    (for(= y(+ nsTop 8)) (&amp;lt; y y2) (= y + y 8)&lt;br /&gt;
      DrawCel(900 0 4 nsLeft y -1)&lt;br /&gt;
      DrawCel(900 0 6 x2   y -1)&lt;br /&gt;
    )&lt;br /&gt;
    // Draw the top and bottom borders&lt;br /&gt;
    (for(= x(+ nsLeft 8)) (&amp;lt; x x2) (= x + x 8)&lt;br /&gt;
      DrawCel(900 0 5 x nsTop -1)&lt;br /&gt;
      DrawCel(900 0 7 x y2   -1)&lt;br /&gt;
    )&lt;br /&gt;
    // Draw the corners&lt;br /&gt;
    DrawCel(900 0 0 nsLeft nsTop -1)&lt;br /&gt;
    DrawCel(900 0 1 x2   nsTop -1)&lt;br /&gt;
    DrawCel(900 0 2 nsLeft y2  -1)&lt;br /&gt;
    DrawCel(900 0 3 x2   y2  -1)&lt;br /&gt;
    // Draw the text&lt;br /&gt;
    Display(text&lt;br /&gt;
      dsCOORD&lt;br /&gt;
        + nsLeft (&amp;gt;&amp;gt; (- w rect[rtRIGHT]) 1)&lt;br /&gt;
        + (+ nsTop (&amp;gt;&amp;gt; (- h rect[rtBOTTOM]) 1) 1)&lt;br /&gt;
      dsCOLOR&lt;br /&gt;
        gWndColor&lt;br /&gt;
      dsBACKGROUND&lt;br /&gt;
        clTRANSPARENT&lt;br /&gt;
      dsFONT&lt;br /&gt;
        font&lt;br /&gt;
      dsWIDTH&lt;br /&gt;
        rect[rtRIGHT]&lt;br /&gt;
    )&lt;br /&gt;
  )&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
(Sierra Script) Add a draw method to the DButton class to override the default one. (Please note this code needs to be added before the method (method (setSize &amp;amp;tmp [rect 4]).&lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;  (method (draw &amp;amp;tmp x y x2 y2 w h [rect 4])&lt;br /&gt;
		; Calculate the areas&lt;br /&gt;
		(= x2 (- nsRight 8))&lt;br /&gt;
		(= y2 (- nsBottom 8))&lt;br /&gt;
		(= w (- nsRight nsLeft))&lt;br /&gt;
		(= h (- nsBottom nsTop))&lt;br /&gt;
		(TextSize @rect text font)&lt;br /&gt;
		; Draw the side borders&lt;br /&gt;
		(for ( (= y (+ nsTop 8))) (&amp;lt; y y2)  ( (= y (+ y 8))) (DrawCel 902 0 4 nsLeft y -1) (DrawCel 902 0 6 x2 y -1))&lt;br /&gt;
		; Draw the top and bottom borders&lt;br /&gt;
		(for ( (= x (+ nsLeft 8))) (&amp;lt; x x2)  ( (= x (+ x 8))) (DrawCel 902 0 5 x nsTop -1) (DrawCel 902 0 7 x y2 -1))&lt;br /&gt;
		; Draw the corners&lt;br /&gt;
		(DrawCel 902 0 0 nsLeft nsTop -1)&lt;br /&gt;
		(DrawCel 902 0 1 x2 nsTop -1)&lt;br /&gt;
		(DrawCel 902 0 2 nsLeft y2 -1)&lt;br /&gt;
		(DrawCel 902 0 3 x2 y2 -1)&lt;br /&gt;
		; Draw the text&lt;br /&gt;
		(Display&lt;br /&gt;
			text&lt;br /&gt;
			dsCOORD&lt;br /&gt;
				(+ nsLeft (&amp;gt;&amp;gt; (- w [rect rtRIGHT]) 1))&lt;br /&gt;
				(+ (+ nsTop (&amp;gt;&amp;gt; (- h [rect rtBOTTOM]) 1)) 1)&lt;br /&gt;
			dsCOLOR gWndColor&lt;br /&gt;
			dsBACKGROUND clTRANSPARENT&lt;br /&gt;
			dsFONT font&lt;br /&gt;
			dsWIDTH [rect rtRIGHT]&lt;br /&gt;
		)&lt;br /&gt;
	)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Needless to say, that code draws the button. It draws the border and edges, then centers and draws the text. It doesn&amp;#039;t bother drawing the inside of the button and just leaves it transparent for speed. It would be a lot slower if it filled in the button with cels.&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| width=&amp;quot;100%&amp;quot;&lt;br /&gt;
| width=&amp;quot;113&amp;quot; | [[Image:Script-Main.png|Main Script]]&lt;br /&gt;
| width=&amp;quot;100%&amp;quot; | Chances are, you&amp;#039;ll want to customize the window colors to go with the button, right? If that&amp;#039;s the case, open up the &amp;quot;&amp;#039;&amp;#039;&amp;#039;Main.sc&amp;#039;&amp;#039;&amp;#039;&amp;quot; script.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
{| width=&amp;quot;100%&amp;quot;&lt;br /&gt;
| width=&amp;quot;216&amp;quot; | [[Image:Script-GameInstance.png|Game Instance]]&lt;br /&gt;
| width=&amp;quot;100%&amp;quot; | Next, scroll down main.sc to the Game instance.&lt;br /&gt;
&lt;br /&gt;
At the very top of the init() method, you will see the window color initialization.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* The gWndColor is the color for the text and borders of of the non-custom controls.&lt;br /&gt;
* The gWndBack is the color of the actual window.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&lt;br /&gt;
To go with the default custom button, we&amp;#039;ll make the window silver. Change: &lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;= gWndBack clWHITE&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
To:&lt;br /&gt;
To go with the default custom button, we&amp;#039;ll make the window silver. Change: &lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;= gWndBack clSILVER&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p align=&amp;quot;center&amp;quot;&amp;gt;Run the game all you&amp;#039;ll see your brand new custom buttons!&amp;lt;br /&amp;gt;[[Image:Controls-QuitDialog.png|Quit Button]]&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
That sums it up! Be sure to check out how to make custom windows and gauges!&lt;br /&gt;
&lt;br /&gt;
&amp;amp;nbsp;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;float: left&amp;quot;&amp;gt;[[Checking a Door&amp;#039;s State|&amp;amp;lt; Previous: Chapter 6 - Checking a Door&amp;#039;s State]]&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;span style=&amp;quot;float: right&amp;quot;&amp;gt;[[Custom Windows|Chapter 8 - Creating Custom Windows &amp;amp;gt;]]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;amp;nbsp;&lt;br /&gt;
&lt;br /&gt;
[[Category:Controls]]&lt;br /&gt;
[[Category:Tutorials]]&lt;/div&gt;</summary>
		<author><name>Rob Craig</name></author>
	</entry>
	<entry>
		<id>http://sciwiki.sierrahelp.com/index.php?title=Custom_Buttons&amp;diff=16027</id>
		<title>Custom Buttons</title>
		<link rel="alternate" type="text/html" href="http://sciwiki.sierrahelp.com/index.php?title=Custom_Buttons&amp;diff=16027"/>
		<updated>2023-06-01T08:39:44Z</updated>

		<summary type="html">&lt;p&gt;Rob Craig: /* Scripting The Button */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Chapter 7 - Creating Custom Buttons=&lt;br /&gt;
&lt;br /&gt;
By default, the interpreter draws all the windows and controls for the game&amp;#039;s GUI. However, with some creative coding, they can be easily customized. This tutorial will teach you how to create custom buttons with views.&lt;br /&gt;
&lt;br /&gt;
===Load The Game===&lt;br /&gt;
&lt;br /&gt;
First you need to open your game in SCI Studio, loading the Resource Explorer.&lt;br /&gt;
&lt;br /&gt;
===The Button View===&lt;br /&gt;
&lt;br /&gt;
First the buttons will need a view so there&amp;#039;s something to draw. I&amp;#039;ve set up the view so that cels 0-3 are for the button&amp;#039;s edges, and 4-7 are for the left, top, right and bottom borders. It can be easily customized to create your own custom button.&lt;br /&gt;
&lt;br /&gt;
The cels are 8x8 pixels. Though they really would only need to be 4x4, they should be no less than 8x8. If they are too small, it will take too long to draw the buttons.&lt;br /&gt;
&lt;br /&gt;
To save time, [http://sierrahelp.com/Files/SCI/view.900 click here] and download it.&lt;br /&gt;
&lt;br /&gt;
Add the view to the game. I chose to number it view.900, but it can be numbered anything you like.&lt;br /&gt;
&lt;br /&gt;
===Scripting The Button===&lt;br /&gt;
&lt;br /&gt;
In the resource explorer, select &amp;#039;&amp;#039;&amp;#039;Script&amp;#039;&amp;#039;&amp;#039; from the left resource tree. This will bring up the list of scripts in your game on the right. Double click on the &amp;quot;&amp;#039;&amp;#039;&amp;#039;Controls.sc&amp;#039;&amp;#039;&amp;#039;&amp;quot; script. It will load it up in the script editor.&lt;br /&gt;
&lt;br /&gt;
Though customizing a button is generally simple, there are many extra steps which must be taken to give it optimum performance and prevent interference.&lt;br /&gt;
&lt;br /&gt;
{| width=&amp;quot;100%&amp;quot;&lt;br /&gt;
| width=&amp;quot;216&amp;quot; | [[Image:Controls-DButton.png|DButton class]]&lt;br /&gt;
| width=&amp;quot;100%&amp;quot; valign=&amp;quot;top&amp;quot; | First, scroll down controls.sc to the DButton class.&lt;br /&gt;
|-&lt;br /&gt;
| width=&amp;quot;216&amp;quot; | [[Image:Controls-SetSize.png|setSize() method]]&lt;br /&gt;
| width=&amp;quot;100%&amp;quot; valign=&amp;quot;top&amp;quot; | Next, scroll down to the setSize() method.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&lt;br /&gt;
(Studio Script).&lt;br /&gt;
Change:&lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;= nsBottom (+ nsTop rect[rtBOTTOM])&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
(Studio Script) to:&lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;= nsBottom (+ nsTop(| (&amp;amp; rect[rtBOTTOM] $FFFC) 7))&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
(Sierra Script)&lt;br /&gt;
Change:&lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;(= nsBottom (+ nsTop [rect rtBOTTOM]))&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
(Sierra Script)&lt;br /&gt;
To:&lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;(= nsBottom (+ nsTop (| (&amp;amp; [rect rtBOTTOM] $FFFC) 7)))&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
(Studio Script) &lt;br /&gt;
Change: &lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;(= nsBottom (+ nsTop (| (&amp;amp; [rect rtBOTTOM] $FFFC) 7)))&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
(Studio Script) to:&lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;= nsRight (+ (| (&amp;amp; rect[rtRIGHT] $FFFC) 7) nsLeft)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
(Sierra Script)&lt;br /&gt;
Change:&lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;(= nsRight (+ [rect rtRIGHT] nsLeft))&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
(Sierra Script)&lt;br /&gt;
To:&lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;(= nsRight (+ (| (&amp;amp; [rect rtRIGHT] $FFFC) 7) nsLeft))&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This makes the control always in dimensions divisible by eight (i.e. 8,16,24,32,etc.). This is needed because we are using 8x8 cels.&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Next, we&amp;#039;ll need to add a draw method to the DButton class to override the default one.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&lt;br /&gt;
Add the following code to the DButton class. &lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;  (method (draw)&lt;br /&gt;
    (var x, y, x2, y2, w, h, rect[4])&lt;br /&gt;
    &lt;br /&gt;
    // Calculate the areas&lt;br /&gt;
    = x2 (- nsRight 8)&lt;br /&gt;
    = y2 (- nsBottom 8)&lt;br /&gt;
    = w (- nsRight nsLeft)&lt;br /&gt;
    = h (- nsBottom nsTop)&lt;br /&gt;
    TextSize(@rect text font)&lt;br /&gt;
&lt;br /&gt;
    // Draw the side borders&lt;br /&gt;
    (for(= y(+ nsTop 8)) (&amp;lt; y y2) (= y + y 8)&lt;br /&gt;
      DrawCel(900 0 4 nsLeft y -1)&lt;br /&gt;
      DrawCel(900 0 6 x2   y -1)&lt;br /&gt;
    )&lt;br /&gt;
    // Draw the top and bottom borders&lt;br /&gt;
    (for(= x(+ nsLeft 8)) (&amp;lt; x x2) (= x + x 8)&lt;br /&gt;
      DrawCel(900 0 5 x nsTop -1)&lt;br /&gt;
      DrawCel(900 0 7 x y2   -1)&lt;br /&gt;
    )&lt;br /&gt;
    // Draw the corners&lt;br /&gt;
    DrawCel(900 0 0 nsLeft nsTop -1)&lt;br /&gt;
    DrawCel(900 0 1 x2   nsTop -1)&lt;br /&gt;
    DrawCel(900 0 2 nsLeft y2  -1)&lt;br /&gt;
    DrawCel(900 0 3 x2   y2  -1)&lt;br /&gt;
    // Draw the text&lt;br /&gt;
    Display(text&lt;br /&gt;
      dsCOORD&lt;br /&gt;
        + nsLeft (&amp;gt;&amp;gt; (- w rect[rtRIGHT]) 1)&lt;br /&gt;
        + (+ nsTop (&amp;gt;&amp;gt; (- h rect[rtBOTTOM]) 1) 1)&lt;br /&gt;
      dsCOLOR&lt;br /&gt;
        gWndColor&lt;br /&gt;
      dsBACKGROUND&lt;br /&gt;
        clTRANSPARENT&lt;br /&gt;
      dsFONT&lt;br /&gt;
        font&lt;br /&gt;
      dsWIDTH&lt;br /&gt;
        rect[rtRIGHT]&lt;br /&gt;
    )&lt;br /&gt;
  )&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
SCI code for SCI Companion. &lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;  (method (draw &amp;amp;tmp x y x2 y2 w h [rect 4])&lt;br /&gt;
		; Calculate the areas&lt;br /&gt;
		(= x2 (- nsRight 8))&lt;br /&gt;
		(= y2 (- nsBottom 8))&lt;br /&gt;
		(= w (- nsRight nsLeft))&lt;br /&gt;
		(= h (- nsBottom nsTop))&lt;br /&gt;
		(TextSize @rect text font)&lt;br /&gt;
		; Draw the side borders&lt;br /&gt;
		(for ( (= y (+ nsTop 8))) (&amp;lt; y y2)  ( (= y (+ y 8))) (DrawCel 902 0 4 nsLeft y -1) (DrawCel 902 0 6 x2 y -1))&lt;br /&gt;
		; Draw the top and bottom borders&lt;br /&gt;
		(for ( (= x (+ nsLeft 8))) (&amp;lt; x x2)  ( (= x (+ x 8))) (DrawCel 902 0 5 x nsTop -1) (DrawCel 902 0 7 x y2 -1))&lt;br /&gt;
		; Draw the corners&lt;br /&gt;
		(DrawCel 902 0 0 nsLeft nsTop -1)&lt;br /&gt;
		(DrawCel 902 0 1 x2 nsTop -1)&lt;br /&gt;
		(DrawCel 902 0 2 nsLeft y2 -1)&lt;br /&gt;
		(DrawCel 902 0 3 x2 y2 -1)&lt;br /&gt;
		; Draw the text&lt;br /&gt;
		(Display&lt;br /&gt;
			text&lt;br /&gt;
			dsCOORD&lt;br /&gt;
				(+ nsLeft (&amp;gt;&amp;gt; (- w [rect rtRIGHT]) 1))&lt;br /&gt;
				(+ (+ nsTop (&amp;gt;&amp;gt; (- h [rect rtBOTTOM]) 1)) 1)&lt;br /&gt;
			dsCOLOR gWndColor&lt;br /&gt;
			dsBACKGROUND clTRANSPARENT&lt;br /&gt;
			dsFONT font&lt;br /&gt;
			dsWIDTH [rect rtRIGHT]&lt;br /&gt;
		)&lt;br /&gt;
	)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Needless to say, that code draws the button. It draws the border and edges, then centers and draws the text. It doesn&amp;#039;t bother drawing the inside of the button and just leaves it transparent for speed. It would be a lot slower if it filled in the button with cels.&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| width=&amp;quot;100%&amp;quot;&lt;br /&gt;
| width=&amp;quot;113&amp;quot; | [[Image:Script-Main.png|Main Script]]&lt;br /&gt;
| width=&amp;quot;100%&amp;quot; | Chances are, you&amp;#039;ll want to customize the window colors to go with the button, right? If that&amp;#039;s the case, open up the &amp;quot;&amp;#039;&amp;#039;&amp;#039;Main.sc&amp;#039;&amp;#039;&amp;#039;&amp;quot; script.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
{| width=&amp;quot;100%&amp;quot;&lt;br /&gt;
| width=&amp;quot;216&amp;quot; | [[Image:Script-GameInstance.png|Game Instance]]&lt;br /&gt;
| width=&amp;quot;100%&amp;quot; | Next, scroll down main.sc to the Game instance.&lt;br /&gt;
&lt;br /&gt;
At the very top of the init() method, you will see the window color initialization.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* The gWndColor is the color for the text and borders of of the non-custom controls.&lt;br /&gt;
* The gWndBack is the color of the actual window.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&lt;br /&gt;
To go with the default custom button, we&amp;#039;ll make the window silver. Change: &lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;= gWndBack clWHITE&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
To:&lt;br /&gt;
To go with the default custom button, we&amp;#039;ll make the window silver. Change: &lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;= gWndBack clSILVER&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p align=&amp;quot;center&amp;quot;&amp;gt;Run the game all you&amp;#039;ll see your brand new custom buttons!&amp;lt;br /&amp;gt;[[Image:Controls-QuitDialog.png|Quit Button]]&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
That sums it up! Be sure to check out how to make custom windows and gauges!&lt;br /&gt;
&lt;br /&gt;
&amp;amp;nbsp;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;float: left&amp;quot;&amp;gt;[[Checking a Door&amp;#039;s State|&amp;amp;lt; Previous: Chapter 6 - Checking a Door&amp;#039;s State]]&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;span style=&amp;quot;float: right&amp;quot;&amp;gt;[[Custom Windows|Chapter 8 - Creating Custom Windows &amp;amp;gt;]]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;amp;nbsp;&lt;br /&gt;
&lt;br /&gt;
[[Category:Controls]]&lt;br /&gt;
[[Category:Tutorials]]&lt;/div&gt;</summary>
		<author><name>Rob Craig</name></author>
	</entry>
	<entry>
		<id>http://sciwiki.sierrahelp.com/index.php?title=Custom_Buttons&amp;diff=16026</id>
		<title>Custom Buttons</title>
		<link rel="alternate" type="text/html" href="http://sciwiki.sierrahelp.com/index.php?title=Custom_Buttons&amp;diff=16026"/>
		<updated>2023-06-01T08:36:58Z</updated>

		<summary type="html">&lt;p&gt;Rob Craig: /* Scripting The Button */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Chapter 7 - Creating Custom Buttons=&lt;br /&gt;
&lt;br /&gt;
By default, the interpreter draws all the windows and controls for the game&amp;#039;s GUI. However, with some creative coding, they can be easily customized. This tutorial will teach you how to create custom buttons with views.&lt;br /&gt;
&lt;br /&gt;
===Load The Game===&lt;br /&gt;
&lt;br /&gt;
First you need to open your game in SCI Studio, loading the Resource Explorer.&lt;br /&gt;
&lt;br /&gt;
===The Button View===&lt;br /&gt;
&lt;br /&gt;
First the buttons will need a view so there&amp;#039;s something to draw. I&amp;#039;ve set up the view so that cels 0-3 are for the button&amp;#039;s edges, and 4-7 are for the left, top, right and bottom borders. It can be easily customized to create your own custom button.&lt;br /&gt;
&lt;br /&gt;
The cels are 8x8 pixels. Though they really would only need to be 4x4, they should be no less than 8x8. If they are too small, it will take too long to draw the buttons.&lt;br /&gt;
&lt;br /&gt;
To save time, [http://sierrahelp.com/Files/SCI/view.900 click here] and download it.&lt;br /&gt;
&lt;br /&gt;
Add the view to the game. I chose to number it view.900, but it can be numbered anything you like.&lt;br /&gt;
&lt;br /&gt;
===Scripting The Button===&lt;br /&gt;
&lt;br /&gt;
In the resource explorer, select &amp;#039;&amp;#039;&amp;#039;Script&amp;#039;&amp;#039;&amp;#039; from the left resource tree. This will bring up the list of scripts in your game on the right. Double click on the &amp;quot;&amp;#039;&amp;#039;&amp;#039;Controls.sc&amp;#039;&amp;#039;&amp;#039;&amp;quot; script. It will load it up in the script editor.&lt;br /&gt;
&lt;br /&gt;
Though customizing a button is generally simple, there are many extra steps which must be taken to give it optimum performance and prevent interference.&lt;br /&gt;
&lt;br /&gt;
{| width=&amp;quot;100%&amp;quot;&lt;br /&gt;
| width=&amp;quot;216&amp;quot; | [[Image:Controls-DButton.png|DButton class]]&lt;br /&gt;
| width=&amp;quot;100%&amp;quot; valign=&amp;quot;top&amp;quot; | First, scroll down controls.sc to the DButton class.&lt;br /&gt;
|-&lt;br /&gt;
| width=&amp;quot;216&amp;quot; | [[Image:Controls-SetSize.png|setSize() method]]&lt;br /&gt;
| width=&amp;quot;100%&amp;quot; valign=&amp;quot;top&amp;quot; | Next, scroll down to the setSize() method.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&lt;br /&gt;
(Studio Script).&lt;br /&gt;
Change:&lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;= nsBottom (+ nsTop rect[rtBOTTOM])&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
(Studio Script) to:&lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;= nsBottom (+ nsTop(| (&amp;amp; rect[rtBOTTOM] $FFFC) 7))&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
(Sierra Script)&lt;br /&gt;
Change:&lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;(= nsBottom (+ nsTop [rect rtBOTTOM]))&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
(Sierra Script)&lt;br /&gt;
To:&lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;(= nsBottom (+ nsTop (| (&amp;amp; [rect rtBOTTOM] $FFFC) 7)))&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
(Studio Script) &lt;br /&gt;
Change: &lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;(= nsBottom (+ nsTop (| (&amp;amp; [rect rtBOTTOM] $FFFC) 7)))&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
(Studio Script) to:&lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;= nsRight (+ (| (&amp;amp; rect[rtRIGHT] $FFFC) 7) nsLeft)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
(Sierra Script)&lt;br /&gt;
To:&lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;(= nsRight (+ (| (&amp;amp; [rect rtRIGHT] $FFFC) 7) nsLeft))&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This makes the control always in dimensions divisible by eight (i.e. 8,16,24,32,etc.). This is needed because we are using 8x8 cels.&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Next, we&amp;#039;ll need to add a draw method to the DButton class to override the default one.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&lt;br /&gt;
Add the following code to the DButton class. &lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;  (method (draw)&lt;br /&gt;
    (var x, y, x2, y2, w, h, rect[4])&lt;br /&gt;
    &lt;br /&gt;
    // Calculate the areas&lt;br /&gt;
    = x2 (- nsRight 8)&lt;br /&gt;
    = y2 (- nsBottom 8)&lt;br /&gt;
    = w (- nsRight nsLeft)&lt;br /&gt;
    = h (- nsBottom nsTop)&lt;br /&gt;
    TextSize(@rect text font)&lt;br /&gt;
&lt;br /&gt;
    // Draw the side borders&lt;br /&gt;
    (for(= y(+ nsTop 8)) (&amp;lt; y y2) (= y + y 8)&lt;br /&gt;
      DrawCel(900 0 4 nsLeft y -1)&lt;br /&gt;
      DrawCel(900 0 6 x2   y -1)&lt;br /&gt;
    )&lt;br /&gt;
    // Draw the top and bottom borders&lt;br /&gt;
    (for(= x(+ nsLeft 8)) (&amp;lt; x x2) (= x + x 8)&lt;br /&gt;
      DrawCel(900 0 5 x nsTop -1)&lt;br /&gt;
      DrawCel(900 0 7 x y2   -1)&lt;br /&gt;
    )&lt;br /&gt;
    // Draw the corners&lt;br /&gt;
    DrawCel(900 0 0 nsLeft nsTop -1)&lt;br /&gt;
    DrawCel(900 0 1 x2   nsTop -1)&lt;br /&gt;
    DrawCel(900 0 2 nsLeft y2  -1)&lt;br /&gt;
    DrawCel(900 0 3 x2   y2  -1)&lt;br /&gt;
    // Draw the text&lt;br /&gt;
    Display(text&lt;br /&gt;
      dsCOORD&lt;br /&gt;
        + nsLeft (&amp;gt;&amp;gt; (- w rect[rtRIGHT]) 1)&lt;br /&gt;
        + (+ nsTop (&amp;gt;&amp;gt; (- h rect[rtBOTTOM]) 1) 1)&lt;br /&gt;
      dsCOLOR&lt;br /&gt;
        gWndColor&lt;br /&gt;
      dsBACKGROUND&lt;br /&gt;
        clTRANSPARENT&lt;br /&gt;
      dsFONT&lt;br /&gt;
        font&lt;br /&gt;
      dsWIDTH&lt;br /&gt;
        rect[rtRIGHT]&lt;br /&gt;
    )&lt;br /&gt;
  )&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
SCI code for SCI Companion. &lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;  (method (draw &amp;amp;tmp x y x2 y2 w h [rect 4])&lt;br /&gt;
		; Calculate the areas&lt;br /&gt;
		(= x2 (- nsRight 8))&lt;br /&gt;
		(= y2 (- nsBottom 8))&lt;br /&gt;
		(= w (- nsRight nsLeft))&lt;br /&gt;
		(= h (- nsBottom nsTop))&lt;br /&gt;
		(TextSize @rect text font)&lt;br /&gt;
		; Draw the side borders&lt;br /&gt;
		(for ( (= y (+ nsTop 8))) (&amp;lt; y y2)  ( (= y (+ y 8))) (DrawCel 902 0 4 nsLeft y -1) (DrawCel 902 0 6 x2 y -1))&lt;br /&gt;
		; Draw the top and bottom borders&lt;br /&gt;
		(for ( (= x (+ nsLeft 8))) (&amp;lt; x x2)  ( (= x (+ x 8))) (DrawCel 902 0 5 x nsTop -1) (DrawCel 902 0 7 x y2 -1))&lt;br /&gt;
		; Draw the corners&lt;br /&gt;
		(DrawCel 902 0 0 nsLeft nsTop -1)&lt;br /&gt;
		(DrawCel 902 0 1 x2 nsTop -1)&lt;br /&gt;
		(DrawCel 902 0 2 nsLeft y2 -1)&lt;br /&gt;
		(DrawCel 902 0 3 x2 y2 -1)&lt;br /&gt;
		; Draw the text&lt;br /&gt;
		(Display&lt;br /&gt;
			text&lt;br /&gt;
			dsCOORD&lt;br /&gt;
				(+ nsLeft (&amp;gt;&amp;gt; (- w [rect rtRIGHT]) 1))&lt;br /&gt;
				(+ (+ nsTop (&amp;gt;&amp;gt; (- h [rect rtBOTTOM]) 1)) 1)&lt;br /&gt;
			dsCOLOR gWndColor&lt;br /&gt;
			dsBACKGROUND clTRANSPARENT&lt;br /&gt;
			dsFONT font&lt;br /&gt;
			dsWIDTH [rect rtRIGHT]&lt;br /&gt;
		)&lt;br /&gt;
	)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Needless to say, that code draws the button. It draws the border and edges, then centers and draws the text. It doesn&amp;#039;t bother drawing the inside of the button and just leaves it transparent for speed. It would be a lot slower if it filled in the button with cels.&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| width=&amp;quot;100%&amp;quot;&lt;br /&gt;
| width=&amp;quot;113&amp;quot; | [[Image:Script-Main.png|Main Script]]&lt;br /&gt;
| width=&amp;quot;100%&amp;quot; | Chances are, you&amp;#039;ll want to customize the window colors to go with the button, right? If that&amp;#039;s the case, open up the &amp;quot;&amp;#039;&amp;#039;&amp;#039;Main.sc&amp;#039;&amp;#039;&amp;#039;&amp;quot; script.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
{| width=&amp;quot;100%&amp;quot;&lt;br /&gt;
| width=&amp;quot;216&amp;quot; | [[Image:Script-GameInstance.png|Game Instance]]&lt;br /&gt;
| width=&amp;quot;100%&amp;quot; | Next, scroll down main.sc to the Game instance.&lt;br /&gt;
&lt;br /&gt;
At the very top of the init() method, you will see the window color initialization.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* The gWndColor is the color for the text and borders of of the non-custom controls.&lt;br /&gt;
* The gWndBack is the color of the actual window.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&lt;br /&gt;
To go with the default custom button, we&amp;#039;ll make the window silver. Change: &lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;= gWndBack clWHITE&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
To:&lt;br /&gt;
To go with the default custom button, we&amp;#039;ll make the window silver. Change: &lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;= gWndBack clSILVER&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p align=&amp;quot;center&amp;quot;&amp;gt;Run the game all you&amp;#039;ll see your brand new custom buttons!&amp;lt;br /&amp;gt;[[Image:Controls-QuitDialog.png|Quit Button]]&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
That sums it up! Be sure to check out how to make custom windows and gauges!&lt;br /&gt;
&lt;br /&gt;
&amp;amp;nbsp;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;float: left&amp;quot;&amp;gt;[[Checking a Door&amp;#039;s State|&amp;amp;lt; Previous: Chapter 6 - Checking a Door&amp;#039;s State]]&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;span style=&amp;quot;float: right&amp;quot;&amp;gt;[[Custom Windows|Chapter 8 - Creating Custom Windows &amp;amp;gt;]]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;amp;nbsp;&lt;br /&gt;
&lt;br /&gt;
[[Category:Controls]]&lt;br /&gt;
[[Category:Tutorials]]&lt;/div&gt;</summary>
		<author><name>Rob Craig</name></author>
	</entry>
	<entry>
		<id>http://sciwiki.sierrahelp.com/index.php?title=Custom_Buttons&amp;diff=16025</id>
		<title>Custom Buttons</title>
		<link rel="alternate" type="text/html" href="http://sciwiki.sierrahelp.com/index.php?title=Custom_Buttons&amp;diff=16025"/>
		<updated>2023-06-01T08:36:34Z</updated>

		<summary type="html">&lt;p&gt;Rob Craig: /* Scripting The Button */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Chapter 7 - Creating Custom Buttons=&lt;br /&gt;
&lt;br /&gt;
By default, the interpreter draws all the windows and controls for the game&amp;#039;s GUI. However, with some creative coding, they can be easily customized. This tutorial will teach you how to create custom buttons with views.&lt;br /&gt;
&lt;br /&gt;
===Load The Game===&lt;br /&gt;
&lt;br /&gt;
First you need to open your game in SCI Studio, loading the Resource Explorer.&lt;br /&gt;
&lt;br /&gt;
===The Button View===&lt;br /&gt;
&lt;br /&gt;
First the buttons will need a view so there&amp;#039;s something to draw. I&amp;#039;ve set up the view so that cels 0-3 are for the button&amp;#039;s edges, and 4-7 are for the left, top, right and bottom borders. It can be easily customized to create your own custom button.&lt;br /&gt;
&lt;br /&gt;
The cels are 8x8 pixels. Though they really would only need to be 4x4, they should be no less than 8x8. If they are too small, it will take too long to draw the buttons.&lt;br /&gt;
&lt;br /&gt;
To save time, [http://sierrahelp.com/Files/SCI/view.900 click here] and download it.&lt;br /&gt;
&lt;br /&gt;
Add the view to the game. I chose to number it view.900, but it can be numbered anything you like.&lt;br /&gt;
&lt;br /&gt;
===Scripting The Button===&lt;br /&gt;
&lt;br /&gt;
In the resource explorer, select &amp;#039;&amp;#039;&amp;#039;Script&amp;#039;&amp;#039;&amp;#039; from the left resource tree. This will bring up the list of scripts in your game on the right. Double click on the &amp;quot;&amp;#039;&amp;#039;&amp;#039;Controls.sc&amp;#039;&amp;#039;&amp;#039;&amp;quot; script. It will load it up in the script editor.&lt;br /&gt;
&lt;br /&gt;
Though customizing a button is generally simple, there are many extra steps which must be taken to give it optimum performance and prevent interference.&lt;br /&gt;
&lt;br /&gt;
{| width=&amp;quot;100%&amp;quot;&lt;br /&gt;
| width=&amp;quot;216&amp;quot; | [[Image:Controls-DButton.png|DButton class]]&lt;br /&gt;
| width=&amp;quot;100%&amp;quot; valign=&amp;quot;top&amp;quot; | First, scroll down controls.sc to the DButton class.&lt;br /&gt;
|-&lt;br /&gt;
| width=&amp;quot;216&amp;quot; | [[Image:Controls-SetSize.png|setSize() method]]&lt;br /&gt;
| width=&amp;quot;100%&amp;quot; valign=&amp;quot;top&amp;quot; | Next, scroll down to the setSize() method.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&lt;br /&gt;
(Studio Script).&lt;br /&gt;
Change:&lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;= nsBottom (+ nsTop rect[rtBOTTOM])&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
(Studio Script example) to:&lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;= nsBottom (+ nsTop(| (&amp;amp; rect[rtBOTTOM] $FFFC) 7))&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
(Sierra Script)&lt;br /&gt;
Change:&lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;(= nsBottom (+ nsTop [rect rtBOTTOM]))&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
(Sierra Script)&lt;br /&gt;
To:&lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;(= nsBottom (+ nsTop (| (&amp;amp; [rect rtBOTTOM] $FFFC) 7)))&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
(Studio Script) &lt;br /&gt;
Change: &lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;(= nsBottom (+ nsTop (| (&amp;amp; [rect rtBOTTOM] $FFFC) 7)))&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
(Studio Script) to:&lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;= nsRight (+ (| (&amp;amp; rect[rtRIGHT] $FFFC) 7) nsLeft)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
(Sierra Script)&lt;br /&gt;
To:&lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;(= nsRight (+ (| (&amp;amp; [rect rtRIGHT] $FFFC) 7) nsLeft))&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This makes the control always in dimensions divisible by eight (i.e. 8,16,24,32,etc.). This is needed because we are using 8x8 cels.&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Next, we&amp;#039;ll need to add a draw method to the DButton class to override the default one.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&lt;br /&gt;
Add the following code to the DButton class. &lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;  (method (draw)&lt;br /&gt;
    (var x, y, x2, y2, w, h, rect[4])&lt;br /&gt;
    &lt;br /&gt;
    // Calculate the areas&lt;br /&gt;
    = x2 (- nsRight 8)&lt;br /&gt;
    = y2 (- nsBottom 8)&lt;br /&gt;
    = w (- nsRight nsLeft)&lt;br /&gt;
    = h (- nsBottom nsTop)&lt;br /&gt;
    TextSize(@rect text font)&lt;br /&gt;
&lt;br /&gt;
    // Draw the side borders&lt;br /&gt;
    (for(= y(+ nsTop 8)) (&amp;lt; y y2) (= y + y 8)&lt;br /&gt;
      DrawCel(900 0 4 nsLeft y -1)&lt;br /&gt;
      DrawCel(900 0 6 x2   y -1)&lt;br /&gt;
    )&lt;br /&gt;
    // Draw the top and bottom borders&lt;br /&gt;
    (for(= x(+ nsLeft 8)) (&amp;lt; x x2) (= x + x 8)&lt;br /&gt;
      DrawCel(900 0 5 x nsTop -1)&lt;br /&gt;
      DrawCel(900 0 7 x y2   -1)&lt;br /&gt;
    )&lt;br /&gt;
    // Draw the corners&lt;br /&gt;
    DrawCel(900 0 0 nsLeft nsTop -1)&lt;br /&gt;
    DrawCel(900 0 1 x2   nsTop -1)&lt;br /&gt;
    DrawCel(900 0 2 nsLeft y2  -1)&lt;br /&gt;
    DrawCel(900 0 3 x2   y2  -1)&lt;br /&gt;
    // Draw the text&lt;br /&gt;
    Display(text&lt;br /&gt;
      dsCOORD&lt;br /&gt;
        + nsLeft (&amp;gt;&amp;gt; (- w rect[rtRIGHT]) 1)&lt;br /&gt;
        + (+ nsTop (&amp;gt;&amp;gt; (- h rect[rtBOTTOM]) 1) 1)&lt;br /&gt;
      dsCOLOR&lt;br /&gt;
        gWndColor&lt;br /&gt;
      dsBACKGROUND&lt;br /&gt;
        clTRANSPARENT&lt;br /&gt;
      dsFONT&lt;br /&gt;
        font&lt;br /&gt;
      dsWIDTH&lt;br /&gt;
        rect[rtRIGHT]&lt;br /&gt;
    )&lt;br /&gt;
  )&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
SCI code for SCI Companion. &lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;  (method (draw &amp;amp;tmp x y x2 y2 w h [rect 4])&lt;br /&gt;
		; Calculate the areas&lt;br /&gt;
		(= x2 (- nsRight 8))&lt;br /&gt;
		(= y2 (- nsBottom 8))&lt;br /&gt;
		(= w (- nsRight nsLeft))&lt;br /&gt;
		(= h (- nsBottom nsTop))&lt;br /&gt;
		(TextSize @rect text font)&lt;br /&gt;
		; Draw the side borders&lt;br /&gt;
		(for ( (= y (+ nsTop 8))) (&amp;lt; y y2)  ( (= y (+ y 8))) (DrawCel 902 0 4 nsLeft y -1) (DrawCel 902 0 6 x2 y -1))&lt;br /&gt;
		; Draw the top and bottom borders&lt;br /&gt;
		(for ( (= x (+ nsLeft 8))) (&amp;lt; x x2)  ( (= x (+ x 8))) (DrawCel 902 0 5 x nsTop -1) (DrawCel 902 0 7 x y2 -1))&lt;br /&gt;
		; Draw the corners&lt;br /&gt;
		(DrawCel 902 0 0 nsLeft nsTop -1)&lt;br /&gt;
		(DrawCel 902 0 1 x2 nsTop -1)&lt;br /&gt;
		(DrawCel 902 0 2 nsLeft y2 -1)&lt;br /&gt;
		(DrawCel 902 0 3 x2 y2 -1)&lt;br /&gt;
		; Draw the text&lt;br /&gt;
		(Display&lt;br /&gt;
			text&lt;br /&gt;
			dsCOORD&lt;br /&gt;
				(+ nsLeft (&amp;gt;&amp;gt; (- w [rect rtRIGHT]) 1))&lt;br /&gt;
				(+ (+ nsTop (&amp;gt;&amp;gt; (- h [rect rtBOTTOM]) 1)) 1)&lt;br /&gt;
			dsCOLOR gWndColor&lt;br /&gt;
			dsBACKGROUND clTRANSPARENT&lt;br /&gt;
			dsFONT font&lt;br /&gt;
			dsWIDTH [rect rtRIGHT]&lt;br /&gt;
		)&lt;br /&gt;
	)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Needless to say, that code draws the button. It draws the border and edges, then centers and draws the text. It doesn&amp;#039;t bother drawing the inside of the button and just leaves it transparent for speed. It would be a lot slower if it filled in the button with cels.&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| width=&amp;quot;100%&amp;quot;&lt;br /&gt;
| width=&amp;quot;113&amp;quot; | [[Image:Script-Main.png|Main Script]]&lt;br /&gt;
| width=&amp;quot;100%&amp;quot; | Chances are, you&amp;#039;ll want to customize the window colors to go with the button, right? If that&amp;#039;s the case, open up the &amp;quot;&amp;#039;&amp;#039;&amp;#039;Main.sc&amp;#039;&amp;#039;&amp;#039;&amp;quot; script.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
{| width=&amp;quot;100%&amp;quot;&lt;br /&gt;
| width=&amp;quot;216&amp;quot; | [[Image:Script-GameInstance.png|Game Instance]]&lt;br /&gt;
| width=&amp;quot;100%&amp;quot; | Next, scroll down main.sc to the Game instance.&lt;br /&gt;
&lt;br /&gt;
At the very top of the init() method, you will see the window color initialization.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* The gWndColor is the color for the text and borders of of the non-custom controls.&lt;br /&gt;
* The gWndBack is the color of the actual window.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&lt;br /&gt;
To go with the default custom button, we&amp;#039;ll make the window silver. Change: &lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;= gWndBack clWHITE&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
To:&lt;br /&gt;
To go with the default custom button, we&amp;#039;ll make the window silver. Change: &lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;= gWndBack clSILVER&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p align=&amp;quot;center&amp;quot;&amp;gt;Run the game all you&amp;#039;ll see your brand new custom buttons!&amp;lt;br /&amp;gt;[[Image:Controls-QuitDialog.png|Quit Button]]&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
That sums it up! Be sure to check out how to make custom windows and gauges!&lt;br /&gt;
&lt;br /&gt;
&amp;amp;nbsp;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;float: left&amp;quot;&amp;gt;[[Checking a Door&amp;#039;s State|&amp;amp;lt; Previous: Chapter 6 - Checking a Door&amp;#039;s State]]&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;span style=&amp;quot;float: right&amp;quot;&amp;gt;[[Custom Windows|Chapter 8 - Creating Custom Windows &amp;amp;gt;]]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;amp;nbsp;&lt;br /&gt;
&lt;br /&gt;
[[Category:Controls]]&lt;br /&gt;
[[Category:Tutorials]]&lt;/div&gt;</summary>
		<author><name>Rob Craig</name></author>
	</entry>
	<entry>
		<id>http://sciwiki.sierrahelp.com/index.php?title=Custom_Buttons&amp;diff=16024</id>
		<title>Custom Buttons</title>
		<link rel="alternate" type="text/html" href="http://sciwiki.sierrahelp.com/index.php?title=Custom_Buttons&amp;diff=16024"/>
		<updated>2023-06-01T08:36:03Z</updated>

		<summary type="html">&lt;p&gt;Rob Craig: /* Scripting The Button */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Chapter 7 - Creating Custom Buttons=&lt;br /&gt;
&lt;br /&gt;
By default, the interpreter draws all the windows and controls for the game&amp;#039;s GUI. However, with some creative coding, they can be easily customized. This tutorial will teach you how to create custom buttons with views.&lt;br /&gt;
&lt;br /&gt;
===Load The Game===&lt;br /&gt;
&lt;br /&gt;
First you need to open your game in SCI Studio, loading the Resource Explorer.&lt;br /&gt;
&lt;br /&gt;
===The Button View===&lt;br /&gt;
&lt;br /&gt;
First the buttons will need a view so there&amp;#039;s something to draw. I&amp;#039;ve set up the view so that cels 0-3 are for the button&amp;#039;s edges, and 4-7 are for the left, top, right and bottom borders. It can be easily customized to create your own custom button.&lt;br /&gt;
&lt;br /&gt;
The cels are 8x8 pixels. Though they really would only need to be 4x4, they should be no less than 8x8. If they are too small, it will take too long to draw the buttons.&lt;br /&gt;
&lt;br /&gt;
To save time, [http://sierrahelp.com/Files/SCI/view.900 click here] and download it.&lt;br /&gt;
&lt;br /&gt;
Add the view to the game. I chose to number it view.900, but it can be numbered anything you like.&lt;br /&gt;
&lt;br /&gt;
===Scripting The Button===&lt;br /&gt;
&lt;br /&gt;
In the resource explorer, select &amp;#039;&amp;#039;&amp;#039;Script&amp;#039;&amp;#039;&amp;#039; from the left resource tree. This will bring up the list of scripts in your game on the right. Double click on the &amp;quot;&amp;#039;&amp;#039;&amp;#039;Controls.sc&amp;#039;&amp;#039;&amp;#039;&amp;quot; script. It will load it up in the script editor.&lt;br /&gt;
&lt;br /&gt;
Though customizing a button is generally simple, there are many extra steps which must be taken to give it optimum performance and prevent interference.&lt;br /&gt;
&lt;br /&gt;
{| width=&amp;quot;100%&amp;quot;&lt;br /&gt;
| width=&amp;quot;216&amp;quot; | [[Image:Controls-DButton.png|DButton class]]&lt;br /&gt;
| width=&amp;quot;100%&amp;quot; valign=&amp;quot;top&amp;quot; | First, scroll down controls.sc to the DButton class.&lt;br /&gt;
|-&lt;br /&gt;
| width=&amp;quot;216&amp;quot; | [[Image:Controls-SetSize.png|setSize() method]]&lt;br /&gt;
| width=&amp;quot;100%&amp;quot; valign=&amp;quot;top&amp;quot; | Next, scroll down to the setSize() method.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&lt;br /&gt;
(Studio Script).&lt;br /&gt;
Change:&lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;= nsBottom (+ nsTop rect[rtBOTTOM])&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
(Studio Script example) to:&lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;= nsBottom (+ nsTop(| (&amp;amp; rect[rtBOTTOM] $FFFC) 7))&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
(Sierra Script)&lt;br /&gt;
Change:&lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;(= nsBottom (+ nsTop (| (&amp;amp; [rect rtBOTTOM] $FFFC) 7)))&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
(Sierra Script)&lt;br /&gt;
To:&lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;(= nsBottom (+ nsTop (| (&amp;amp; [rect rtBOTTOM] $FFFC) 7)))&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
(Studio Script) &lt;br /&gt;
Change: &lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;(= nsBottom (+ nsTop (| (&amp;amp; [rect rtBOTTOM] $FFFC) 7)))&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
(Studio Script) to:&lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;= nsRight (+ (| (&amp;amp; rect[rtRIGHT] $FFFC) 7) nsLeft)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
(Sierra Script)&lt;br /&gt;
To:&lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;(= nsRight (+ (| (&amp;amp; [rect rtRIGHT] $FFFC) 7) nsLeft))&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This makes the control always in dimensions divisible by eight (i.e. 8,16,24,32,etc.). This is needed because we are using 8x8 cels.&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Next, we&amp;#039;ll need to add a draw method to the DButton class to override the default one.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&lt;br /&gt;
Add the following code to the DButton class. &lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;  (method (draw)&lt;br /&gt;
    (var x, y, x2, y2, w, h, rect[4])&lt;br /&gt;
    &lt;br /&gt;
    // Calculate the areas&lt;br /&gt;
    = x2 (- nsRight 8)&lt;br /&gt;
    = y2 (- nsBottom 8)&lt;br /&gt;
    = w (- nsRight nsLeft)&lt;br /&gt;
    = h (- nsBottom nsTop)&lt;br /&gt;
    TextSize(@rect text font)&lt;br /&gt;
&lt;br /&gt;
    // Draw the side borders&lt;br /&gt;
    (for(= y(+ nsTop 8)) (&amp;lt; y y2) (= y + y 8)&lt;br /&gt;
      DrawCel(900 0 4 nsLeft y -1)&lt;br /&gt;
      DrawCel(900 0 6 x2   y -1)&lt;br /&gt;
    )&lt;br /&gt;
    // Draw the top and bottom borders&lt;br /&gt;
    (for(= x(+ nsLeft 8)) (&amp;lt; x x2) (= x + x 8)&lt;br /&gt;
      DrawCel(900 0 5 x nsTop -1)&lt;br /&gt;
      DrawCel(900 0 7 x y2   -1)&lt;br /&gt;
    )&lt;br /&gt;
    // Draw the corners&lt;br /&gt;
    DrawCel(900 0 0 nsLeft nsTop -1)&lt;br /&gt;
    DrawCel(900 0 1 x2   nsTop -1)&lt;br /&gt;
    DrawCel(900 0 2 nsLeft y2  -1)&lt;br /&gt;
    DrawCel(900 0 3 x2   y2  -1)&lt;br /&gt;
    // Draw the text&lt;br /&gt;
    Display(text&lt;br /&gt;
      dsCOORD&lt;br /&gt;
        + nsLeft (&amp;gt;&amp;gt; (- w rect[rtRIGHT]) 1)&lt;br /&gt;
        + (+ nsTop (&amp;gt;&amp;gt; (- h rect[rtBOTTOM]) 1) 1)&lt;br /&gt;
      dsCOLOR&lt;br /&gt;
        gWndColor&lt;br /&gt;
      dsBACKGROUND&lt;br /&gt;
        clTRANSPARENT&lt;br /&gt;
      dsFONT&lt;br /&gt;
        font&lt;br /&gt;
      dsWIDTH&lt;br /&gt;
        rect[rtRIGHT]&lt;br /&gt;
    )&lt;br /&gt;
  )&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
SCI code for SCI Companion. &lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;  (method (draw &amp;amp;tmp x y x2 y2 w h [rect 4])&lt;br /&gt;
		; Calculate the areas&lt;br /&gt;
		(= x2 (- nsRight 8))&lt;br /&gt;
		(= y2 (- nsBottom 8))&lt;br /&gt;
		(= w (- nsRight nsLeft))&lt;br /&gt;
		(= h (- nsBottom nsTop))&lt;br /&gt;
		(TextSize @rect text font)&lt;br /&gt;
		; Draw the side borders&lt;br /&gt;
		(for ( (= y (+ nsTop 8))) (&amp;lt; y y2)  ( (= y (+ y 8))) (DrawCel 902 0 4 nsLeft y -1) (DrawCel 902 0 6 x2 y -1))&lt;br /&gt;
		; Draw the top and bottom borders&lt;br /&gt;
		(for ( (= x (+ nsLeft 8))) (&amp;lt; x x2)  ( (= x (+ x 8))) (DrawCel 902 0 5 x nsTop -1) (DrawCel 902 0 7 x y2 -1))&lt;br /&gt;
		; Draw the corners&lt;br /&gt;
		(DrawCel 902 0 0 nsLeft nsTop -1)&lt;br /&gt;
		(DrawCel 902 0 1 x2 nsTop -1)&lt;br /&gt;
		(DrawCel 902 0 2 nsLeft y2 -1)&lt;br /&gt;
		(DrawCel 902 0 3 x2 y2 -1)&lt;br /&gt;
		; Draw the text&lt;br /&gt;
		(Display&lt;br /&gt;
			text&lt;br /&gt;
			dsCOORD&lt;br /&gt;
				(+ nsLeft (&amp;gt;&amp;gt; (- w [rect rtRIGHT]) 1))&lt;br /&gt;
				(+ (+ nsTop (&amp;gt;&amp;gt; (- h [rect rtBOTTOM]) 1)) 1)&lt;br /&gt;
			dsCOLOR gWndColor&lt;br /&gt;
			dsBACKGROUND clTRANSPARENT&lt;br /&gt;
			dsFONT font&lt;br /&gt;
			dsWIDTH [rect rtRIGHT]&lt;br /&gt;
		)&lt;br /&gt;
	)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Needless to say, that code draws the button. It draws the border and edges, then centers and draws the text. It doesn&amp;#039;t bother drawing the inside of the button and just leaves it transparent for speed. It would be a lot slower if it filled in the button with cels.&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| width=&amp;quot;100%&amp;quot;&lt;br /&gt;
| width=&amp;quot;113&amp;quot; | [[Image:Script-Main.png|Main Script]]&lt;br /&gt;
| width=&amp;quot;100%&amp;quot; | Chances are, you&amp;#039;ll want to customize the window colors to go with the button, right? If that&amp;#039;s the case, open up the &amp;quot;&amp;#039;&amp;#039;&amp;#039;Main.sc&amp;#039;&amp;#039;&amp;#039;&amp;quot; script.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
{| width=&amp;quot;100%&amp;quot;&lt;br /&gt;
| width=&amp;quot;216&amp;quot; | [[Image:Script-GameInstance.png|Game Instance]]&lt;br /&gt;
| width=&amp;quot;100%&amp;quot; | Next, scroll down main.sc to the Game instance.&lt;br /&gt;
&lt;br /&gt;
At the very top of the init() method, you will see the window color initialization.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* The gWndColor is the color for the text and borders of of the non-custom controls.&lt;br /&gt;
* The gWndBack is the color of the actual window.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&lt;br /&gt;
To go with the default custom button, we&amp;#039;ll make the window silver. Change: &lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;= gWndBack clWHITE&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
To:&lt;br /&gt;
To go with the default custom button, we&amp;#039;ll make the window silver. Change: &lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;= gWndBack clSILVER&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p align=&amp;quot;center&amp;quot;&amp;gt;Run the game all you&amp;#039;ll see your brand new custom buttons!&amp;lt;br /&amp;gt;[[Image:Controls-QuitDialog.png|Quit Button]]&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
That sums it up! Be sure to check out how to make custom windows and gauges!&lt;br /&gt;
&lt;br /&gt;
&amp;amp;nbsp;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;float: left&amp;quot;&amp;gt;[[Checking a Door&amp;#039;s State|&amp;amp;lt; Previous: Chapter 6 - Checking a Door&amp;#039;s State]]&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;span style=&amp;quot;float: right&amp;quot;&amp;gt;[[Custom Windows|Chapter 8 - Creating Custom Windows &amp;amp;gt;]]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;amp;nbsp;&lt;br /&gt;
&lt;br /&gt;
[[Category:Controls]]&lt;br /&gt;
[[Category:Tutorials]]&lt;/div&gt;</summary>
		<author><name>Rob Craig</name></author>
	</entry>
	<entry>
		<id>http://sciwiki.sierrahelp.com/index.php?title=Custom_Buttons&amp;diff=16023</id>
		<title>Custom Buttons</title>
		<link rel="alternate" type="text/html" href="http://sciwiki.sierrahelp.com/index.php?title=Custom_Buttons&amp;diff=16023"/>
		<updated>2023-06-01T08:29:34Z</updated>

		<summary type="html">&lt;p&gt;Rob Craig: /* Scripting The Button */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Chapter 7 - Creating Custom Buttons=&lt;br /&gt;
&lt;br /&gt;
By default, the interpreter draws all the windows and controls for the game&amp;#039;s GUI. However, with some creative coding, they can be easily customized. This tutorial will teach you how to create custom buttons with views.&lt;br /&gt;
&lt;br /&gt;
===Load The Game===&lt;br /&gt;
&lt;br /&gt;
First you need to open your game in SCI Studio, loading the Resource Explorer.&lt;br /&gt;
&lt;br /&gt;
===The Button View===&lt;br /&gt;
&lt;br /&gt;
First the buttons will need a view so there&amp;#039;s something to draw. I&amp;#039;ve set up the view so that cels 0-3 are for the button&amp;#039;s edges, and 4-7 are for the left, top, right and bottom borders. It can be easily customized to create your own custom button.&lt;br /&gt;
&lt;br /&gt;
The cels are 8x8 pixels. Though they really would only need to be 4x4, they should be no less than 8x8. If they are too small, it will take too long to draw the buttons.&lt;br /&gt;
&lt;br /&gt;
To save time, [http://sierrahelp.com/Files/SCI/view.900 click here] and download it.&lt;br /&gt;
&lt;br /&gt;
Add the view to the game. I chose to number it view.900, but it can be numbered anything you like.&lt;br /&gt;
&lt;br /&gt;
===Scripting The Button===&lt;br /&gt;
&lt;br /&gt;
In the resource explorer, select &amp;#039;&amp;#039;&amp;#039;Script&amp;#039;&amp;#039;&amp;#039; from the left resource tree. This will bring up the list of scripts in your game on the right. Double click on the &amp;quot;&amp;#039;&amp;#039;&amp;#039;Controls.sc&amp;#039;&amp;#039;&amp;#039;&amp;quot; script. It will load it up in the script editor.&lt;br /&gt;
&lt;br /&gt;
Though customizing a button is generally simple, there are many extra steps which must be taken to give it optimum performance and prevent interference.&lt;br /&gt;
&lt;br /&gt;
{| width=&amp;quot;100%&amp;quot;&lt;br /&gt;
| width=&amp;quot;216&amp;quot; | [[Image:Controls-DButton.png|DButton class]]&lt;br /&gt;
| width=&amp;quot;100%&amp;quot; valign=&amp;quot;top&amp;quot; | First, scroll down controls.sc to the DButton class.&lt;br /&gt;
|-&lt;br /&gt;
| width=&amp;quot;216&amp;quot; | [[Image:Controls-SetSize.png|setSize() method]]&lt;br /&gt;
| width=&amp;quot;100%&amp;quot; valign=&amp;quot;top&amp;quot; | Next, scroll down to the setSize() method.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&lt;br /&gt;
(Studio Script).&lt;br /&gt;
Change:&lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;= nsBottom (+ nsTop rect[rtBOTTOM])&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
(Studio Script example) to:&lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;= nsBottom (+ nsTop(| (&amp;amp; rect[rtBOTTOM] $FFFC) 7))&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
(Sierra Script)&lt;br /&gt;
To:&lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;(= nsBottom (+ nsTop (| (&amp;amp; [rect rtBOTTOM] $FFFC) 7)))&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
(Studio Script) &lt;br /&gt;
Change: &lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;(= nsBottom (+ nsTop (| (&amp;amp; [rect rtBOTTOM] $FFFC) 7)))&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
(Studio Script) to:&lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;= nsRight (+ (| (&amp;amp; rect[rtRIGHT] $FFFC) 7) nsLeft)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
(Sierra Script)&lt;br /&gt;
To:&lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;(= nsRight (+ (| (&amp;amp; [rect rtRIGHT] $FFFC) 7) nsLeft))&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This makes the control always in dimensions divisible by eight (i.e. 8,16,24,32,etc.). This is needed because we are using 8x8 cels.&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Next, we&amp;#039;ll need to add a draw method to the DButton class to override the default one.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&lt;br /&gt;
Add the following code to the DButton class. &lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;  (method (draw)&lt;br /&gt;
    (var x, y, x2, y2, w, h, rect[4])&lt;br /&gt;
    &lt;br /&gt;
    // Calculate the areas&lt;br /&gt;
    = x2 (- nsRight 8)&lt;br /&gt;
    = y2 (- nsBottom 8)&lt;br /&gt;
    = w (- nsRight nsLeft)&lt;br /&gt;
    = h (- nsBottom nsTop)&lt;br /&gt;
    TextSize(@rect text font)&lt;br /&gt;
&lt;br /&gt;
    // Draw the side borders&lt;br /&gt;
    (for(= y(+ nsTop 8)) (&amp;lt; y y2) (= y + y 8)&lt;br /&gt;
      DrawCel(900 0 4 nsLeft y -1)&lt;br /&gt;
      DrawCel(900 0 6 x2   y -1)&lt;br /&gt;
    )&lt;br /&gt;
    // Draw the top and bottom borders&lt;br /&gt;
    (for(= x(+ nsLeft 8)) (&amp;lt; x x2) (= x + x 8)&lt;br /&gt;
      DrawCel(900 0 5 x nsTop -1)&lt;br /&gt;
      DrawCel(900 0 7 x y2   -1)&lt;br /&gt;
    )&lt;br /&gt;
    // Draw the corners&lt;br /&gt;
    DrawCel(900 0 0 nsLeft nsTop -1)&lt;br /&gt;
    DrawCel(900 0 1 x2   nsTop -1)&lt;br /&gt;
    DrawCel(900 0 2 nsLeft y2  -1)&lt;br /&gt;
    DrawCel(900 0 3 x2   y2  -1)&lt;br /&gt;
    // Draw the text&lt;br /&gt;
    Display(text&lt;br /&gt;
      dsCOORD&lt;br /&gt;
        + nsLeft (&amp;gt;&amp;gt; (- w rect[rtRIGHT]) 1)&lt;br /&gt;
        + (+ nsTop (&amp;gt;&amp;gt; (- h rect[rtBOTTOM]) 1) 1)&lt;br /&gt;
      dsCOLOR&lt;br /&gt;
        gWndColor&lt;br /&gt;
      dsBACKGROUND&lt;br /&gt;
        clTRANSPARENT&lt;br /&gt;
      dsFONT&lt;br /&gt;
        font&lt;br /&gt;
      dsWIDTH&lt;br /&gt;
        rect[rtRIGHT]&lt;br /&gt;
    )&lt;br /&gt;
  )&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
SCI code for SCI Companion. &lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;  (method (draw &amp;amp;tmp x y x2 y2 w h [rect 4])&lt;br /&gt;
		; Calculate the areas&lt;br /&gt;
		(= x2 (- nsRight 8))&lt;br /&gt;
		(= y2 (- nsBottom 8))&lt;br /&gt;
		(= w (- nsRight nsLeft))&lt;br /&gt;
		(= h (- nsBottom nsTop))&lt;br /&gt;
		(TextSize @rect text font)&lt;br /&gt;
		; Draw the side borders&lt;br /&gt;
		(for ( (= y (+ nsTop 8))) (&amp;lt; y y2)  ( (= y (+ y 8))) (DrawCel 902 0 4 nsLeft y -1) (DrawCel 902 0 6 x2 y -1))&lt;br /&gt;
		; Draw the top and bottom borders&lt;br /&gt;
		(for ( (= x (+ nsLeft 8))) (&amp;lt; x x2)  ( (= x (+ x 8))) (DrawCel 902 0 5 x nsTop -1) (DrawCel 902 0 7 x y2 -1))&lt;br /&gt;
		; Draw the corners&lt;br /&gt;
		(DrawCel 902 0 0 nsLeft nsTop -1)&lt;br /&gt;
		(DrawCel 902 0 1 x2 nsTop -1)&lt;br /&gt;
		(DrawCel 902 0 2 nsLeft y2 -1)&lt;br /&gt;
		(DrawCel 902 0 3 x2 y2 -1)&lt;br /&gt;
		; Draw the text&lt;br /&gt;
		(Display&lt;br /&gt;
			text&lt;br /&gt;
			dsCOORD&lt;br /&gt;
				(+ nsLeft (&amp;gt;&amp;gt; (- w [rect rtRIGHT]) 1))&lt;br /&gt;
				(+ (+ nsTop (&amp;gt;&amp;gt; (- h [rect rtBOTTOM]) 1)) 1)&lt;br /&gt;
			dsCOLOR gWndColor&lt;br /&gt;
			dsBACKGROUND clTRANSPARENT&lt;br /&gt;
			dsFONT font&lt;br /&gt;
			dsWIDTH [rect rtRIGHT]&lt;br /&gt;
		)&lt;br /&gt;
	)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Needless to say, that code draws the button. It draws the border and edges, then centers and draws the text. It doesn&amp;#039;t bother drawing the inside of the button and just leaves it transparent for speed. It would be a lot slower if it filled in the button with cels.&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| width=&amp;quot;100%&amp;quot;&lt;br /&gt;
| width=&amp;quot;113&amp;quot; | [[Image:Script-Main.png|Main Script]]&lt;br /&gt;
| width=&amp;quot;100%&amp;quot; | Chances are, you&amp;#039;ll want to customize the window colors to go with the button, right? If that&amp;#039;s the case, open up the &amp;quot;&amp;#039;&amp;#039;&amp;#039;Main.sc&amp;#039;&amp;#039;&amp;#039;&amp;quot; script.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
{| width=&amp;quot;100%&amp;quot;&lt;br /&gt;
| width=&amp;quot;216&amp;quot; | [[Image:Script-GameInstance.png|Game Instance]]&lt;br /&gt;
| width=&amp;quot;100%&amp;quot; | Next, scroll down main.sc to the Game instance.&lt;br /&gt;
&lt;br /&gt;
At the very top of the init() method, you will see the window color initialization.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* The gWndColor is the color for the text and borders of of the non-custom controls.&lt;br /&gt;
* The gWndBack is the color of the actual window.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&lt;br /&gt;
To go with the default custom button, we&amp;#039;ll make the window silver. Change: &lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;= gWndBack clWHITE&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
To:&lt;br /&gt;
To go with the default custom button, we&amp;#039;ll make the window silver. Change: &lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;= gWndBack clSILVER&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p align=&amp;quot;center&amp;quot;&amp;gt;Run the game all you&amp;#039;ll see your brand new custom buttons!&amp;lt;br /&amp;gt;[[Image:Controls-QuitDialog.png|Quit Button]]&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
That sums it up! Be sure to check out how to make custom windows and gauges!&lt;br /&gt;
&lt;br /&gt;
&amp;amp;nbsp;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;float: left&amp;quot;&amp;gt;[[Checking a Door&amp;#039;s State|&amp;amp;lt; Previous: Chapter 6 - Checking a Door&amp;#039;s State]]&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;span style=&amp;quot;float: right&amp;quot;&amp;gt;[[Custom Windows|Chapter 8 - Creating Custom Windows &amp;amp;gt;]]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;amp;nbsp;&lt;br /&gt;
&lt;br /&gt;
[[Category:Controls]]&lt;br /&gt;
[[Category:Tutorials]]&lt;/div&gt;</summary>
		<author><name>Rob Craig</name></author>
	</entry>
	<entry>
		<id>http://sciwiki.sierrahelp.com/index.php?title=Custom_Buttons&amp;diff=16022</id>
		<title>Custom Buttons</title>
		<link rel="alternate" type="text/html" href="http://sciwiki.sierrahelp.com/index.php?title=Custom_Buttons&amp;diff=16022"/>
		<updated>2023-06-01T08:27:13Z</updated>

		<summary type="html">&lt;p&gt;Rob Craig: /* Scripting The Button */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Chapter 7 - Creating Custom Buttons=&lt;br /&gt;
&lt;br /&gt;
By default, the interpreter draws all the windows and controls for the game&amp;#039;s GUI. However, with some creative coding, they can be easily customized. This tutorial will teach you how to create custom buttons with views.&lt;br /&gt;
&lt;br /&gt;
===Load The Game===&lt;br /&gt;
&lt;br /&gt;
First you need to open your game in SCI Studio, loading the Resource Explorer.&lt;br /&gt;
&lt;br /&gt;
===The Button View===&lt;br /&gt;
&lt;br /&gt;
First the buttons will need a view so there&amp;#039;s something to draw. I&amp;#039;ve set up the view so that cels 0-3 are for the button&amp;#039;s edges, and 4-7 are for the left, top, right and bottom borders. It can be easily customized to create your own custom button.&lt;br /&gt;
&lt;br /&gt;
The cels are 8x8 pixels. Though they really would only need to be 4x4, they should be no less than 8x8. If they are too small, it will take too long to draw the buttons.&lt;br /&gt;
&lt;br /&gt;
To save time, [http://sierrahelp.com/Files/SCI/view.900 click here] and download it.&lt;br /&gt;
&lt;br /&gt;
Add the view to the game. I chose to number it view.900, but it can be numbered anything you like.&lt;br /&gt;
&lt;br /&gt;
===Scripting The Button===&lt;br /&gt;
&lt;br /&gt;
In the resource explorer, select &amp;#039;&amp;#039;&amp;#039;Script&amp;#039;&amp;#039;&amp;#039; from the left resource tree. This will bring up the list of scripts in your game on the right. Double click on the &amp;quot;&amp;#039;&amp;#039;&amp;#039;Controls.sc&amp;#039;&amp;#039;&amp;#039;&amp;quot; script. It will load it up in the script editor.&lt;br /&gt;
&lt;br /&gt;
Though customizing a button is generally simple, there are many extra steps which must be taken to give it optimum performance and prevent interference.&lt;br /&gt;
&lt;br /&gt;
{| width=&amp;quot;100%&amp;quot;&lt;br /&gt;
| width=&amp;quot;216&amp;quot; | [[Image:Controls-DButton.png|DButton class]]&lt;br /&gt;
| width=&amp;quot;100%&amp;quot; valign=&amp;quot;top&amp;quot; | First, scroll down controls.sc to the DButton class.&lt;br /&gt;
|-&lt;br /&gt;
| width=&amp;quot;216&amp;quot; | [[Image:Controls-SetSize.png|setSize() method]]&lt;br /&gt;
| width=&amp;quot;100%&amp;quot; valign=&amp;quot;top&amp;quot; | Next, scroll down to the setSize() method.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&lt;br /&gt;
Studio Script example.&lt;br /&gt;
Change:&lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;= nsBottom (+ nsTop rect[rtBOTTOM])&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
to:&lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;= nsBottom (+ nsTop(| (&amp;amp; rect[rtBOTTOM] $FFFC) 7))&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Sierra Script example.&lt;br /&gt;
Change:&lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;(= nsBottom (+ nsTop (| (&amp;amp; [rect rtBOTTOM] $FFFC) 7)))&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Studio Script example &lt;br /&gt;
Change: &lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;(= nsBottom (+ nsTop (| (&amp;amp; [rect rtBOTTOM] $FFFC) 7)))&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
to:&lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;= nsRight (+ (| (&amp;amp; rect[rtRIGHT] $FFFC) 7) nsLeft)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Sierra Script example.&lt;br /&gt;
Change:&lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;(= nsRight (+ (| (&amp;amp; [rect rtRIGHT] $FFFC) 7) nsLeft))&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This makes the control always in dimensions divisible by eight (i.e. 8,16,24,32,etc.). This is needed because we are using 8x8 cels.&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Next, we&amp;#039;ll need to add a draw method to the DButton class to override the default one.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&lt;br /&gt;
Add the following code to the DButton class. &lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;  (method (draw)&lt;br /&gt;
    (var x, y, x2, y2, w, h, rect[4])&lt;br /&gt;
    &lt;br /&gt;
    // Calculate the areas&lt;br /&gt;
    = x2 (- nsRight 8)&lt;br /&gt;
    = y2 (- nsBottom 8)&lt;br /&gt;
    = w (- nsRight nsLeft)&lt;br /&gt;
    = h (- nsBottom nsTop)&lt;br /&gt;
    TextSize(@rect text font)&lt;br /&gt;
&lt;br /&gt;
    // Draw the side borders&lt;br /&gt;
    (for(= y(+ nsTop 8)) (&amp;lt; y y2) (= y + y 8)&lt;br /&gt;
      DrawCel(900 0 4 nsLeft y -1)&lt;br /&gt;
      DrawCel(900 0 6 x2   y -1)&lt;br /&gt;
    )&lt;br /&gt;
    // Draw the top and bottom borders&lt;br /&gt;
    (for(= x(+ nsLeft 8)) (&amp;lt; x x2) (= x + x 8)&lt;br /&gt;
      DrawCel(900 0 5 x nsTop -1)&lt;br /&gt;
      DrawCel(900 0 7 x y2   -1)&lt;br /&gt;
    )&lt;br /&gt;
    // Draw the corners&lt;br /&gt;
    DrawCel(900 0 0 nsLeft nsTop -1)&lt;br /&gt;
    DrawCel(900 0 1 x2   nsTop -1)&lt;br /&gt;
    DrawCel(900 0 2 nsLeft y2  -1)&lt;br /&gt;
    DrawCel(900 0 3 x2   y2  -1)&lt;br /&gt;
    // Draw the text&lt;br /&gt;
    Display(text&lt;br /&gt;
      dsCOORD&lt;br /&gt;
        + nsLeft (&amp;gt;&amp;gt; (- w rect[rtRIGHT]) 1)&lt;br /&gt;
        + (+ nsTop (&amp;gt;&amp;gt; (- h rect[rtBOTTOM]) 1) 1)&lt;br /&gt;
      dsCOLOR&lt;br /&gt;
        gWndColor&lt;br /&gt;
      dsBACKGROUND&lt;br /&gt;
        clTRANSPARENT&lt;br /&gt;
      dsFONT&lt;br /&gt;
        font&lt;br /&gt;
      dsWIDTH&lt;br /&gt;
        rect[rtRIGHT]&lt;br /&gt;
    )&lt;br /&gt;
  )&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
SCI code for SCI Companion. &lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;  (method (draw &amp;amp;tmp x y x2 y2 w h [rect 4])&lt;br /&gt;
		; Calculate the areas&lt;br /&gt;
		(= x2 (- nsRight 8))&lt;br /&gt;
		(= y2 (- nsBottom 8))&lt;br /&gt;
		(= w (- nsRight nsLeft))&lt;br /&gt;
		(= h (- nsBottom nsTop))&lt;br /&gt;
		(TextSize @rect text font)&lt;br /&gt;
		; Draw the side borders&lt;br /&gt;
		(for ( (= y (+ nsTop 8))) (&amp;lt; y y2)  ( (= y (+ y 8))) (DrawCel 902 0 4 nsLeft y -1) (DrawCel 902 0 6 x2 y -1))&lt;br /&gt;
		; Draw the top and bottom borders&lt;br /&gt;
		(for ( (= x (+ nsLeft 8))) (&amp;lt; x x2)  ( (= x (+ x 8))) (DrawCel 902 0 5 x nsTop -1) (DrawCel 902 0 7 x y2 -1))&lt;br /&gt;
		; Draw the corners&lt;br /&gt;
		(DrawCel 902 0 0 nsLeft nsTop -1)&lt;br /&gt;
		(DrawCel 902 0 1 x2 nsTop -1)&lt;br /&gt;
		(DrawCel 902 0 2 nsLeft y2 -1)&lt;br /&gt;
		(DrawCel 902 0 3 x2 y2 -1)&lt;br /&gt;
		; Draw the text&lt;br /&gt;
		(Display&lt;br /&gt;
			text&lt;br /&gt;
			dsCOORD&lt;br /&gt;
				(+ nsLeft (&amp;gt;&amp;gt; (- w [rect rtRIGHT]) 1))&lt;br /&gt;
				(+ (+ nsTop (&amp;gt;&amp;gt; (- h [rect rtBOTTOM]) 1)) 1)&lt;br /&gt;
			dsCOLOR gWndColor&lt;br /&gt;
			dsBACKGROUND clTRANSPARENT&lt;br /&gt;
			dsFONT font&lt;br /&gt;
			dsWIDTH [rect rtRIGHT]&lt;br /&gt;
		)&lt;br /&gt;
	)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Needless to say, that code draws the button. It draws the border and edges, then centers and draws the text. It doesn&amp;#039;t bother drawing the inside of the button and just leaves it transparent for speed. It would be a lot slower if it filled in the button with cels.&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| width=&amp;quot;100%&amp;quot;&lt;br /&gt;
| width=&amp;quot;113&amp;quot; | [[Image:Script-Main.png|Main Script]]&lt;br /&gt;
| width=&amp;quot;100%&amp;quot; | Chances are, you&amp;#039;ll want to customize the window colors to go with the button, right? If that&amp;#039;s the case, open up the &amp;quot;&amp;#039;&amp;#039;&amp;#039;Main.sc&amp;#039;&amp;#039;&amp;#039;&amp;quot; script.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
{| width=&amp;quot;100%&amp;quot;&lt;br /&gt;
| width=&amp;quot;216&amp;quot; | [[Image:Script-GameInstance.png|Game Instance]]&lt;br /&gt;
| width=&amp;quot;100%&amp;quot; | Next, scroll down main.sc to the Game instance.&lt;br /&gt;
&lt;br /&gt;
At the very top of the init() method, you will see the window color initialization.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* The gWndColor is the color for the text and borders of of the non-custom controls.&lt;br /&gt;
* The gWndBack is the color of the actual window.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&lt;br /&gt;
To go with the default custom button, we&amp;#039;ll make the window silver. Change: &lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;= gWndBack clWHITE&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
To:&lt;br /&gt;
To go with the default custom button, we&amp;#039;ll make the window silver. Change: &lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;= gWndBack clSILVER&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p align=&amp;quot;center&amp;quot;&amp;gt;Run the game all you&amp;#039;ll see your brand new custom buttons!&amp;lt;br /&amp;gt;[[Image:Controls-QuitDialog.png|Quit Button]]&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
That sums it up! Be sure to check out how to make custom windows and gauges!&lt;br /&gt;
&lt;br /&gt;
&amp;amp;nbsp;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;float: left&amp;quot;&amp;gt;[[Checking a Door&amp;#039;s State|&amp;amp;lt; Previous: Chapter 6 - Checking a Door&amp;#039;s State]]&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;span style=&amp;quot;float: right&amp;quot;&amp;gt;[[Custom Windows|Chapter 8 - Creating Custom Windows &amp;amp;gt;]]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;amp;nbsp;&lt;br /&gt;
&lt;br /&gt;
[[Category:Controls]]&lt;br /&gt;
[[Category:Tutorials]]&lt;/div&gt;</summary>
		<author><name>Rob Craig</name></author>
	</entry>
	<entry>
		<id>http://sciwiki.sierrahelp.com/index.php?title=WordFail,_syntaxFail_and_pragmaFail&amp;diff=16021</id>
		<title>WordFail, syntaxFail and pragmaFail</title>
		<link rel="alternate" type="text/html" href="http://sciwiki.sierrahelp.com/index.php?title=WordFail,_syntaxFail_and_pragmaFail&amp;diff=16021"/>
		<updated>2023-06-01T08:24:10Z</updated>

		<summary type="html">&lt;p&gt;Rob Craig: /* Adding Response Handlers */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Chapter 2 - Oh, yeah? Well, &amp;quot;%s&amp;quot; this!=&lt;br /&gt;
&lt;br /&gt;
In order to make your game fun and enjoyable, you&amp;#039;ll want it to be more intelligent to the player. By default, if the player enters a word not in the vocabulary, or a sentence that doesn&amp;#039;t make sense, it will just display a message like &amp;quot;I don&amp;#039;t understand &amp;quot;that word&amp;quot;.&amp;quot; or &amp;quot;That sentence doesn&amp;#039;t make sense.&amp;quot;. This can be easily changed.&lt;br /&gt;
&lt;br /&gt;
In Sierra&amp;#039;s games, you&amp;#039;ll notice that it displays different responses when you enter invalid phrases. If you enter a word not in the game&amp;#039;s vocabulary, it will display &amp;quot;Oh, yeah? Well, &amp;quot;the word&amp;quot; this!&amp;quot; or &amp;quot;You don&amp;#039;t need to type the word &amp;quot;the word&amp;quot; to complete this game!&amp;quot;, or &amp;quot;Don&amp;#039;t you ever say the word &amp;quot;the word&amp;quot; again!&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
Implementing an intelligent response system is very easy. There are three types of phrase catchers: &amp;#039;&amp;#039;&amp;#039;wordFail&amp;#039;&amp;#039;&amp;#039;, &amp;#039;&amp;#039;&amp;#039;syntaxFail&amp;#039;&amp;#039;&amp;#039; and &amp;#039;&amp;#039;&amp;#039;pragmaFail&amp;#039;&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;wordFail&amp;#039;&amp;#039;&amp;#039;, is executed when the player enters a word in the phrase that is not in the game&amp;#039;s vocabulary.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;syntaxFail&amp;#039;&amp;#039;&amp;#039; is executed when the player enters an improper sentence.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;pragmaFail&amp;#039;&amp;#039;&amp;#039; is executed when the player enters an valid sentence that is not handled by any said statements.&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Adding Response Handlers ==&lt;br /&gt;
&lt;br /&gt;
The toolbar gives quick access to opening, closing and running games, the resource editors, and the help file. To add the response handlers, you simply need to add the methods by name to your game&amp;#039;s instance.&lt;br /&gt;
&lt;br /&gt;
[[Image:Script-Main.png|Main Script]] First, open up your game&amp;#039;s &amp;quot;main.sc&amp;quot; script.&lt;br /&gt;
&lt;br /&gt;
{| width=&amp;quot;100%&amp;quot;&lt;br /&gt;
| width=&amp;quot;274&amp;quot; | [[Image:Script-GameInstance.png|New Game Dialog]]&lt;br /&gt;
| valign=&amp;quot;top&amp;quot; | Scroll down to the game&amp;#039;s instance.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Scroll to the end of it and add the methods to handle the responses. You can add any or all in any order.&lt;br /&gt;
&lt;br /&gt;
You&amp;#039;ll naturally want multiple responses, and want them randomly said. To do this, we&amp;#039;ll use a combination of a switch statement and Rand() kernel call.&lt;br /&gt;
&lt;br /&gt;
We&amp;#039;ll start with the &amp;#039;&amp;#039;&amp;#039;wordFail&amp;#039;&amp;#039;&amp;#039; method. Here&amp;#039;s an example in SCI Studio Script:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;(method (wordFail theString)&lt;br /&gt;
  (switch(Random(0 4))&lt;br /&gt;
    (case 0&lt;br /&gt;
      FormatPrint(&amp;quot;Oh, yeah? Well, \&amp;quot;%s\&amp;quot; this!&amp;quot; theString)&lt;br /&gt;
    )&lt;br /&gt;
    (case 1&lt;br /&gt;
      FormatPrint(&amp;quot;You may know the word \&amp;quot;%s\&amp;quot; but it&amp;#039;s beyond &amp;#039;s vocabulary!&amp;quot; theString)&lt;br /&gt;
    )&lt;br /&gt;
    (case 2&lt;br /&gt;
      FormatPrint(&amp;quot;Oh, yeah? Well, I&amp;#039;ve got your \&amp;quot;%s\&amp;quot; right here!&amp;quot; theString)&lt;br /&gt;
    )&lt;br /&gt;
    (case 3&lt;br /&gt;
      FormatPrint(&amp;quot;You don&amp;#039;t need to type the word \&amp;quot;%s\&amp;quot; to complete this game!&amp;quot; theString)&lt;br /&gt;
    )&lt;br /&gt;
    (default&lt;br /&gt;
      FormatPrint(&amp;quot;Don&amp;#039;t you ever say the word \&amp;quot;%s\&amp;quot; again!&amp;quot; theString)&lt;br /&gt;
    )&lt;br /&gt;
  )&lt;br /&gt;
)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The &amp;#039;&amp;#039;&amp;#039;wordFail&amp;#039;&amp;#039;&amp;#039; method in Sierra Script:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;	(method (wordFail theString)&lt;br /&gt;
		(switch (Random 0 4)&lt;br /&gt;
			(0&lt;br /&gt;
				(FormatPrint {Oh, yeah? Well, &amp;quot;%s&amp;quot; this!} theString)&lt;br /&gt;
			)&lt;br /&gt;
			(1&lt;br /&gt;
				(FormatPrint&lt;br /&gt;
					{You may know the word &amp;quot;%s&amp;quot; but it&amp;#039;s beyond &amp;#039;s vocabulary!}&lt;br /&gt;
					theString&lt;br /&gt;
				)&lt;br /&gt;
			)&lt;br /&gt;
			(2&lt;br /&gt;
				(FormatPrint&lt;br /&gt;
					{Oh, yeah? Well, I&amp;#039;ve got your &amp;quot;%s&amp;quot; right here!}&lt;br /&gt;
					theString&lt;br /&gt;
				)&lt;br /&gt;
			)&lt;br /&gt;
			(3&lt;br /&gt;
				(FormatPrint&lt;br /&gt;
					{You don&amp;#039;t need to type the word &amp;quot;%s&amp;quot; to complete this game!}&lt;br /&gt;
					theString&lt;br /&gt;
				)&lt;br /&gt;
			)&lt;br /&gt;
			(else &lt;br /&gt;
				(FormatPrint&lt;br /&gt;
					{Don&amp;#039;t you ever say the word &amp;quot;%s&amp;quot; again!}&lt;br /&gt;
					theString&lt;br /&gt;
				)&lt;br /&gt;
			)&lt;br /&gt;
		)&lt;br /&gt;
	)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This generates a random number from 0 to 4 (five possible numbers), and displays a response depending on which is generated.&lt;br /&gt;
&lt;br /&gt;
The syntaxFail and pragmaFail operate identical to wordFail, but I&amp;#039;ll give examples of them as well. &lt;br /&gt;
Here&amp;#039;s an example in SCI Studio Script:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
(method (syntaxFail theString)&lt;br /&gt;
  (switch(Random(0 2))&lt;br /&gt;
    (case 0&lt;br /&gt;
      Print(&amp;quot;That doesn&amp;#039;t appear to be a proper sentence.&amp;quot;)&lt;br /&gt;
    )&lt;br /&gt;
    (case 1&lt;br /&gt;
      Print(&amp;quot;What in the heck are you talking about?&amp;quot;)&lt;br /&gt;
    )&lt;br /&gt;
    (default&lt;br /&gt;
      Print(&amp;quot;That&amp;#039;s probably something you could do, but this game won&amp;#039;t!&amp;quot;)&lt;br /&gt;
    )&lt;br /&gt;
  )&lt;br /&gt;
)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&amp;amp;nbsp;&lt;br /&gt;
Example in Sierra Script:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;&lt;br /&gt;
	(method (syntaxFail theString)&lt;br /&gt;
  		(switch (Random 0 2)&lt;br /&gt;
    		(0&lt;br /&gt;
     		(Print {That doesn&amp;#039;t appear to be a proper sentence.})&lt;br /&gt;
    		)&lt;br /&gt;
    		(1&lt;br /&gt;
      		(Print {What in the hell are you talking about?})&lt;br /&gt;
    		)&lt;br /&gt;
    		(else&lt;br /&gt;
     		(Print {That&amp;#039;s probably something you could do, but this game won&amp;#039;t!})&lt;br /&gt;
    		)&lt;br /&gt;
  		)&lt;br /&gt;
	)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
Here&amp;#039;s an example in SCI Studio Script:&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;(method (pragmaFail theString)&lt;br /&gt;
  (switch(Random(0 2))&lt;br /&gt;
    (case 0&lt;br /&gt;
      Print(&amp;quot;The heck you say?&amp;quot;)&lt;br /&gt;
    )&lt;br /&gt;
    (case 1&lt;br /&gt;
      Print(&amp;quot;You&amp;#039;re too smart for this game!&amp;quot;)&lt;br /&gt;
    )&lt;br /&gt;
    (default&lt;br /&gt;
      Print(&amp;quot;Congratulations! You have dumbfounded this game!&amp;quot;)&lt;br /&gt;
    )&lt;br /&gt;
  )&lt;br /&gt;
)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
An example for pragmaFail in Sierra Script:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;(method (pragmaFail theString)&lt;br /&gt;
  (method (pragmaFail theString)&lt;br /&gt;
  		(switch (Random 0 2)&lt;br /&gt;
    		(0&lt;br /&gt;
      		(Print {The hell you say?})&lt;br /&gt;
    		)&lt;br /&gt;
    		(1&lt;br /&gt;
      		(Print {You&amp;#039;re too smart for this game!})&lt;br /&gt;
    		)&lt;br /&gt;
    		(else&lt;br /&gt;
      		(Print {Congratulations! You have dumbfounded this game!})&lt;br /&gt;
    		)&lt;br /&gt;
  		)&lt;br /&gt;
	)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;amp;nbsp;&lt;br /&gt;
&lt;br /&gt;
The methods all take the string as a parameter. Whether you choose to use it or not is up to you.&lt;br /&gt;
&lt;br /&gt;
You can have as many or as few responses as you like. Just change the random amount and cases.&lt;br /&gt;
&lt;br /&gt;
That sums up global response handlers! Now your game can have attitude!&lt;br /&gt;
&lt;br /&gt;
&amp;amp;nbsp;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;float: left&amp;quot;&amp;gt;[[Global Said() Statements|&amp;amp;lt; Previous: Chapter 1 - Global Said() Statements]]&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;span style=&amp;quot;float: right&amp;quot;&amp;gt;[[Actor Paths|Next: Chapter 3 - Making Actors Move Along Paths &amp;amp;gt;]]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;amp;nbsp;&lt;br /&gt;
&lt;br /&gt;
[[Category:Said() Strings]]&lt;br /&gt;
[[Category:The SCI Parser]]&lt;br /&gt;
[[Category:Tutorials]]&lt;/div&gt;</summary>
		<author><name>Rob Craig</name></author>
	</entry>
	<entry>
		<id>http://sciwiki.sierrahelp.com/index.php?title=Custom_Buttons&amp;diff=16015</id>
		<title>Custom Buttons</title>
		<link rel="alternate" type="text/html" href="http://sciwiki.sierrahelp.com/index.php?title=Custom_Buttons&amp;diff=16015"/>
		<updated>2023-05-31T12:53:58Z</updated>

		<summary type="html">&lt;p&gt;Rob Craig: /* Scripting The Button */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Chapter 7 - Creating Custom Buttons=&lt;br /&gt;
&lt;br /&gt;
By default, the interpreter draws all the windows and controls for the game&amp;#039;s GUI. However, with some creative coding, they can be easily customized. This tutorial will teach you how to create custom buttons with views.&lt;br /&gt;
&lt;br /&gt;
===Load The Game===&lt;br /&gt;
&lt;br /&gt;
First you need to open your game in SCI Studio, loading the Resource Explorer.&lt;br /&gt;
&lt;br /&gt;
===The Button View===&lt;br /&gt;
&lt;br /&gt;
First the buttons will need a view so there&amp;#039;s something to draw. I&amp;#039;ve set up the view so that cels 0-3 are for the button&amp;#039;s edges, and 4-7 are for the left, top, right and bottom borders. It can be easily customized to create your own custom button.&lt;br /&gt;
&lt;br /&gt;
The cels are 8x8 pixels. Though they really would only need to be 4x4, they should be no less than 8x8. If they are too small, it will take too long to draw the buttons.&lt;br /&gt;
&lt;br /&gt;
To save time, [http://sierrahelp.com/Files/SCI/view.900 click here] and download it.&lt;br /&gt;
&lt;br /&gt;
Add the view to the game. I chose to number it view.900, but it can be numbered anything you like.&lt;br /&gt;
&lt;br /&gt;
===Scripting The Button===&lt;br /&gt;
&lt;br /&gt;
In the resource explorer, select &amp;#039;&amp;#039;&amp;#039;Script&amp;#039;&amp;#039;&amp;#039; from the left resource tree. This will bring up the list of scripts in your game on the right. Double click on the &amp;quot;&amp;#039;&amp;#039;&amp;#039;Controls.sc&amp;#039;&amp;#039;&amp;#039;&amp;quot; script. It will load it up in the script editor.&lt;br /&gt;
&lt;br /&gt;
Though customizing a button is generally simple, there are many extra steps which must be taken to give it optimum performance and prevent interference.&lt;br /&gt;
&lt;br /&gt;
{| width=&amp;quot;100%&amp;quot;&lt;br /&gt;
| width=&amp;quot;216&amp;quot; | [[Image:Controls-DButton.png|DButton class]]&lt;br /&gt;
| width=&amp;quot;100%&amp;quot; valign=&amp;quot;top&amp;quot; | First, scroll down controls.sc to the DButton class.&lt;br /&gt;
|-&lt;br /&gt;
| width=&amp;quot;216&amp;quot; | [[Image:Controls-SetSize.png|setSize() method]]&lt;br /&gt;
| width=&amp;quot;100%&amp;quot; valign=&amp;quot;top&amp;quot; | Next, scroll down to the setSize() method.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&lt;br /&gt;
Change:&lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;= nsBottom (+ nsTop rect[rtBOTTOM])&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
to:&lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;= nsBottom (+ nsTop(| (&amp;amp; rect[rtBOTTOM] $FFFC) 7))&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
SCI code for SCI Companion:&lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;(= nsBottom (+ nsTop (| (&amp;amp; [rect rtBOTTOM] $FFFC) 7)))&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and Change: &lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;(= nsBottom (+ nsTop (| (&amp;amp; [rect rtBOTTOM] $FFFC) 7)))&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
to:&lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;= nsRight (+ (| (&amp;amp; rect[rtRIGHT] $FFFC) 7) nsLeft)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
SCI code for SCI Companion:&lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;(= nsRight (+ (| (&amp;amp; [rect rtRIGHT] $FFFC) 7) nsLeft))&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This makes the control always in dimensions divisible by eight (i.e. 8,16,24,32,etc.). This is needed because we are using 8x8 cels.&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Next, we&amp;#039;ll need to add a draw method to the DButton class to override the default one.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&lt;br /&gt;
Add the following code to the DButton class. &lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;  (method (draw)&lt;br /&gt;
    (var x, y, x2, y2, w, h, rect[4])&lt;br /&gt;
    &lt;br /&gt;
    // Calculate the areas&lt;br /&gt;
    = x2 (- nsRight 8)&lt;br /&gt;
    = y2 (- nsBottom 8)&lt;br /&gt;
    = w (- nsRight nsLeft)&lt;br /&gt;
    = h (- nsBottom nsTop)&lt;br /&gt;
    TextSize(@rect text font)&lt;br /&gt;
&lt;br /&gt;
    // Draw the side borders&lt;br /&gt;
    (for(= y(+ nsTop 8)) (&amp;lt; y y2) (= y + y 8)&lt;br /&gt;
      DrawCel(900 0 4 nsLeft y -1)&lt;br /&gt;
      DrawCel(900 0 6 x2   y -1)&lt;br /&gt;
    )&lt;br /&gt;
    // Draw the top and bottom borders&lt;br /&gt;
    (for(= x(+ nsLeft 8)) (&amp;lt; x x2) (= x + x 8)&lt;br /&gt;
      DrawCel(900 0 5 x nsTop -1)&lt;br /&gt;
      DrawCel(900 0 7 x y2   -1)&lt;br /&gt;
    )&lt;br /&gt;
    // Draw the corners&lt;br /&gt;
    DrawCel(900 0 0 nsLeft nsTop -1)&lt;br /&gt;
    DrawCel(900 0 1 x2   nsTop -1)&lt;br /&gt;
    DrawCel(900 0 2 nsLeft y2  -1)&lt;br /&gt;
    DrawCel(900 0 3 x2   y2  -1)&lt;br /&gt;
    // Draw the text&lt;br /&gt;
    Display(text&lt;br /&gt;
      dsCOORD&lt;br /&gt;
        + nsLeft (&amp;gt;&amp;gt; (- w rect[rtRIGHT]) 1)&lt;br /&gt;
        + (+ nsTop (&amp;gt;&amp;gt; (- h rect[rtBOTTOM]) 1) 1)&lt;br /&gt;
      dsCOLOR&lt;br /&gt;
        gWndColor&lt;br /&gt;
      dsBACKGROUND&lt;br /&gt;
        clTRANSPARENT&lt;br /&gt;
      dsFONT&lt;br /&gt;
        font&lt;br /&gt;
      dsWIDTH&lt;br /&gt;
        rect[rtRIGHT]&lt;br /&gt;
    )&lt;br /&gt;
  )&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
SCI code for SCI Companion. &lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;  (method (draw &amp;amp;tmp x y x2 y2 w h [rect 4])&lt;br /&gt;
		; Calculate the areas&lt;br /&gt;
		(= x2 (- nsRight 8))&lt;br /&gt;
		(= y2 (- nsBottom 8))&lt;br /&gt;
		(= w (- nsRight nsLeft))&lt;br /&gt;
		(= h (- nsBottom nsTop))&lt;br /&gt;
		(TextSize @rect text font)&lt;br /&gt;
		; Draw the side borders&lt;br /&gt;
		(for ( (= y (+ nsTop 8))) (&amp;lt; y y2)  ( (= y (+ y 8))) (DrawCel 902 0 4 nsLeft y -1) (DrawCel 902 0 6 x2 y -1))&lt;br /&gt;
		; Draw the top and bottom borders&lt;br /&gt;
		(for ( (= x (+ nsLeft 8))) (&amp;lt; x x2)  ( (= x (+ x 8))) (DrawCel 902 0 5 x nsTop -1) (DrawCel 902 0 7 x y2 -1))&lt;br /&gt;
		; Draw the corners&lt;br /&gt;
		(DrawCel 902 0 0 nsLeft nsTop -1)&lt;br /&gt;
		(DrawCel 902 0 1 x2 nsTop -1)&lt;br /&gt;
		(DrawCel 902 0 2 nsLeft y2 -1)&lt;br /&gt;
		(DrawCel 902 0 3 x2 y2 -1)&lt;br /&gt;
		; Draw the text&lt;br /&gt;
		(Display&lt;br /&gt;
			text&lt;br /&gt;
			dsCOORD&lt;br /&gt;
				(+ nsLeft (&amp;gt;&amp;gt; (- w [rect rtRIGHT]) 1))&lt;br /&gt;
				(+ (+ nsTop (&amp;gt;&amp;gt; (- h [rect rtBOTTOM]) 1)) 1)&lt;br /&gt;
			dsCOLOR gWndColor&lt;br /&gt;
			dsBACKGROUND clTRANSPARENT&lt;br /&gt;
			dsFONT font&lt;br /&gt;
			dsWIDTH [rect rtRIGHT]&lt;br /&gt;
		)&lt;br /&gt;
	)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Needless to say, that code draws the button. It draws the border and edges, then centers and draws the text. It doesn&amp;#039;t bother drawing the inside of the button and just leaves it transparent for speed. It would be a lot slower if it filled in the button with cels.&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| width=&amp;quot;100%&amp;quot;&lt;br /&gt;
| width=&amp;quot;113&amp;quot; | [[Image:Script-Main.png|Main Script]]&lt;br /&gt;
| width=&amp;quot;100%&amp;quot; | Chances are, you&amp;#039;ll want to customize the window colors to go with the button, right? If that&amp;#039;s the case, open up the &amp;quot;&amp;#039;&amp;#039;&amp;#039;Main.sc&amp;#039;&amp;#039;&amp;#039;&amp;quot; script.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
{| width=&amp;quot;100%&amp;quot;&lt;br /&gt;
| width=&amp;quot;216&amp;quot; | [[Image:Script-GameInstance.png|Game Instance]]&lt;br /&gt;
| width=&amp;quot;100%&amp;quot; | Next, scroll down main.sc to the Game instance.&lt;br /&gt;
&lt;br /&gt;
At the very top of the init() method, you will see the window color initialization.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* The gWndColor is the color for the text and borders of of the non-custom controls.&lt;br /&gt;
* The gWndBack is the color of the actual window.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&lt;br /&gt;
To go with the default custom button, we&amp;#039;ll make the window silver. Change: &lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;= gWndBack clWHITE&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
To:&lt;br /&gt;
To go with the default custom button, we&amp;#039;ll make the window silver. Change: &lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;= gWndBack clSILVER&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p align=&amp;quot;center&amp;quot;&amp;gt;Run the game all you&amp;#039;ll see your brand new custom buttons!&amp;lt;br /&amp;gt;[[Image:Controls-QuitDialog.png|Quit Button]]&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
That sums it up! Be sure to check out how to make custom windows and gauges!&lt;br /&gt;
&lt;br /&gt;
&amp;amp;nbsp;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;float: left&amp;quot;&amp;gt;[[Checking a Door&amp;#039;s State|&amp;amp;lt; Previous: Chapter 6 - Checking a Door&amp;#039;s State]]&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;span style=&amp;quot;float: right&amp;quot;&amp;gt;[[Custom Windows|Chapter 8 - Creating Custom Windows &amp;amp;gt;]]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;amp;nbsp;&lt;br /&gt;
&lt;br /&gt;
[[Category:Controls]]&lt;br /&gt;
[[Category:Tutorials]]&lt;/div&gt;</summary>
		<author><name>Rob Craig</name></author>
	</entry>
	<entry>
		<id>http://sciwiki.sierrahelp.com/index.php?title=Custom_Buttons&amp;diff=16014</id>
		<title>Custom Buttons</title>
		<link rel="alternate" type="text/html" href="http://sciwiki.sierrahelp.com/index.php?title=Custom_Buttons&amp;diff=16014"/>
		<updated>2023-05-31T12:52:37Z</updated>

		<summary type="html">&lt;p&gt;Rob Craig: /* Scripting The Button */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Chapter 7 - Creating Custom Buttons=&lt;br /&gt;
&lt;br /&gt;
By default, the interpreter draws all the windows and controls for the game&amp;#039;s GUI. However, with some creative coding, they can be easily customized. This tutorial will teach you how to create custom buttons with views.&lt;br /&gt;
&lt;br /&gt;
===Load The Game===&lt;br /&gt;
&lt;br /&gt;
First you need to open your game in SCI Studio, loading the Resource Explorer.&lt;br /&gt;
&lt;br /&gt;
===The Button View===&lt;br /&gt;
&lt;br /&gt;
First the buttons will need a view so there&amp;#039;s something to draw. I&amp;#039;ve set up the view so that cels 0-3 are for the button&amp;#039;s edges, and 4-7 are for the left, top, right and bottom borders. It can be easily customized to create your own custom button.&lt;br /&gt;
&lt;br /&gt;
The cels are 8x8 pixels. Though they really would only need to be 4x4, they should be no less than 8x8. If they are too small, it will take too long to draw the buttons.&lt;br /&gt;
&lt;br /&gt;
To save time, [http://sierrahelp.com/Files/SCI/view.900 click here] and download it.&lt;br /&gt;
&lt;br /&gt;
Add the view to the game. I chose to number it view.900, but it can be numbered anything you like.&lt;br /&gt;
&lt;br /&gt;
===Scripting The Button===&lt;br /&gt;
&lt;br /&gt;
In the resource explorer, select &amp;#039;&amp;#039;&amp;#039;Script&amp;#039;&amp;#039;&amp;#039; from the left resource tree. This will bring up the list of scripts in your game on the right. Double click on the &amp;quot;&amp;#039;&amp;#039;&amp;#039;Controls.sc&amp;#039;&amp;#039;&amp;#039;&amp;quot; script. It will load it up in the script editor.&lt;br /&gt;
&lt;br /&gt;
Though customizing a button is generally simple, there are many extra steps which must be taken to give it optimum performance and prevent interference.&lt;br /&gt;
&lt;br /&gt;
{| width=&amp;quot;100%&amp;quot;&lt;br /&gt;
| width=&amp;quot;216&amp;quot; | [[Image:Controls-DButton.png|DButton class]]&lt;br /&gt;
| width=&amp;quot;100%&amp;quot; valign=&amp;quot;top&amp;quot; | First, scroll down controls.sc to the DButton class.&lt;br /&gt;
|-&lt;br /&gt;
| width=&amp;quot;216&amp;quot; | [[Image:Controls-SetSize.png|setSize() method]]&lt;br /&gt;
| width=&amp;quot;100%&amp;quot; valign=&amp;quot;top&amp;quot; | Next, scroll down to the setSize() method.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&lt;br /&gt;
Change:&lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;= nsBottom (+ nsTop rect[rtBOTTOM])&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
to:&lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;= nsBottom (+ nsTop(| (&amp;amp; rect[rtBOTTOM] $FFFC) 7))&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
SCI code for SCI Companion:&lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;(= nsBottom (+ nsTop (| (&amp;amp; [rect rtBOTTOM] $FFFC) 7)))&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and Change: &lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;(= nsBottom (+ nsTop (| (&amp;amp; [rect rtBOTTOM] $FFFC) 7)))&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
to:&lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;= nsRight (+ (| (&amp;amp; rect[rtRIGHT] $FFFC) 7) nsLeft)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
SCI code for SCI Companion:&lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;(= nsRight (+ (| (&amp;amp; [rect rtRIGHT] $FFFC) 7) nsLeft))&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This makes the control always in dimensions divisible by eight (i.e. 8,16,24,32,etc.). This is needed because we are using 8x8 cels.&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Next, we&amp;#039;ll need to add a draw method to the DButton class to override the default one.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&lt;br /&gt;
Add the following code to the DButton class. &lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;  (method (draw)&lt;br /&gt;
    (var x, y, x2, y2, w, h, rect[4])&lt;br /&gt;
    &lt;br /&gt;
    // Calculate the areas&lt;br /&gt;
    = x2 (- nsRight 8)&lt;br /&gt;
    = y2 (- nsBottom 8)&lt;br /&gt;
    = w (- nsRight nsLeft)&lt;br /&gt;
    = h (- nsBottom nsTop)&lt;br /&gt;
    TextSize(@rect text font)&lt;br /&gt;
&lt;br /&gt;
    // Draw the side borders&lt;br /&gt;
    (for(= y(+ nsTop 8)) (&amp;lt; y y2) (= y + y 8)&lt;br /&gt;
      DrawCel(900 0 4 nsLeft y -1)&lt;br /&gt;
      DrawCel(900 0 6 x2   y -1)&lt;br /&gt;
    )&lt;br /&gt;
    // Draw the top and bottom borders&lt;br /&gt;
    (for(= x(+ nsLeft 8)) (&amp;lt; x x2) (= x + x 8)&lt;br /&gt;
      DrawCel(900 0 5 x nsTop -1)&lt;br /&gt;
      DrawCel(900 0 7 x y2   -1)&lt;br /&gt;
    )&lt;br /&gt;
    // Draw the corners&lt;br /&gt;
    DrawCel(900 0 0 nsLeft nsTop -1)&lt;br /&gt;
    DrawCel(900 0 1 x2   nsTop -1)&lt;br /&gt;
    DrawCel(900 0 2 nsLeft y2  -1)&lt;br /&gt;
    DrawCel(900 0 3 x2   y2  -1)&lt;br /&gt;
    // Draw the text&lt;br /&gt;
    Display(text&lt;br /&gt;
      dsCOORD&lt;br /&gt;
        + nsLeft (&amp;gt;&amp;gt; (- w rect[rtRIGHT]) 1)&lt;br /&gt;
        + (+ nsTop (&amp;gt;&amp;gt; (- h rect[rtBOTTOM]) 1) 1)&lt;br /&gt;
      dsCOLOR&lt;br /&gt;
        gWndColor&lt;br /&gt;
      dsBACKGROUND&lt;br /&gt;
        clTRANSPARENT&lt;br /&gt;
      dsFONT&lt;br /&gt;
        font&lt;br /&gt;
      dsWIDTH&lt;br /&gt;
        rect[rtRIGHT]&lt;br /&gt;
    )&lt;br /&gt;
  )&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Needless to say, that code draws the button. It draws the border and edges, then centers and draws the text. It doesn&amp;#039;t bother drawing the inside of the button and just leaves it transparent for speed. It would be a lot slower if it filled in the button with cels.&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| width=&amp;quot;100%&amp;quot;&lt;br /&gt;
| width=&amp;quot;113&amp;quot; | [[Image:Script-Main.png|Main Script]]&lt;br /&gt;
| width=&amp;quot;100%&amp;quot; | Chances are, you&amp;#039;ll want to customize the window colors to go with the button, right? If that&amp;#039;s the case, open up the &amp;quot;&amp;#039;&amp;#039;&amp;#039;Main.sc&amp;#039;&amp;#039;&amp;#039;&amp;quot; script.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
{| width=&amp;quot;100%&amp;quot;&lt;br /&gt;
| width=&amp;quot;216&amp;quot; | [[Image:Script-GameInstance.png|Game Instance]]&lt;br /&gt;
| width=&amp;quot;100%&amp;quot; | Next, scroll down main.sc to the Game instance.&lt;br /&gt;
&lt;br /&gt;
At the very top of the init() method, you will see the window color initialization.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* The gWndColor is the color for the text and borders of of the non-custom controls.&lt;br /&gt;
* The gWndBack is the color of the actual window.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&lt;br /&gt;
To go with the default custom button, we&amp;#039;ll make the window silver. Change: &lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;= gWndBack clWHITE&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
To:&lt;br /&gt;
To go with the default custom button, we&amp;#039;ll make the window silver. Change: &lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;= gWndBack clSILVER&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p align=&amp;quot;center&amp;quot;&amp;gt;Run the game all you&amp;#039;ll see your brand new custom buttons!&amp;lt;br /&amp;gt;[[Image:Controls-QuitDialog.png|Quit Button]]&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
That sums it up! Be sure to check out how to make custom windows and gauges!&lt;br /&gt;
&lt;br /&gt;
&amp;amp;nbsp;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;float: left&amp;quot;&amp;gt;[[Checking a Door&amp;#039;s State|&amp;amp;lt; Previous: Chapter 6 - Checking a Door&amp;#039;s State]]&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;span style=&amp;quot;float: right&amp;quot;&amp;gt;[[Custom Windows|Chapter 8 - Creating Custom Windows &amp;amp;gt;]]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;amp;nbsp;&lt;br /&gt;
&lt;br /&gt;
[[Category:Controls]]&lt;br /&gt;
[[Category:Tutorials]]&lt;/div&gt;</summary>
		<author><name>Rob Craig</name></author>
	</entry>
	<entry>
		<id>http://sciwiki.sierrahelp.com/index.php?title=Custom_Buttons&amp;diff=16013</id>
		<title>Custom Buttons</title>
		<link rel="alternate" type="text/html" href="http://sciwiki.sierrahelp.com/index.php?title=Custom_Buttons&amp;diff=16013"/>
		<updated>2023-05-31T12:49:42Z</updated>

		<summary type="html">&lt;p&gt;Rob Craig: /* Scripting The Button */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Chapter 7 - Creating Custom Buttons=&lt;br /&gt;
&lt;br /&gt;
By default, the interpreter draws all the windows and controls for the game&amp;#039;s GUI. However, with some creative coding, they can be easily customized. This tutorial will teach you how to create custom buttons with views.&lt;br /&gt;
&lt;br /&gt;
===Load The Game===&lt;br /&gt;
&lt;br /&gt;
First you need to open your game in SCI Studio, loading the Resource Explorer.&lt;br /&gt;
&lt;br /&gt;
===The Button View===&lt;br /&gt;
&lt;br /&gt;
First the buttons will need a view so there&amp;#039;s something to draw. I&amp;#039;ve set up the view so that cels 0-3 are for the button&amp;#039;s edges, and 4-7 are for the left, top, right and bottom borders. It can be easily customized to create your own custom button.&lt;br /&gt;
&lt;br /&gt;
The cels are 8x8 pixels. Though they really would only need to be 4x4, they should be no less than 8x8. If they are too small, it will take too long to draw the buttons.&lt;br /&gt;
&lt;br /&gt;
To save time, [http://sierrahelp.com/Files/SCI/view.900 click here] and download it.&lt;br /&gt;
&lt;br /&gt;
Add the view to the game. I chose to number it view.900, but it can be numbered anything you like.&lt;br /&gt;
&lt;br /&gt;
===Scripting The Button===&lt;br /&gt;
&lt;br /&gt;
In the resource explorer, select &amp;#039;&amp;#039;&amp;#039;Script&amp;#039;&amp;#039;&amp;#039; from the left resource tree. This will bring up the list of scripts in your game on the right. Double click on the &amp;quot;&amp;#039;&amp;#039;&amp;#039;Controls.sc&amp;#039;&amp;#039;&amp;#039;&amp;quot; script. It will load it up in the script editor.&lt;br /&gt;
&lt;br /&gt;
Though customizing a button is generally simple, there are many extra steps which must be taken to give it optimum performance and prevent interference.&lt;br /&gt;
&lt;br /&gt;
{| width=&amp;quot;100%&amp;quot;&lt;br /&gt;
| width=&amp;quot;216&amp;quot; | [[Image:Controls-DButton.png|DButton class]]&lt;br /&gt;
| width=&amp;quot;100%&amp;quot; valign=&amp;quot;top&amp;quot; | First, scroll down controls.sc to the DButton class.&lt;br /&gt;
|-&lt;br /&gt;
| width=&amp;quot;216&amp;quot; | [[Image:Controls-SetSize.png|setSize() method]]&lt;br /&gt;
| width=&amp;quot;100%&amp;quot; valign=&amp;quot;top&amp;quot; | Next, scroll down to the setSize() method.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&lt;br /&gt;
Change:&lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;= nsBottom (+ nsTop rect[rtBOTTOM])&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
to:&lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;= nsBottom (+ nsTop(| (&amp;amp; rect[rtBOTTOM] $FFFC) 7))&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;= nsBottom (+ nsTop(| (&amp;amp; rect[rtBOTTOM] $FFFC) 7))&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and Change: &lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;(= nsBottom (+ nsTop (| (&amp;amp; [rect rtBOTTOM] $FFFC) 7)))&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
to:&lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;= nsRight (+ (| (&amp;amp; rect[rtRIGHT] $FFFC) 7) nsLeft)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This makes the control always in dimensions divisible by eight (i.e. 8,16,24,32,etc.). This is needed because we are using 8x8 cels.&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Next, we&amp;#039;ll need to add a draw method to the DButton class to override the default one.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&lt;br /&gt;
Add the following code to the DButton class. &lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;  (method (draw)&lt;br /&gt;
    (var x, y, x2, y2, w, h, rect[4])&lt;br /&gt;
    &lt;br /&gt;
    // Calculate the areas&lt;br /&gt;
    = x2 (- nsRight 8)&lt;br /&gt;
    = y2 (- nsBottom 8)&lt;br /&gt;
    = w (- nsRight nsLeft)&lt;br /&gt;
    = h (- nsBottom nsTop)&lt;br /&gt;
    TextSize(@rect text font)&lt;br /&gt;
&lt;br /&gt;
    // Draw the side borders&lt;br /&gt;
    (for(= y(+ nsTop 8)) (&amp;lt; y y2) (= y + y 8)&lt;br /&gt;
      DrawCel(900 0 4 nsLeft y -1)&lt;br /&gt;
      DrawCel(900 0 6 x2   y -1)&lt;br /&gt;
    )&lt;br /&gt;
    // Draw the top and bottom borders&lt;br /&gt;
    (for(= x(+ nsLeft 8)) (&amp;lt; x x2) (= x + x 8)&lt;br /&gt;
      DrawCel(900 0 5 x nsTop -1)&lt;br /&gt;
      DrawCel(900 0 7 x y2   -1)&lt;br /&gt;
    )&lt;br /&gt;
    // Draw the corners&lt;br /&gt;
    DrawCel(900 0 0 nsLeft nsTop -1)&lt;br /&gt;
    DrawCel(900 0 1 x2   nsTop -1)&lt;br /&gt;
    DrawCel(900 0 2 nsLeft y2  -1)&lt;br /&gt;
    DrawCel(900 0 3 x2   y2  -1)&lt;br /&gt;
    // Draw the text&lt;br /&gt;
    Display(text&lt;br /&gt;
      dsCOORD&lt;br /&gt;
        + nsLeft (&amp;gt;&amp;gt; (- w rect[rtRIGHT]) 1)&lt;br /&gt;
        + (+ nsTop (&amp;gt;&amp;gt; (- h rect[rtBOTTOM]) 1) 1)&lt;br /&gt;
      dsCOLOR&lt;br /&gt;
        gWndColor&lt;br /&gt;
      dsBACKGROUND&lt;br /&gt;
        clTRANSPARENT&lt;br /&gt;
      dsFONT&lt;br /&gt;
        font&lt;br /&gt;
      dsWIDTH&lt;br /&gt;
        rect[rtRIGHT]&lt;br /&gt;
    )&lt;br /&gt;
  )&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Needless to say, that code draws the button. It draws the border and edges, then centers and draws the text. It doesn&amp;#039;t bother drawing the inside of the button and just leaves it transparent for speed. It would be a lot slower if it filled in the button with cels.&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| width=&amp;quot;100%&amp;quot;&lt;br /&gt;
| width=&amp;quot;113&amp;quot; | [[Image:Script-Main.png|Main Script]]&lt;br /&gt;
| width=&amp;quot;100%&amp;quot; | Chances are, you&amp;#039;ll want to customize the window colors to go with the button, right? If that&amp;#039;s the case, open up the &amp;quot;&amp;#039;&amp;#039;&amp;#039;Main.sc&amp;#039;&amp;#039;&amp;#039;&amp;quot; script.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
{| width=&amp;quot;100%&amp;quot;&lt;br /&gt;
| width=&amp;quot;216&amp;quot; | [[Image:Script-GameInstance.png|Game Instance]]&lt;br /&gt;
| width=&amp;quot;100%&amp;quot; | Next, scroll down main.sc to the Game instance.&lt;br /&gt;
&lt;br /&gt;
At the very top of the init() method, you will see the window color initialization.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* The gWndColor is the color for the text and borders of of the non-custom controls.&lt;br /&gt;
* The gWndBack is the color of the actual window.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&lt;br /&gt;
To go with the default custom button, we&amp;#039;ll make the window silver. Change: &lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;= gWndBack clWHITE&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
To:&lt;br /&gt;
To go with the default custom button, we&amp;#039;ll make the window silver. Change: &lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;= gWndBack clSILVER&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p align=&amp;quot;center&amp;quot;&amp;gt;Run the game all you&amp;#039;ll see your brand new custom buttons!&amp;lt;br /&amp;gt;[[Image:Controls-QuitDialog.png|Quit Button]]&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
That sums it up! Be sure to check out how to make custom windows and gauges!&lt;br /&gt;
&lt;br /&gt;
&amp;amp;nbsp;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;float: left&amp;quot;&amp;gt;[[Checking a Door&amp;#039;s State|&amp;amp;lt; Previous: Chapter 6 - Checking a Door&amp;#039;s State]]&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;span style=&amp;quot;float: right&amp;quot;&amp;gt;[[Custom Windows|Chapter 8 - Creating Custom Windows &amp;amp;gt;]]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;amp;nbsp;&lt;br /&gt;
&lt;br /&gt;
[[Category:Controls]]&lt;br /&gt;
[[Category:Tutorials]]&lt;/div&gt;</summary>
		<author><name>Rob Craig</name></author>
	</entry>
	<entry>
		<id>http://sciwiki.sierrahelp.com/index.php?title=WordFail,_syntaxFail_and_pragmaFail&amp;diff=16012</id>
		<title>WordFail, syntaxFail and pragmaFail</title>
		<link rel="alternate" type="text/html" href="http://sciwiki.sierrahelp.com/index.php?title=WordFail,_syntaxFail_and_pragmaFail&amp;diff=16012"/>
		<updated>2023-05-31T12:46:12Z</updated>

		<summary type="html">&lt;p&gt;Rob Craig: /* Adding Response Handlers */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Chapter 2 - Oh, yeah? Well, &amp;quot;%s&amp;quot; this!=&lt;br /&gt;
&lt;br /&gt;
In order to make your game fun and enjoyable, you&amp;#039;ll want it to be more intelligent to the player. By default, if the player enters a word not in the vocabulary, or a sentence that doesn&amp;#039;t make sense, it will just display a message like &amp;quot;I don&amp;#039;t understand &amp;quot;that word&amp;quot;.&amp;quot; or &amp;quot;That sentence doesn&amp;#039;t make sense.&amp;quot;. This can be easily changed.&lt;br /&gt;
&lt;br /&gt;
In Sierra&amp;#039;s games, you&amp;#039;ll notice that it displays different responses when you enter invalid phrases. If you enter a word not in the game&amp;#039;s vocabulary, it will display &amp;quot;Oh, yeah? Well, &amp;quot;the word&amp;quot; this!&amp;quot; or &amp;quot;You don&amp;#039;t need to type the word &amp;quot;the word&amp;quot; to complete this game!&amp;quot;, or &amp;quot;Don&amp;#039;t you ever say the word &amp;quot;the word&amp;quot; again!&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
Implementing an intelligent response system is very easy. There are three types of phrase catchers: &amp;#039;&amp;#039;&amp;#039;wordFail&amp;#039;&amp;#039;&amp;#039;, &amp;#039;&amp;#039;&amp;#039;syntaxFail&amp;#039;&amp;#039;&amp;#039; and &amp;#039;&amp;#039;&amp;#039;pragmaFail&amp;#039;&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;wordFail&amp;#039;&amp;#039;&amp;#039;, is executed when the player enters a word in the phrase that is not in the game&amp;#039;s vocabulary.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;syntaxFail&amp;#039;&amp;#039;&amp;#039; is executed when the player enters an improper sentence.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;pragmaFail&amp;#039;&amp;#039;&amp;#039; is executed when the player enters an valid sentence that is not handled by any said statements.&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Adding Response Handlers ==&lt;br /&gt;
&lt;br /&gt;
The toolbar gives quick access to opening, closing and running games, the resource editors, and the help file. To add the response handlers, you simply need to add the methods by name to your game&amp;#039;s instance.&lt;br /&gt;
&lt;br /&gt;
[[Image:Script-Main.png|Main Script]] First, open up your game&amp;#039;s &amp;quot;main.sc&amp;quot; script.&lt;br /&gt;
&lt;br /&gt;
{| width=&amp;quot;100%&amp;quot;&lt;br /&gt;
| width=&amp;quot;274&amp;quot; | [[Image:Script-GameInstance.png|New Game Dialog]]&lt;br /&gt;
| valign=&amp;quot;top&amp;quot; | Scroll down to the game&amp;#039;s instance.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Scroll to the end of it and add the methods to handle the responses. You can add any or all in any order.&lt;br /&gt;
&lt;br /&gt;
You&amp;#039;ll naturally want multiple responses, and want them randomly said. To do this, we&amp;#039;ll use a combination of a switch statement and Rand() kernel call.&lt;br /&gt;
&lt;br /&gt;
We&amp;#039;ll start with the &amp;#039;&amp;#039;&amp;#039;wordFail&amp;#039;&amp;#039;&amp;#039; method. Here&amp;#039;s an example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;(method (wordFail theString)&lt;br /&gt;
  (switch(Random(0 4))&lt;br /&gt;
    (case 0&lt;br /&gt;
      FormatPrint(&amp;quot;Oh, yeah? Well, \&amp;quot;%s\&amp;quot; this!&amp;quot; theString)&lt;br /&gt;
    )&lt;br /&gt;
    (case 1&lt;br /&gt;
      FormatPrint(&amp;quot;You may know the word \&amp;quot;%s\&amp;quot; but it&amp;#039;s beyond &amp;#039;s vocabulary!&amp;quot; theString)&lt;br /&gt;
    )&lt;br /&gt;
    (case 2&lt;br /&gt;
      FormatPrint(&amp;quot;Oh, yeah? Well, I&amp;#039;ve got your \&amp;quot;%s\&amp;quot; right here!&amp;quot; theString)&lt;br /&gt;
    )&lt;br /&gt;
    (case 3&lt;br /&gt;
      FormatPrint(&amp;quot;You don&amp;#039;t need to type the word \&amp;quot;%s\&amp;quot; to complete this game!&amp;quot; theString)&lt;br /&gt;
    )&lt;br /&gt;
    (default&lt;br /&gt;
      FormatPrint(&amp;quot;Don&amp;#039;t you ever say the word \&amp;quot;%s\&amp;quot; again!&amp;quot; theString)&lt;br /&gt;
    )&lt;br /&gt;
  )&lt;br /&gt;
)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
SCI code for wordFail compatible with SCI Companion.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;(method (wordFail theString)&lt;br /&gt;
  (method (wordFail theString)&lt;br /&gt;
  		(switch (Random 0 4)&lt;br /&gt;
    		(0&lt;br /&gt;
      		(FormatPrint {Oh, yeah? Well, %s this!} theString)&lt;br /&gt;
   			 )&lt;br /&gt;
    		(1&lt;br /&gt;
      		(FormatPrint {You may know the word %s but it&amp;#039;s beyond the game&amp;#039;s vocabulary!} theString)&lt;br /&gt;
    		)&lt;br /&gt;
    		(2&lt;br /&gt;
      		(FormatPrint {Oh, yeah? Well, I&amp;#039;ve got your %s right here!} theString)&lt;br /&gt;
    		)&lt;br /&gt;
    		(3&lt;br /&gt;
      		(FormatPrint {You don&amp;#039;t need to type the word %s to complete this game!} theString)&lt;br /&gt;
    		)&lt;br /&gt;
    		(else&lt;br /&gt;
      		(FormatPrint {Don&amp;#039;t you ever say the word %s again!} theString)&lt;br /&gt;
			)&lt;br /&gt;
		)&lt;br /&gt;
	)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This generates a random number from 0 to 4 (five possible numbers), and displays a response depending on which is generated.&lt;br /&gt;
&lt;br /&gt;
The syntaxFail and pragmaFail operate identical to wordFail, but I&amp;#039;ll give examples of them as well:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
(method (syntaxFail theString)&lt;br /&gt;
  (switch(Random(0 2))&lt;br /&gt;
    (case 0&lt;br /&gt;
      Print(&amp;quot;That doesn&amp;#039;t appear to be a proper sentence.&amp;quot;)&lt;br /&gt;
    )&lt;br /&gt;
    (case 1&lt;br /&gt;
      Print(&amp;quot;What in the heck are you talking about?&amp;quot;)&lt;br /&gt;
    )&lt;br /&gt;
    (default&lt;br /&gt;
      Print(&amp;quot;That&amp;#039;s probably something you could do, but this game won&amp;#039;t!&amp;quot;)&lt;br /&gt;
    )&lt;br /&gt;
  )&lt;br /&gt;
)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&amp;amp;nbsp;&lt;br /&gt;
SCI code for syntaxFail compatible with SCI Companion.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;&lt;br /&gt;
	(method (syntaxFail theString)&lt;br /&gt;
  		(switch (Random 0 2)&lt;br /&gt;
    		(0&lt;br /&gt;
     		(Print {That doesn&amp;#039;t appear to be a proper sentence.})&lt;br /&gt;
    		)&lt;br /&gt;
    		(1&lt;br /&gt;
      		(Print {What in the hell are you talking about?})&lt;br /&gt;
    		)&lt;br /&gt;
    		(else&lt;br /&gt;
     		(Print {That&amp;#039;s probably something you could do, but this game won&amp;#039;t!})&lt;br /&gt;
    		)&lt;br /&gt;
  		)&lt;br /&gt;
	)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;(method (pragmaFail theString)&lt;br /&gt;
  (switch(Random(0 2))&lt;br /&gt;
    (case 0&lt;br /&gt;
      Print(&amp;quot;The heck you say?&amp;quot;)&lt;br /&gt;
    )&lt;br /&gt;
    (case 1&lt;br /&gt;
      Print(&amp;quot;You&amp;#039;re too smart for this game!&amp;quot;)&lt;br /&gt;
    )&lt;br /&gt;
    (default&lt;br /&gt;
      Print(&amp;quot;Congratulations! You have dumbfounded this game!&amp;quot;)&lt;br /&gt;
    )&lt;br /&gt;
  )&lt;br /&gt;
)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
SCI code for pragmaFail compatible with SCI Companion.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;(method (pragmaFail theString)&lt;br /&gt;
  (method (pragmaFail theString)&lt;br /&gt;
  		(switch (Random 0 2)&lt;br /&gt;
    		(0&lt;br /&gt;
      		(Print {The hell you say?})&lt;br /&gt;
    		)&lt;br /&gt;
    		(1&lt;br /&gt;
      		(Print {You&amp;#039;re too smart for this game!})&lt;br /&gt;
    		)&lt;br /&gt;
    		(else&lt;br /&gt;
      		(Print {Congratulations! You have dumbfounded this game!})&lt;br /&gt;
    		)&lt;br /&gt;
  		)&lt;br /&gt;
	)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;amp;nbsp;&lt;br /&gt;
&lt;br /&gt;
The methods all take the string as a parameter. Whether you choose to use it or not is up to you.&lt;br /&gt;
&lt;br /&gt;
You can have as many or as few responses as you like. Just change the random amount and cases.&lt;br /&gt;
&lt;br /&gt;
That sums up global response handlers! Now your game can have attitude!&lt;br /&gt;
&lt;br /&gt;
&amp;amp;nbsp;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;float: left&amp;quot;&amp;gt;[[Global Said() Statements|&amp;amp;lt; Previous: Chapter 1 - Global Said() Statements]]&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;span style=&amp;quot;float: right&amp;quot;&amp;gt;[[Actor Paths|Next: Chapter 3 - Making Actors Move Along Paths &amp;amp;gt;]]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;amp;nbsp;&lt;br /&gt;
&lt;br /&gt;
[[Category:Said() Strings]]&lt;br /&gt;
[[Category:The SCI Parser]]&lt;br /&gt;
[[Category:Tutorials]]&lt;/div&gt;</summary>
		<author><name>Rob Craig</name></author>
	</entry>
	<entry>
		<id>http://sciwiki.sierrahelp.com/index.php?title=WordFail,_syntaxFail_and_pragmaFail&amp;diff=16011</id>
		<title>WordFail, syntaxFail and pragmaFail</title>
		<link rel="alternate" type="text/html" href="http://sciwiki.sierrahelp.com/index.php?title=WordFail,_syntaxFail_and_pragmaFail&amp;diff=16011"/>
		<updated>2023-05-31T12:45:09Z</updated>

		<summary type="html">&lt;p&gt;Rob Craig: /* Adding Response Handlers */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Chapter 2 - Oh, yeah? Well, &amp;quot;%s&amp;quot; this!=&lt;br /&gt;
&lt;br /&gt;
In order to make your game fun and enjoyable, you&amp;#039;ll want it to be more intelligent to the player. By default, if the player enters a word not in the vocabulary, or a sentence that doesn&amp;#039;t make sense, it will just display a message like &amp;quot;I don&amp;#039;t understand &amp;quot;that word&amp;quot;.&amp;quot; or &amp;quot;That sentence doesn&amp;#039;t make sense.&amp;quot;. This can be easily changed.&lt;br /&gt;
&lt;br /&gt;
In Sierra&amp;#039;s games, you&amp;#039;ll notice that it displays different responses when you enter invalid phrases. If you enter a word not in the game&amp;#039;s vocabulary, it will display &amp;quot;Oh, yeah? Well, &amp;quot;the word&amp;quot; this!&amp;quot; or &amp;quot;You don&amp;#039;t need to type the word &amp;quot;the word&amp;quot; to complete this game!&amp;quot;, or &amp;quot;Don&amp;#039;t you ever say the word &amp;quot;the word&amp;quot; again!&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
Implementing an intelligent response system is very easy. There are three types of phrase catchers: &amp;#039;&amp;#039;&amp;#039;wordFail&amp;#039;&amp;#039;&amp;#039;, &amp;#039;&amp;#039;&amp;#039;syntaxFail&amp;#039;&amp;#039;&amp;#039; and &amp;#039;&amp;#039;&amp;#039;pragmaFail&amp;#039;&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;wordFail&amp;#039;&amp;#039;&amp;#039;, is executed when the player enters a word in the phrase that is not in the game&amp;#039;s vocabulary.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;syntaxFail&amp;#039;&amp;#039;&amp;#039; is executed when the player enters an improper sentence.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;pragmaFail&amp;#039;&amp;#039;&amp;#039; is executed when the player enters an valid sentence that is not handled by any said statements.&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Adding Response Handlers ==&lt;br /&gt;
&lt;br /&gt;
The toolbar gives quick access to opening, closing and running games, the resource editors, and the help file. To add the response handlers, you simply need to add the methods by name to your game&amp;#039;s instance.&lt;br /&gt;
&lt;br /&gt;
[[Image:Script-Main.png|Main Script]] First, open up your game&amp;#039;s &amp;quot;main.sc&amp;quot; script.&lt;br /&gt;
&lt;br /&gt;
{| width=&amp;quot;100%&amp;quot;&lt;br /&gt;
| width=&amp;quot;274&amp;quot; | [[Image:Script-GameInstance.png|New Game Dialog]]&lt;br /&gt;
| valign=&amp;quot;top&amp;quot; | Scroll down to the game&amp;#039;s instance.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Scroll to the end of it and add the methods to handle the responses. You can add any or all in any order.&lt;br /&gt;
&lt;br /&gt;
You&amp;#039;ll naturally want multiple responses, and want them randomly said. To do this, we&amp;#039;ll use a combination of a switch statement and Rand() kernel call.&lt;br /&gt;
&lt;br /&gt;
We&amp;#039;ll start with the &amp;#039;&amp;#039;&amp;#039;wordFail&amp;#039;&amp;#039;&amp;#039; method. Here&amp;#039;s an example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;(method (wordFail theString)&lt;br /&gt;
  (switch(Random(0 4))&lt;br /&gt;
    (case 0&lt;br /&gt;
      FormatPrint(&amp;quot;Oh, yeah? Well, \&amp;quot;%s\&amp;quot; this!&amp;quot; theString)&lt;br /&gt;
    )&lt;br /&gt;
    (case 1&lt;br /&gt;
      FormatPrint(&amp;quot;You may know the word \&amp;quot;%s\&amp;quot; but it&amp;#039;s beyond &amp;#039;s vocabulary!&amp;quot; theString)&lt;br /&gt;
    )&lt;br /&gt;
    (case 2&lt;br /&gt;
      FormatPrint(&amp;quot;Oh, yeah? Well, I&amp;#039;ve got your \&amp;quot;%s\&amp;quot; right here!&amp;quot; theString)&lt;br /&gt;
    )&lt;br /&gt;
    (case 3&lt;br /&gt;
      FormatPrint(&amp;quot;You don&amp;#039;t need to type the word \&amp;quot;%s\&amp;quot; to complete this game!&amp;quot; theString)&lt;br /&gt;
    )&lt;br /&gt;
    (default&lt;br /&gt;
      FormatPrint(&amp;quot;Don&amp;#039;t you ever say the word \&amp;quot;%s\&amp;quot; again!&amp;quot; theString)&lt;br /&gt;
    )&lt;br /&gt;
  )&lt;br /&gt;
)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
SCI code for wordFail compatible with SCI Companion.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;(method (wordFail theString)&lt;br /&gt;
  (method (wordFail theString)&lt;br /&gt;
  		(switch (Random 0 4)&lt;br /&gt;
    		(0&lt;br /&gt;
      		(FormatPrint {Oh, yeah? Well, %s this!} theString)&lt;br /&gt;
   			 )&lt;br /&gt;
    		(1&lt;br /&gt;
      		(FormatPrint {You may know the word %s but it&amp;#039;s beyond the game&amp;#039;s vocabulary!} theString)&lt;br /&gt;
    		)&lt;br /&gt;
    		(2&lt;br /&gt;
      		(FormatPrint {Oh, yeah? Well, I&amp;#039;ve got your %s right here!} theString)&lt;br /&gt;
    		)&lt;br /&gt;
    		(3&lt;br /&gt;
      		(FormatPrint {You don&amp;#039;t need to type the word %s to complete this game!} theString)&lt;br /&gt;
    		)&lt;br /&gt;
    		(else&lt;br /&gt;
      		(FormatPrint {Don&amp;#039;t you ever say the word %s again!} theString)&lt;br /&gt;
			)&lt;br /&gt;
		)&lt;br /&gt;
	)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This generates a random number from 0 to 4 (five possible numbers), and displays a response depending on which is generated.&lt;br /&gt;
&lt;br /&gt;
The syntaxFail and pragmaFail operate identical to wordFail, but I&amp;#039;ll give examples of them as well:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
(method (syntaxFail theString)&lt;br /&gt;
  (switch(Random(0 2))&lt;br /&gt;
    (case 0&lt;br /&gt;
      Print(&amp;quot;That doesn&amp;#039;t appear to be a proper sentence.&amp;quot;)&lt;br /&gt;
    )&lt;br /&gt;
    (case 1&lt;br /&gt;
      Print(&amp;quot;What in the heck are you talking about?&amp;quot;)&lt;br /&gt;
    )&lt;br /&gt;
    (default&lt;br /&gt;
      Print(&amp;quot;That&amp;#039;s probably something you could do, but this game won&amp;#039;t!&amp;quot;)&lt;br /&gt;
    )&lt;br /&gt;
  )&lt;br /&gt;
)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&amp;amp;nbsp;&lt;br /&gt;
SCI code for syntaxFail compatible with SCI Companion.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;(method (pragmaFail theString)&lt;br /&gt;
	(method (syntaxFail theString)&lt;br /&gt;
  		(switch (Random 0 2)&lt;br /&gt;
    		(0&lt;br /&gt;
     		(Print {That doesn&amp;#039;t appear to be a proper sentence.})&lt;br /&gt;
    		)&lt;br /&gt;
    		(1&lt;br /&gt;
      		(Print {What in the hell are you talking about?})&lt;br /&gt;
    		)&lt;br /&gt;
    		(else&lt;br /&gt;
     		(Print {That&amp;#039;s probably something you could do, but this game won&amp;#039;t!})&lt;br /&gt;
    		)&lt;br /&gt;
  		)&lt;br /&gt;
	)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;(method (pragmaFail theString)&lt;br /&gt;
  (switch(Random(0 2))&lt;br /&gt;
    (case 0&lt;br /&gt;
      Print(&amp;quot;The heck you say?&amp;quot;)&lt;br /&gt;
    )&lt;br /&gt;
    (case 1&lt;br /&gt;
      Print(&amp;quot;You&amp;#039;re too smart for this game!&amp;quot;)&lt;br /&gt;
    )&lt;br /&gt;
    (default&lt;br /&gt;
      Print(&amp;quot;Congratulations! You have dumbfounded this game!&amp;quot;)&lt;br /&gt;
    )&lt;br /&gt;
  )&lt;br /&gt;
)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
SCI code for pragmaFail compatible with SCI Companion.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;(method (pragmaFail theString)&lt;br /&gt;
  (method (pragmaFail theString)&lt;br /&gt;
  		(switch (Random 0 2)&lt;br /&gt;
    		(0&lt;br /&gt;
      		(Print {The hell you say?})&lt;br /&gt;
    		)&lt;br /&gt;
    		(1&lt;br /&gt;
      		(Print {You&amp;#039;re too smart for this game!})&lt;br /&gt;
    		)&lt;br /&gt;
    		(else&lt;br /&gt;
      		(Print {Congratulations! You have dumbfounded this game!})&lt;br /&gt;
    		)&lt;br /&gt;
  		)&lt;br /&gt;
	)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;amp;nbsp;&lt;br /&gt;
&lt;br /&gt;
The methods all take the string as a parameter. Whether you choose to use it or not is up to you.&lt;br /&gt;
&lt;br /&gt;
You can have as many or as few responses as you like. Just change the random amount and cases.&lt;br /&gt;
&lt;br /&gt;
That sums up global response handlers! Now your game can have attitude!&lt;br /&gt;
&lt;br /&gt;
&amp;amp;nbsp;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;float: left&amp;quot;&amp;gt;[[Global Said() Statements|&amp;amp;lt; Previous: Chapter 1 - Global Said() Statements]]&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;span style=&amp;quot;float: right&amp;quot;&amp;gt;[[Actor Paths|Next: Chapter 3 - Making Actors Move Along Paths &amp;amp;gt;]]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;amp;nbsp;&lt;br /&gt;
&lt;br /&gt;
[[Category:Said() Strings]]&lt;br /&gt;
[[Category:The SCI Parser]]&lt;br /&gt;
[[Category:Tutorials]]&lt;/div&gt;</summary>
		<author><name>Rob Craig</name></author>
	</entry>
	<entry>
		<id>http://sciwiki.sierrahelp.com/index.php?title=WordFail,_syntaxFail_and_pragmaFail&amp;diff=16010</id>
		<title>WordFail, syntaxFail and pragmaFail</title>
		<link rel="alternate" type="text/html" href="http://sciwiki.sierrahelp.com/index.php?title=WordFail,_syntaxFail_and_pragmaFail&amp;diff=16010"/>
		<updated>2023-05-31T12:40:39Z</updated>

		<summary type="html">&lt;p&gt;Rob Craig: /* Adding Response Handlers */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Chapter 2 - Oh, yeah? Well, &amp;quot;%s&amp;quot; this!=&lt;br /&gt;
&lt;br /&gt;
In order to make your game fun and enjoyable, you&amp;#039;ll want it to be more intelligent to the player. By default, if the player enters a word not in the vocabulary, or a sentence that doesn&amp;#039;t make sense, it will just display a message like &amp;quot;I don&amp;#039;t understand &amp;quot;that word&amp;quot;.&amp;quot; or &amp;quot;That sentence doesn&amp;#039;t make sense.&amp;quot;. This can be easily changed.&lt;br /&gt;
&lt;br /&gt;
In Sierra&amp;#039;s games, you&amp;#039;ll notice that it displays different responses when you enter invalid phrases. If you enter a word not in the game&amp;#039;s vocabulary, it will display &amp;quot;Oh, yeah? Well, &amp;quot;the word&amp;quot; this!&amp;quot; or &amp;quot;You don&amp;#039;t need to type the word &amp;quot;the word&amp;quot; to complete this game!&amp;quot;, or &amp;quot;Don&amp;#039;t you ever say the word &amp;quot;the word&amp;quot; again!&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
Implementing an intelligent response system is very easy. There are three types of phrase catchers: &amp;#039;&amp;#039;&amp;#039;wordFail&amp;#039;&amp;#039;&amp;#039;, &amp;#039;&amp;#039;&amp;#039;syntaxFail&amp;#039;&amp;#039;&amp;#039; and &amp;#039;&amp;#039;&amp;#039;pragmaFail&amp;#039;&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;wordFail&amp;#039;&amp;#039;&amp;#039;, is executed when the player enters a word in the phrase that is not in the game&amp;#039;s vocabulary.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;syntaxFail&amp;#039;&amp;#039;&amp;#039; is executed when the player enters an improper sentence.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;pragmaFail&amp;#039;&amp;#039;&amp;#039; is executed when the player enters an valid sentence that is not handled by any said statements.&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Adding Response Handlers ==&lt;br /&gt;
&lt;br /&gt;
The toolbar gives quick access to opening, closing and running games, the resource editors, and the help file. To add the response handlers, you simply need to add the methods by name to your game&amp;#039;s instance.&lt;br /&gt;
&lt;br /&gt;
[[Image:Script-Main.png|Main Script]] First, open up your game&amp;#039;s &amp;quot;main.sc&amp;quot; script.&lt;br /&gt;
&lt;br /&gt;
{| width=&amp;quot;100%&amp;quot;&lt;br /&gt;
| width=&amp;quot;274&amp;quot; | [[Image:Script-GameInstance.png|New Game Dialog]]&lt;br /&gt;
| valign=&amp;quot;top&amp;quot; | Scroll down to the game&amp;#039;s instance.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Scroll to the end of it and add the methods to handle the responses. You can add any or all in any order.&lt;br /&gt;
&lt;br /&gt;
You&amp;#039;ll naturally want multiple responses, and want them randomly said. To do this, we&amp;#039;ll use a combination of a switch statement and Rand() kernel call.&lt;br /&gt;
&lt;br /&gt;
We&amp;#039;ll start with the &amp;#039;&amp;#039;&amp;#039;wordFail&amp;#039;&amp;#039;&amp;#039; method. Here&amp;#039;s an example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;(method (wordFail theString)&lt;br /&gt;
  (switch(Random(0 4))&lt;br /&gt;
    (case 0&lt;br /&gt;
      FormatPrint(&amp;quot;Oh, yeah? Well, \&amp;quot;%s\&amp;quot; this!&amp;quot; theString)&lt;br /&gt;
    )&lt;br /&gt;
    (case 1&lt;br /&gt;
      FormatPrint(&amp;quot;You may know the word \&amp;quot;%s\&amp;quot; but it&amp;#039;s beyond &amp;#039;s vocabulary!&amp;quot; theString)&lt;br /&gt;
    )&lt;br /&gt;
    (case 2&lt;br /&gt;
      FormatPrint(&amp;quot;Oh, yeah? Well, I&amp;#039;ve got your \&amp;quot;%s\&amp;quot; right here!&amp;quot; theString)&lt;br /&gt;
    )&lt;br /&gt;
    (case 3&lt;br /&gt;
      FormatPrint(&amp;quot;You don&amp;#039;t need to type the word \&amp;quot;%s\&amp;quot; to complete this game!&amp;quot; theString)&lt;br /&gt;
    )&lt;br /&gt;
    (default&lt;br /&gt;
      FormatPrint(&amp;quot;Don&amp;#039;t you ever say the word \&amp;quot;%s\&amp;quot; again!&amp;quot; theString)&lt;br /&gt;
    )&lt;br /&gt;
  )&lt;br /&gt;
)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
SCI code compatible with SCI Companion.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;(method (wordFail theString)&lt;br /&gt;
  (method (wordFail theString)&lt;br /&gt;
  		(switch (Random 0 4)&lt;br /&gt;
    		(0&lt;br /&gt;
      		(FormatPrint {Oh, yeah? Well, %s this!} theString)&lt;br /&gt;
   			 )&lt;br /&gt;
    		(1&lt;br /&gt;
      		(FormatPrint {You may know the word %s but it&amp;#039;s beyond the game&amp;#039;s vocabulary!} theString)&lt;br /&gt;
    		)&lt;br /&gt;
    		(2&lt;br /&gt;
      		(FormatPrint {Oh, yeah? Well, I&amp;#039;ve got your %s right here!} theString)&lt;br /&gt;
    		)&lt;br /&gt;
    		(3&lt;br /&gt;
      		(FormatPrint {You don&amp;#039;t need to type the word %s to complete this game!} theString)&lt;br /&gt;
    		)&lt;br /&gt;
    		(else&lt;br /&gt;
      		(FormatPrint {Don&amp;#039;t you ever say the word %s again!} theString)&lt;br /&gt;
			)&lt;br /&gt;
		)&lt;br /&gt;
	)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This generates a random number from 0 to 4 (five possible numbers), and displays a response depending on which is generated.&lt;br /&gt;
&lt;br /&gt;
The syntaxFail and pragmaFail operate identical to wordFail, but I&amp;#039;ll give examples of them as well:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
(method (syntaxFail theString)&lt;br /&gt;
  (switch(Random(0 2))&lt;br /&gt;
    (case 0&lt;br /&gt;
      Print(&amp;quot;That doesn&amp;#039;t appear to be a proper sentence.&amp;quot;)&lt;br /&gt;
    )&lt;br /&gt;
    (case 1&lt;br /&gt;
      Print(&amp;quot;What in the heck are you talking about?&amp;quot;)&lt;br /&gt;
    )&lt;br /&gt;
    (default&lt;br /&gt;
      Print(&amp;quot;That&amp;#039;s probably something you could do, but this game won&amp;#039;t!&amp;quot;)&lt;br /&gt;
    )&lt;br /&gt;
  )&lt;br /&gt;
)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&amp;amp;nbsp;&lt;br /&gt;
SCI code compatible with SCI Companion.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;(method (pragmaFail theString)&lt;br /&gt;
	(method (syntaxFail theString)&lt;br /&gt;
  		(switch (Random 0 2)&lt;br /&gt;
    		(0&lt;br /&gt;
     		(Print {That doesn&amp;#039;t appear to be a proper sentence.})&lt;br /&gt;
    		)&lt;br /&gt;
    		(1&lt;br /&gt;
      		(Print {What in the hell are you talking about?})&lt;br /&gt;
    		)&lt;br /&gt;
    		(else&lt;br /&gt;
     		(Print {That&amp;#039;s probably something you could do, but this game won&amp;#039;t!})&lt;br /&gt;
    		)&lt;br /&gt;
  		)&lt;br /&gt;
	)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;(method (pragmaFail theString)&lt;br /&gt;
  (switch(Random(0 2))&lt;br /&gt;
    (case 0&lt;br /&gt;
      Print(&amp;quot;The heck you say?&amp;quot;)&lt;br /&gt;
    )&lt;br /&gt;
    (case 1&lt;br /&gt;
      Print(&amp;quot;You&amp;#039;re too smart for this game!&amp;quot;)&lt;br /&gt;
    )&lt;br /&gt;
    (default&lt;br /&gt;
      Print(&amp;quot;Congratulations! You have dumbfounded this game!&amp;quot;)&lt;br /&gt;
    )&lt;br /&gt;
  )&lt;br /&gt;
)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
(method (syntaxFail theString)&lt;br /&gt;
  (switch(Random(0 2))&lt;br /&gt;
    (case 0&lt;br /&gt;
      Print(&amp;quot;That doesn&amp;#039;t appear to be a proper sentence.&amp;quot;)&lt;br /&gt;
    )&lt;br /&gt;
    (case 1&lt;br /&gt;
      Print(&amp;quot;What in the heck are you talking about?&amp;quot;)&lt;br /&gt;
    )&lt;br /&gt;
    (default&lt;br /&gt;
      Print(&amp;quot;That&amp;#039;s probably something you could do, but this game won&amp;#039;t!&amp;quot;)&lt;br /&gt;
    )&lt;br /&gt;
  )&lt;br /&gt;
)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&amp;amp;nbsp;&lt;br /&gt;
&lt;br /&gt;
The methods all take the string as a parameter. Whether you choose to use it or not is up to you.&lt;br /&gt;
&lt;br /&gt;
You can have as many or as few responses as you like. Just change the random amount and cases.&lt;br /&gt;
&lt;br /&gt;
That sums up global response handlers! Now your game can have attitude!&lt;br /&gt;
&lt;br /&gt;
&amp;amp;nbsp;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;float: left&amp;quot;&amp;gt;[[Global Said() Statements|&amp;amp;lt; Previous: Chapter 1 - Global Said() Statements]]&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;span style=&amp;quot;float: right&amp;quot;&amp;gt;[[Actor Paths|Next: Chapter 3 - Making Actors Move Along Paths &amp;amp;gt;]]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;amp;nbsp;&lt;br /&gt;
&lt;br /&gt;
[[Category:Said() Strings]]&lt;br /&gt;
[[Category:The SCI Parser]]&lt;br /&gt;
[[Category:Tutorials]]&lt;/div&gt;</summary>
		<author><name>Rob Craig</name></author>
	</entry>
	<entry>
		<id>http://sciwiki.sierrahelp.com/index.php?title=WordFail,_syntaxFail_and_pragmaFail&amp;diff=16009</id>
		<title>WordFail, syntaxFail and pragmaFail</title>
		<link rel="alternate" type="text/html" href="http://sciwiki.sierrahelp.com/index.php?title=WordFail,_syntaxFail_and_pragmaFail&amp;diff=16009"/>
		<updated>2023-05-31T12:34:43Z</updated>

		<summary type="html">&lt;p&gt;Rob Craig: /* Adding Response Handlers */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Chapter 2 - Oh, yeah? Well, &amp;quot;%s&amp;quot; this!=&lt;br /&gt;
&lt;br /&gt;
In order to make your game fun and enjoyable, you&amp;#039;ll want it to be more intelligent to the player. By default, if the player enters a word not in the vocabulary, or a sentence that doesn&amp;#039;t make sense, it will just display a message like &amp;quot;I don&amp;#039;t understand &amp;quot;that word&amp;quot;.&amp;quot; or &amp;quot;That sentence doesn&amp;#039;t make sense.&amp;quot;. This can be easily changed.&lt;br /&gt;
&lt;br /&gt;
In Sierra&amp;#039;s games, you&amp;#039;ll notice that it displays different responses when you enter invalid phrases. If you enter a word not in the game&amp;#039;s vocabulary, it will display &amp;quot;Oh, yeah? Well, &amp;quot;the word&amp;quot; this!&amp;quot; or &amp;quot;You don&amp;#039;t need to type the word &amp;quot;the word&amp;quot; to complete this game!&amp;quot;, or &amp;quot;Don&amp;#039;t you ever say the word &amp;quot;the word&amp;quot; again!&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
Implementing an intelligent response system is very easy. There are three types of phrase catchers: &amp;#039;&amp;#039;&amp;#039;wordFail&amp;#039;&amp;#039;&amp;#039;, &amp;#039;&amp;#039;&amp;#039;syntaxFail&amp;#039;&amp;#039;&amp;#039; and &amp;#039;&amp;#039;&amp;#039;pragmaFail&amp;#039;&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;wordFail&amp;#039;&amp;#039;&amp;#039;, is executed when the player enters a word in the phrase that is not in the game&amp;#039;s vocabulary.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;syntaxFail&amp;#039;&amp;#039;&amp;#039; is executed when the player enters an improper sentence.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;pragmaFail&amp;#039;&amp;#039;&amp;#039; is executed when the player enters an valid sentence that is not handled by any said statements.&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Adding Response Handlers ==&lt;br /&gt;
&lt;br /&gt;
The toolbar gives quick access to opening, closing and running games, the resource editors, and the help file. To add the response handlers, you simply need to add the methods by name to your game&amp;#039;s instance.&lt;br /&gt;
&lt;br /&gt;
[[Image:Script-Main.png|Main Script]] First, open up your game&amp;#039;s &amp;quot;main.sc&amp;quot; script.&lt;br /&gt;
&lt;br /&gt;
{| width=&amp;quot;100%&amp;quot;&lt;br /&gt;
| width=&amp;quot;274&amp;quot; | [[Image:Script-GameInstance.png|New Game Dialog]]&lt;br /&gt;
| valign=&amp;quot;top&amp;quot; | Scroll down to the game&amp;#039;s instance.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Scroll to the end of it and add the methods to handle the responses. You can add any or all in any order.&lt;br /&gt;
&lt;br /&gt;
You&amp;#039;ll naturally want multiple responses, and want them randomly said. To do this, we&amp;#039;ll use a combination of a switch statement and Rand() kernel call.&lt;br /&gt;
&lt;br /&gt;
We&amp;#039;ll start with the &amp;#039;&amp;#039;&amp;#039;wordFail&amp;#039;&amp;#039;&amp;#039; method. Here&amp;#039;s an example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;(method (wordFail theString)&lt;br /&gt;
  (switch(Random(0 4))&lt;br /&gt;
    (case 0&lt;br /&gt;
      FormatPrint(&amp;quot;Oh, yeah? Well, \&amp;quot;%s\&amp;quot; this!&amp;quot; theString)&lt;br /&gt;
    )&lt;br /&gt;
    (case 1&lt;br /&gt;
      FormatPrint(&amp;quot;You may know the word \&amp;quot;%s\&amp;quot; but it&amp;#039;s beyond &amp;#039;s vocabulary!&amp;quot; theString)&lt;br /&gt;
    )&lt;br /&gt;
    (case 2&lt;br /&gt;
      FormatPrint(&amp;quot;Oh, yeah? Well, I&amp;#039;ve got your \&amp;quot;%s\&amp;quot; right here!&amp;quot; theString)&lt;br /&gt;
    )&lt;br /&gt;
    (case 3&lt;br /&gt;
      FormatPrint(&amp;quot;You don&amp;#039;t need to type the word \&amp;quot;%s\&amp;quot; to complete this game!&amp;quot; theString)&lt;br /&gt;
    )&lt;br /&gt;
    (default&lt;br /&gt;
      FormatPrint(&amp;quot;Don&amp;#039;t you ever say the word \&amp;quot;%s\&amp;quot; again!&amp;quot; theString)&lt;br /&gt;
    )&lt;br /&gt;
  )&lt;br /&gt;
)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
SCI code compatible with SCI Companion.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;(method (wordFail theString)&lt;br /&gt;
  (method (wordFail theString)&lt;br /&gt;
  		(switch (Random 0 4)&lt;br /&gt;
    		(0&lt;br /&gt;
      		(FormatPrint {Oh, yeah? Well, %s this!} theString)&lt;br /&gt;
   			 )&lt;br /&gt;
    		(1&lt;br /&gt;
      		(FormatPrint {You may know the word %s but it&amp;#039;s beyond the game&amp;#039;s vocabulary!} theString)&lt;br /&gt;
    		)&lt;br /&gt;
    		(2&lt;br /&gt;
      		(FormatPrint {Oh, yeah? Well, I&amp;#039;ve got your %s right here!} theString)&lt;br /&gt;
    		)&lt;br /&gt;
    		(3&lt;br /&gt;
      		(FormatPrint {You don&amp;#039;t need to type the word %s to complete this game!} theString)&lt;br /&gt;
    		)&lt;br /&gt;
    		(else&lt;br /&gt;
      		(FormatPrint {Don&amp;#039;t you ever say the word %s again!} theString)&lt;br /&gt;
			)&lt;br /&gt;
		)&lt;br /&gt;
	)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This generates a random number from 0 to 4 (five possible numbers), and displays a response depending on which is generated.&lt;br /&gt;
&lt;br /&gt;
The syntaxFail and pragmaFail operate identical to wordFail, but I&amp;#039;ll give examples of them as well:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
(method (syntaxFail theString)&lt;br /&gt;
  (switch(Random(0 2))&lt;br /&gt;
    (case 0&lt;br /&gt;
      Print(&amp;quot;That doesn&amp;#039;t appear to be a proper sentence.&amp;quot;)&lt;br /&gt;
    )&lt;br /&gt;
    (case 1&lt;br /&gt;
      Print(&amp;quot;What in the heck are you talking about?&amp;quot;)&lt;br /&gt;
    )&lt;br /&gt;
    (default&lt;br /&gt;
      Print(&amp;quot;That&amp;#039;s probably something you could do, but this game won&amp;#039;t!&amp;quot;)&lt;br /&gt;
    )&lt;br /&gt;
  )&lt;br /&gt;
)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&amp;amp;nbsp;&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;(method (pragmaFail theString)&lt;br /&gt;
  (switch(Random(0 2))&lt;br /&gt;
    (case 0&lt;br /&gt;
      Print(&amp;quot;The heck you say?&amp;quot;)&lt;br /&gt;
    )&lt;br /&gt;
    (case 1&lt;br /&gt;
      Print(&amp;quot;You&amp;#039;re too smart for this game!&amp;quot;)&lt;br /&gt;
    )&lt;br /&gt;
    (default&lt;br /&gt;
      Print(&amp;quot;Congratulations! You have dumbfounded this game!&amp;quot;)&lt;br /&gt;
    )&lt;br /&gt;
  )&lt;br /&gt;
)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
(method (syntaxFail theString)&lt;br /&gt;
  (switch(Random(0 2))&lt;br /&gt;
    (case 0&lt;br /&gt;
      Print(&amp;quot;That doesn&amp;#039;t appear to be a proper sentence.&amp;quot;)&lt;br /&gt;
    )&lt;br /&gt;
    (case 1&lt;br /&gt;
      Print(&amp;quot;What in the heck are you talking about?&amp;quot;)&lt;br /&gt;
    )&lt;br /&gt;
    (default&lt;br /&gt;
      Print(&amp;quot;That&amp;#039;s probably something you could do, but this game won&amp;#039;t!&amp;quot;)&lt;br /&gt;
    )&lt;br /&gt;
  )&lt;br /&gt;
)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&amp;amp;nbsp;&lt;br /&gt;
&lt;br /&gt;
SCI code compatible with SCI Companion.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;(method (pragmaFail theString)&lt;br /&gt;
	(method (syntaxFail theString)&lt;br /&gt;
  		(switch (Random 0 2)&lt;br /&gt;
    		(0&lt;br /&gt;
     		(Print {That doesn&amp;#039;t appear to be a proper sentence.})&lt;br /&gt;
    		)&lt;br /&gt;
    		(1&lt;br /&gt;
      		(Print {What in the hell are you talking about?})&lt;br /&gt;
    		)&lt;br /&gt;
    		(else&lt;br /&gt;
     		(Print {That&amp;#039;s probably something you could do, but this game won&amp;#039;t!})&lt;br /&gt;
    		)&lt;br /&gt;
  		)&lt;br /&gt;
	)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The methods all take the string as a parameter. Whether you choose to use it or not is up to you.&lt;br /&gt;
&lt;br /&gt;
You can have as many or as few responses as you like. Just change the random amount and cases.&lt;br /&gt;
&lt;br /&gt;
That sums up global response handlers! Now your game can have attitude!&lt;br /&gt;
&lt;br /&gt;
&amp;amp;nbsp;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;float: left&amp;quot;&amp;gt;[[Global Said() Statements|&amp;amp;lt; Previous: Chapter 1 - Global Said() Statements]]&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;span style=&amp;quot;float: right&amp;quot;&amp;gt;[[Actor Paths|Next: Chapter 3 - Making Actors Move Along Paths &amp;amp;gt;]]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;amp;nbsp;&lt;br /&gt;
&lt;br /&gt;
[[Category:Said() Strings]]&lt;br /&gt;
[[Category:The SCI Parser]]&lt;br /&gt;
[[Category:Tutorials]]&lt;/div&gt;</summary>
		<author><name>Rob Craig</name></author>
	</entry>
	<entry>
		<id>http://sciwiki.sierrahelp.com/index.php?title=WordFail,_syntaxFail_and_pragmaFail&amp;diff=16008</id>
		<title>WordFail, syntaxFail and pragmaFail</title>
		<link rel="alternate" type="text/html" href="http://sciwiki.sierrahelp.com/index.php?title=WordFail,_syntaxFail_and_pragmaFail&amp;diff=16008"/>
		<updated>2023-05-31T12:32:54Z</updated>

		<summary type="html">&lt;p&gt;Rob Craig: /* Adding Response Handlers */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Chapter 2 - Oh, yeah? Well, &amp;quot;%s&amp;quot; this!=&lt;br /&gt;
&lt;br /&gt;
In order to make your game fun and enjoyable, you&amp;#039;ll want it to be more intelligent to the player. By default, if the player enters a word not in the vocabulary, or a sentence that doesn&amp;#039;t make sense, it will just display a message like &amp;quot;I don&amp;#039;t understand &amp;quot;that word&amp;quot;.&amp;quot; or &amp;quot;That sentence doesn&amp;#039;t make sense.&amp;quot;. This can be easily changed.&lt;br /&gt;
&lt;br /&gt;
In Sierra&amp;#039;s games, you&amp;#039;ll notice that it displays different responses when you enter invalid phrases. If you enter a word not in the game&amp;#039;s vocabulary, it will display &amp;quot;Oh, yeah? Well, &amp;quot;the word&amp;quot; this!&amp;quot; or &amp;quot;You don&amp;#039;t need to type the word &amp;quot;the word&amp;quot; to complete this game!&amp;quot;, or &amp;quot;Don&amp;#039;t you ever say the word &amp;quot;the word&amp;quot; again!&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
Implementing an intelligent response system is very easy. There are three types of phrase catchers: &amp;#039;&amp;#039;&amp;#039;wordFail&amp;#039;&amp;#039;&amp;#039;, &amp;#039;&amp;#039;&amp;#039;syntaxFail&amp;#039;&amp;#039;&amp;#039; and &amp;#039;&amp;#039;&amp;#039;pragmaFail&amp;#039;&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;wordFail&amp;#039;&amp;#039;&amp;#039;, is executed when the player enters a word in the phrase that is not in the game&amp;#039;s vocabulary.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;syntaxFail&amp;#039;&amp;#039;&amp;#039; is executed when the player enters an improper sentence.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;pragmaFail&amp;#039;&amp;#039;&amp;#039; is executed when the player enters an valid sentence that is not handled by any said statements.&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Adding Response Handlers ==&lt;br /&gt;
&lt;br /&gt;
The toolbar gives quick access to opening, closing and running games, the resource editors, and the help file. To add the response handlers, you simply need to add the methods by name to your game&amp;#039;s instance.&lt;br /&gt;
&lt;br /&gt;
[[Image:Script-Main.png|Main Script]] First, open up your game&amp;#039;s &amp;quot;main.sc&amp;quot; script.&lt;br /&gt;
&lt;br /&gt;
{| width=&amp;quot;100%&amp;quot;&lt;br /&gt;
| width=&amp;quot;274&amp;quot; | [[Image:Script-GameInstance.png|New Game Dialog]]&lt;br /&gt;
| valign=&amp;quot;top&amp;quot; | Scroll down to the game&amp;#039;s instance.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Scroll to the end of it and add the methods to handle the responses. You can add any or all in any order.&lt;br /&gt;
&lt;br /&gt;
You&amp;#039;ll naturally want multiple responses, and want them randomly said. To do this, we&amp;#039;ll use a combination of a switch statement and Rand() kernel call.&lt;br /&gt;
&lt;br /&gt;
We&amp;#039;ll start with the &amp;#039;&amp;#039;&amp;#039;wordFail&amp;#039;&amp;#039;&amp;#039; method. Here&amp;#039;s an example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;(method (wordFail theString)&lt;br /&gt;
  (switch(Random(0 4))&lt;br /&gt;
    (case 0&lt;br /&gt;
      FormatPrint(&amp;quot;Oh, yeah? Well, \&amp;quot;%s\&amp;quot; this!&amp;quot; theString)&lt;br /&gt;
    )&lt;br /&gt;
    (case 1&lt;br /&gt;
      FormatPrint(&amp;quot;You may know the word \&amp;quot;%s\&amp;quot; but it&amp;#039;s beyond &amp;#039;s vocabulary!&amp;quot; theString)&lt;br /&gt;
    )&lt;br /&gt;
    (case 2&lt;br /&gt;
      FormatPrint(&amp;quot;Oh, yeah? Well, I&amp;#039;ve got your \&amp;quot;%s\&amp;quot; right here!&amp;quot; theString)&lt;br /&gt;
    )&lt;br /&gt;
    (case 3&lt;br /&gt;
      FormatPrint(&amp;quot;You don&amp;#039;t need to type the word \&amp;quot;%s\&amp;quot; to complete this game!&amp;quot; theString)&lt;br /&gt;
    )&lt;br /&gt;
    (default&lt;br /&gt;
      FormatPrint(&amp;quot;Don&amp;#039;t you ever say the word \&amp;quot;%s\&amp;quot; again!&amp;quot; theString)&lt;br /&gt;
    )&lt;br /&gt;
  )&lt;br /&gt;
)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
SCI Code compatible with SCI Companion.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;(method (wordFail theString)&lt;br /&gt;
  (method (wordFail theString)&lt;br /&gt;
  		(switch (Random 0 4)&lt;br /&gt;
    		(0&lt;br /&gt;
      		(FormatPrint {Oh, yeah? Well, %s this!} theString)&lt;br /&gt;
   			 )&lt;br /&gt;
    		(1&lt;br /&gt;
      		(FormatPrint {You may know the word %s but it&amp;#039;s beyond the game&amp;#039;s vocabulary!} theString)&lt;br /&gt;
    		)&lt;br /&gt;
    		(2&lt;br /&gt;
      		(FormatPrint {Oh, yeah? Well, I&amp;#039;ve got your %s right here!} theString)&lt;br /&gt;
    		)&lt;br /&gt;
    		(3&lt;br /&gt;
      		(FormatPrint {You don&amp;#039;t need to type the word %s to complete this game!} theString)&lt;br /&gt;
    		)&lt;br /&gt;
    		(else&lt;br /&gt;
      		(FormatPrint {Don&amp;#039;t you ever say the word %s again!} theString)&lt;br /&gt;
			)&lt;br /&gt;
		)&lt;br /&gt;
	)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This generates a random number from 0 to 4 (five possible numbers), and displays a response depending on which is generated.&lt;br /&gt;
&lt;br /&gt;
The syntaxFail and pragmaFail operate identical to wordFail, but I&amp;#039;ll give examples of them as well:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
(method (syntaxFail theString)&lt;br /&gt;
  (switch(Random(0 2))&lt;br /&gt;
    (case 0&lt;br /&gt;
      Print(&amp;quot;That doesn&amp;#039;t appear to be a proper sentence.&amp;quot;)&lt;br /&gt;
    )&lt;br /&gt;
    (case 1&lt;br /&gt;
      Print(&amp;quot;What in the heck are you talking about?&amp;quot;)&lt;br /&gt;
    )&lt;br /&gt;
    (default&lt;br /&gt;
      Print(&amp;quot;That&amp;#039;s probably something you could do, but this game won&amp;#039;t!&amp;quot;)&lt;br /&gt;
    )&lt;br /&gt;
  )&lt;br /&gt;
)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&amp;amp;nbsp;&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;CodeBlockHeader&amp;quot;&amp;gt;Code:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sci&amp;quot; class=&amp;quot;cs&amp;quot;&amp;gt;(method (pragmaFail theString)&lt;br /&gt;
  (switch(Random(0 2))&lt;br /&gt;
    (case 0&lt;br /&gt;
      Print(&amp;quot;The heck you say?&amp;quot;)&lt;br /&gt;
    )&lt;br /&gt;
    (case 1&lt;br /&gt;
      Print(&amp;quot;You&amp;#039;re too smart for this game!&amp;quot;)&lt;br /&gt;
    )&lt;br /&gt;
    (default&lt;br /&gt;
      Print(&amp;quot;Congratulations! You have dumbfounded this game!&amp;quot;)&lt;br /&gt;
    )&lt;br /&gt;
  )&lt;br /&gt;
)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The methods all take the string as a parameter. Whether you choose to use it or not is up to you.&lt;br /&gt;
&lt;br /&gt;
You can have as many or as few responses as you like. Just change the random amount and cases.&lt;br /&gt;
&lt;br /&gt;
That sums up global response handlers! Now your game can have attitude!&lt;br /&gt;
&lt;br /&gt;
&amp;amp;nbsp;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;float: left&amp;quot;&amp;gt;[[Global Said() Statements|&amp;amp;lt; Previous: Chapter 1 - Global Said() Statements]]&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;span style=&amp;quot;float: right&amp;quot;&amp;gt;[[Actor Paths|Next: Chapter 3 - Making Actors Move Along Paths &amp;amp;gt;]]&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;amp;nbsp;&lt;br /&gt;
&lt;br /&gt;
[[Category:Said() Strings]]&lt;br /&gt;
[[Category:The SCI Parser]]&lt;br /&gt;
[[Category:Tutorials]]&lt;/div&gt;</summary>
		<author><name>Rob Craig</name></author>
	</entry>
</feed>