Community
SCI Programming => SCI Syntax Help => Topic started by: robbo007 on May 29, 2023, 08:21:39 AM
-
Hi guys,
Did anyone ever convert the code from these tutorials to SCI at any point? I've been tackling it but getting very lost.
http://sierrahelp.com/SCI/Tutorials/Tutorial2/chapter07.html
http://sierrahelp.com/SCI/Tutorials/Tutorial2/chapter08.html
http://sierrahelp.com/SCI/Tutorials/Tutorial2/chapter09.html
Regards,
Rob
-
Chapter 7
Change: (= nsBottom (+ nsTop [rect rtBOTTOM]))
To: (= nsBottom (+ nsTop (| (& [rect rtBOTTOM] $FFFC) 7)))
and change: (= nsRight (+ [rect rtRIGHT] nsLeft))
To: (= nsRight (+ (| (& [rect rtRIGHT] $FFFC) 7) nsLeft))
Add the following code to the DButton class.
(method (draw &tmp x y x2 y2 w h [rect 4])
; Calculate the areas
(= x2 (- nsRight 8))
(= y2 (- nsBottom 8))
(= w (- nsRight nsLeft))
(= h (- nsBottom nsTop))
(TextSize @rect text font)
; Draw the side borders
(for ( (= y (+ nsTop 8))) (< y y2) ( (= y (+ y 8)))
(DrawCel 900 0 4 nsLeft y -1)
(DrawCel 900 0 6 x2 y -1)
)
; Draw the top and bottom borders
(for ( (= x (+ nsLeft 8))) (< x x2) ( (= x (+ x 8))) (DrawCel 900 0 5 x nsTop -1) (DrawCel 900 0 7 x y2 -1))
; Draw the corners
(DrawCel 900 0 0 nsLeft nsTop -1)
(DrawCel 900 0 1 x2 nsTop -1)
(DrawCel 900 0 2 nsLeft y2 -1)
(DrawCel 900 0 3 x2 y2 -1)
; Draw the text
(Display text
dsCOORD
(+ nsLeft (>> (- w [rect rtRIGHT]) 1))
(+ (+ nsTop (>> (- h [rect rtBOTTOM]) 1)) 1)
dsCOLOR gWndColor
dsBACKGROUND clTRANSPARENT
dsFONT font
dsWIDTH [rect rtRIGHT]
)
)
To go with the default custom button, we'll make the window silver.
Change: (= gWndBack clWHITE)
To: (= gWndBack clSILVER)
Chapter 8
Replace the entire method with the following code:
(method (open theType thePriority)
(if (and (PicNotValid) gCast)
(Animate (gCast elements?) 0)
)
(= window (window new:))
(= nsRight (+ nsRight 2))
(= nsLeft (- nsLeft 2))
(if (& theType nwTITLE)
(= nsBottom (+ nsBottom 10))
(= nsTop (- nsTop 10))
(self eachElementDo: #move 2 18)
else
(= nsBottom (+ nsBottom 2))
(= nsTop (- nsTop 2))
(self eachElementDo: #move 2 2)
)
(window
top: nsTop
left: nsLeft
bottom: nsBottom
right: nsRight
title: text
type: nwNOFRAME
priority: thePriority
color: gWndColor
back: gWndBack
open:
)
(= seconds time)
(self draw:)
)
Scroll down and replace the draw method with the following:
(method (draw &tmp hItem x y x2 y2 y3 w h [rect 4])
(= x2 (- (- nsRight nsLeft) 16))
(= y2 (- (- nsBottom nsTop) 16))
(= w (- nsRight nsLeft))
(= h (- nsBottom nsTop))
(TextSize @rect text 0)
(for ( (= y 16)) (< y y2) ( (= y (+ y 16)))
(DrawCel 901 0 4 0 y -1)
(DrawCel 901 0 6 x2 y -1)
)
(DrawCel 901 0 2 0 y2 -1)
(DrawCel 901 0 3 x2 y2 -1)
(if text
(for ( (= x 16)) (< x x2) ( (= x (+ x 16)))
(DrawCel 901 0 10 x 0 -1)
(DrawCel 901 0 5 x 16 -1)
(DrawCel 901 0 7 x y2 -1)
)
(DrawCel 901 0 8 0 0 -1)
(DrawCel 901 0 9 x2 0 -1)
(DrawCel 901 0 0 0 16 -1)
(DrawCel 901 0 1 x2 16 -1)
(Display text
dsCOORD
(>> (- w [rect rtRIGHT]) 1)
(>> (- 18 [rect rtBOTTOM]) 1)
dsCOLOR clWHITE
dsBACKGROUND clTRANSPARENT
dsFONT 0
dsWIDTH [rect rtRIGHT]
)
else
(for ( (= x 16)) (< x x2) ( (= x (+ x 16)))
(DrawCel 901 0 5 x 0 -1)
(DrawCel 901 0 7 x y2 -1)
)
(DrawCel 901 0 0 0 0 -1)
(DrawCel 901 0 1 x2 0 -1)
)
(self eachElementDo: #draw)
)
Chapter 9
There appears to be something about the replacement Gauge script that makes it not compile. Will have to call again.
-
Keep in mind that those tutorials are old an in Studio script. You will want to use Sierra script. Try this instead: http://scicompanion.com/Documentation/index.html
-
But Collector, that's the whole point: to convert those old tutorials to Sierra script. Which I did, for the first two out of three links.
-
True. It is something that I have been meaning to get around to doing at some point, but never find the time. The Wiki needs this done as well.
-
Amazing, Thanks again Kawa. Yeah the Gauge script had some changes in it. I need to go through it to find out what exactly was changed.
If I had access to edit the wiki I would help update it.
I've converted the "Chapter 2 - Oh, yeah? Well, "%s" this!" but that was pretty easy. :http://sierrahelp.com/SCI/Tutorials/Tutorial2/chapter02.html
If someone wants to update the wiki also with this. It would be good to include this post from Gumby as well: https://sciprogramming.com/community/index.php?topic=603.msg3346#msg3346
(method (wordFail theString)
(switch (Random 0 4)
(0
(FormatPrint {Oh, yeah? Well, %s this!} theString)
)
(1
(FormatPrint {You may know the word %s but it's beyond the game's vocabulary!} theString)
)
(2
(FormatPrint {Oh, yeah? Well, I've got your %s right here!} theString)
)
(3
(FormatPrint {You don't need to type the word %s to complete this game!} theString)
)
(else
(FormatPrint {Don't you ever say the word %s again!} theString)
)
)
)
(method (syntaxFail theString)
(switch (Random 0 2)
(0
(Print {That doesn't appear to be a proper sentence.})
)
(1
(Print {What in the hell are you talking about?})
)
(else
(Print {That's probably something you could do, but this game won't!})
)
)
)
(method (pragmaFail theString)
(switch (Random 0 2)
(0
(Print {The hell you say?})
)
(1
(Print {You're too smart for this game!})
)
(else
(Print {Congratulations! You have dumbfounded this game!})
)
)
)
-
If I had access to edit the wiki I would help update it.
PM me your real name and an email address and I'll create an account for you.
-
It would be good to include this post from Gumby as well
NONE OF THIS IS TESTED TO COMPILATION. I DID THIS MANUALLY.
Part 1: Parse the Verb
(= Verb UNSET) ; initialize it to 'nothing' before each parse
(if (Said 'dig/*/*>') ; ex: dig in ground with shovel
(= Verb VERB_DIG)
)
(if (Said 'dig/*[/!*]>') ; ex: dig in ground
(= Verb VERB_DIG)
(= needSecond TRUE) ; what do you want to dig in the ground with?
)
(if (Said 'dig[/!*]>') ; ex: dig
(= Verb VERB_DIG)
(= needNoun TRUE) ; what do you want to dig in?
)
Part 2: Parsing the noun & 'second' noun
(= noun UNSET) ; initialize it to 'nothing' before each parse
(if (Said '*/ground>')
(= noun GROUND_OBJ)
)
(if (Said '*/shovel>')
(= noun SHOVEL_OBJ)
)
and:
(= second UNSET) ; initialize it to 'nothing' before each parse
(if (Said '*/*/ground>')
(= second GROUND_OBJ)
)
(if (Said '*/*/shovel>')
(= second SHOVEL_OBJ)
)
Part 3: A robust 'pragmaFail' method
(procedure (RobustPragmaFail)
(if (and (== needNoun TRUE) (== noun UNSET))
(FormatPrint "What do you want to %s?" VERB_NAMES Verb)
(return TRUE)
)
(if (and (== needSecond TRUE) (== second UNSET))
(FormatPrint "What do you want to %s the %s with?" VERB_NAMES Verb NOUN_NAMES noun)
(return TRUE)
)
(if (and (== unneededNoun TRUE) (!= noun UNSET))
(FormatPrint "I understood only as far as you wanting to %s." VERB_NAMES Verb)
(return TRUE)
)
(if (and (== unneededSecond TRUE) (!= second UNSET)
(FormatPrint "I understood only as far as you wanting to %s the %s." VERB_NAMES Verb NOUN_NAMES noun)
(return TRUE)
)
(return FALSE)
)
Part 4: Are the nouns here?
;;; *************** Main.sc *************
;; global variables
Verb
noun
second
needNoun
needSecond
unneededNoun
unneededSecond
;; The array that will track where our objects are
[objectLocations10] ; one for each object in our game
;; in the init method of Main.sc
(= [objectLocations TREE_OBJ] TREE_ROOM)
(= [objectLocations SAW_OBJ] NOWHERE)
(= [objectLocations GROUND_OBJ] EVERYWHERE)
(= [objectLocations SHOVEL_OBJ] HOUSE_ROOM)
(= [objectLocations BIRD_OBJ] TREE_ROOM)
(= [objectLocations HOUSE_OBJ] HOUSE_ROOM)
(= [objectLocations DOOR_OBJ] HOUSE_ROOM)
(= [objectLocations KEY_OBJ] INVENTORY)
;; Rooms
(define INVENTORY -2)
(define EVERYWHERE -1)
(define NOWHERE 0)
;; From here, the number should match the room script numbers
(define HOUSE_ROOM 1)
(define TREE_ROOM 2)
Here's the procedure that does the checking for whether the nouns are 'in-scope':
(procedure (ValidateNouns)
(if (!= noun UNSET)
(if (and
(!= [objectLocations noun] gRoomNumber)
(!= [objectLocations noun] INVENTORY)
(!= [objectLocations noun] EVERYWHERE)
)
(FormatPrint "I don't see any %s here." NOUN_NAMES noun)
return FALSE)
)
)
(if (!= second UNSET)
(if (and
(!= [objectLocations second] gRoomNumber)
(!= [objectLocations second] INVENTORY)
(!= [objectLocations second] EVERYWHERE)
)
(FormatPrint "I don't see any %s here." NOUN_NAMES second)
(return FALSE)
)
)
; All the nouns are here
(return TRUE)
)
Part 5: Call the action script
(procedure (CallAction)
(if (== Verb VERB_CUT) (CutAction) (return))
(if (== Verb VERB_CLIMBUP) (ClimbUpAction) (return))
(if (== Verb VERB_CLIMBDOWN) (ClimbDownAction) (return))
(if (== Verb VERB_DIG) (DigAction) (return))
(if (== Verb VERB_LISTEN) (ListenAction) (return))
(if (== Verb VERB_LOOK) (LookAction) (return))
(if (== Verb VERB_RUN) (RunAction) (return))
)
(KAWA NOTE: I'd rewrite that as a switch but maybe that's just me lol.
(procedure public (DigAction)
; Could be "dig ground with shovel" or "dig with shovel in ground"
(if (and (!= second SHOVEL_OBJ) (!= noun SHOVEL_OBJ))
Print "That doesn't have a blade adequate for digging.")
(return)
)
(if (and (!= second GROUND_OBJ) (!= noun GROUND_OBJ))
(Print "It would be best if you dug in something sensible!")
(return)
)
(Print "Nice hole. What next?")
)
NONE OF THIS IS TESTED TO COMPILATION. I DID THIS MANUALLY.
-
I have corrected the syntax error in the fancier Gauge script, allowing it to be converted to Sierra Script, and attached it. And that concludes the first post's workload.
-
Chapter 7
Change: (= nsBottom (+ nsTop [rect rtBOTTOM]))
To: = nsBottom (+ nsTop (| (& rect[rtBOTTOM] $FFFC) 7))
and change: (= nsRight (+ [rect rtRIGHT] nsLeft))
To: = nsRight (+ (| (& rect[rtRIGHT] $FFFC) 7) nsLeft)
Add the following code to the DButton class.
(method (draw &tmp x y x2 y2 w h [rect 4])
; Calculate the areas
(= x2 (- nsRight 8))
(= y2 (- nsBottom 8))
(= w (- nsRight nsLeft))
(= h (- nsBottom nsTop))
(TextSize @rect text font)
; Draw the side borders
(for ( (= y (+ nsTop 8))) (< y y2) ( (= y (+ y 8))) (DrawCel 900 0 4 nsLeft y -1) (DrawCel 900 0 6 x2 y -1))
; Draw the top and bottom borders
(for ( (= x (+ nsLeft 8))) (< x x2) ( (= x (+ x 8))) (DrawCel 900 0 5 x nsTop -1) (DrawCel 900 0 7 x y2 -1))
; Draw the corners
(DrawCel 900 0 0 nsLeft nsTop -1)
(DrawCel 900 0 1 x2 nsTop -1)
(DrawCel 900 0 2 nsLeft y2 -1)
(DrawCel 900 0 3 x2 y2 -1)
; Draw the text
(Display
text
dsCOORD
(+ nsLeft (>> (- w [rect rtRIGHT]) 1))
(+ (+ nsTop (>> (- h [rect rtBOTTOM]) 1)) 1 dsCOLOR)
gWndColor
dsBACKGROUND
clTRANSPARENT
dsFONT
font
dsWIDTH
[rect
rtRIGHT]
)
)
To go with the default custom button, we'll make the window silver.
Change: (= gWndBack clWHITE)
To: (= gWndBack clSILVER)
I think there is an issue with this. As I don't get the text on the actual buttons. (See screenshot)
I had to change the square brackets on this as it would not compile:
(= nsBottom (+ nsTop (| (& [rect rtBOTTOM] $FFFC) 7)))
(= nsRight (+ (| (& [rect rtRIGHT] $FFFC) 7) nsLeft))
-
Yeah I may have missed some things in editing.
I feel like the Display call may have broken in auto-translation. Here's a corrected version.
(Display
text
dsCOORD
(+ nsLeft (>> (- w [rect rtRIGHT]) 1))
(+ (+ nsTop (>> (- h [rect rtBOTTOM]) 1)) 1)
dsCOLOR gWndColor
dsBACKGROUND clTRANSPARENT
dsFONT font
dsWIDTH [rect rtRIGHT]
)
I think I'll go edit my first post to match.
-
Yeah I may have missed some things in editing.
Maybe you should have used AI to check for errors...
-
There is one last think I can see. On the right hand side its adding a thin grey line to the dialogue box. It only happens on certain box sizes.
See attachments:
-
This is by design, I think. The changes to setSize deliberately round up to the nearest multiple of eight so the border tiles fit.
Might be that said rounding is a little off. I wonder if that happens in SCI Studio, too?
-
That constantly happened to me during KQ2SCI and I elected to just ignore it as I never found a way around it. Mind you, that was years ago and in Studio Script and I just never bothered looking into it again. So yes, it definitely happened in SCI Studio too.
-
I'd ask if there might be a better way to do it but my math skills are lacking and it's already one of the more optimized ways to to round up to the nearest eight.
Might be why so many SCI10/11 games with custom borders just drew lines for the edges. In fact, that might be more efficient -- just use a highly simplified take on the BorderWindow to draw all this stuff instead of using views, and leave the size of things alone.
-
I never really liked Brian's custom GUI code because it draws all the cels inside the textbox instead of outside (like KQ1SCI does). I always meant to go back and try to rewrite it, especially now that we have the KQ1SCI decompiled source. Just another of those things in the long list of things I haven't gotten around to. That would also solve the rounding error that causes the extra space on the right side of the window. Because, as was said, depending on the size of the textbox it doesn't always draw the cel exactly to the edge of the window. I think some of this has to do with the cel widths honestly. It can't really predict properly somehow.
Interestingly, I think sometimes (again, depending on the size of the window), it actually cuts off the cell instead of giving it too much space.
-
I meant to add a link in my previous post to my blog post series about custom windows, but importantly, King's Quest 1 draws the edges as lines, with cels on the corners and a single cel as decoration on the top.
That's almost like how King's Quest 5 (https://helmet.kafuka.org/logopending/2019/02/18/on-sci-windows-part-3-kings-quest-5/), King's Quest 6 (https://helmet.kafuka.org/logopending/2019/02/19/on-sci-windows-part-4-kings-quest-6/), and Colonel's Bequest (https://helmet.kafuka.org/logopending/2019/02/21/on-sci-windows-part-nan-the-colonels-bequest/) draw their windows. Basically a bunch of lines for the edges and cels on the corners. And BorderWindows don't even have those. (https://helmet.kafuka.org/logopending/2019/02/18/on-sci-windows-part-2-borderwindow/)
(https://helmet.kafuka.org/logopending/wp-content/uploads/2019/02/sierra_056.png)
Yeah. You'd think those wooden planks were cels, but they're not.
-
Heh that's awesome. It's always neat to see how Sierra used the line-drawing features of SCI because it's not really that common I don't think. SQ4's Sequel Police laser shots is one really cool implementation.
-
How can you say it's "not that common" when the BorderWindow is used in every single one of these SCI10/11 games?
In general: SQ1, SQ4, SQ5, Brain1, PQ1, PQ3
Control window only: Longbow, Brain2, MUFT
Inventory window only: Eco2, Freddy, Brain2, LB2, LSL1, LSL5
Fifteen out of, what, twenty four?
You're not wrong about the Sequel Police though.
-
Well yes besides that. KQ6's was certainly unique though.
-
https://cacm.acm.org/blogs/blog-cacm/273577-ai-does-not-help-programmers/fulltext