Author Topic: SCI0 - Custom buttons, windows and gauges  (Read 1440 times)

0 Members and 1 Guest are viewing this topic.

Offline robbo007

SCI0 - Custom buttons, windows and gauges
« 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


« Last Edit: May 29, 2023, 08:38:36 AM by robbo007 »



Offline Kawa

Re: SCI0 - Custom buttons, windows and gauges
« Reply #1 on: May 29, 2023, 08:40:22 AM »
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.
Code: [Select]
(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:
Code: [Select]
(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:
Code: [Select]
(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.
« Last Edit: May 30, 2023, 10:05:58 AM by Kawa »

Offline Collector

Re: SCI0 - Custom buttons, windows and gauges
« Reply #2 on: May 29, 2023, 09:53:38 AM »
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
KQII Remake Pic

Offline Kawa

Re: SCI0 - Custom buttons, windows and gauges
« Reply #3 on: May 29, 2023, 09:58:16 AM »
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.

Offline Collector

Re: SCI0 - Custom buttons, windows and gauges
« Reply #4 on: May 29, 2023, 10:01:19 AM »
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.
KQII Remake Pic

Offline robbo007

Re: SCI0 - Custom buttons, windows and gauges
« Reply #5 on: May 29, 2023, 10:22:58 AM »
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

Code: [Select]
(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!})
    )
  )
)

Offline Collector

Re: SCI0 - Custom buttons, windows and gauges
« Reply #6 on: May 29, 2023, 10:26:28 AM »
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.
KQII Remake Pic

Offline Kawa

Re: SCI0 - Custom buttons, windows and gauges
« Reply #7 on: May 29, 2023, 10:49:21 AM »
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
Code: [Select]
(= 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
Code: [Select]
(= noun UNSET) ; initialize it to 'nothing' before each parse
(if (Said '*/ground>')
(= noun GROUND_OBJ)
)

(if (Said '*/shovel>')
(= noun SHOVEL_OBJ)
)
and:
Code: [Select]
(= 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
Code: [Select]
(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?
Code: [Select]
;;; *************** 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)

Code: [Select]
;; 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':
Code: [Select]
(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
Code: [Select]
(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.
Code: [Select]
(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.

Offline Kawa

Re: SCI0 - Custom buttons, windows and gauges
« Reply #8 on: May 29, 2023, 06:50:40 PM »
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.

Offline robbo007

Re: SCI0 - Custom buttons, windows and gauges
« Reply #9 on: May 30, 2023, 09:53:50 AM »
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.
Code: [Select]
(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:
Code: [Select]
(= nsBottom (+ nsTop (| (& [rect rtBOTTOM] $FFFC) 7)))
(= nsRight (+ (| (& [rect rtRIGHT] $FFFC) 7) nsLeft))


Offline Kawa

Re: SCI0 - Custom buttons, windows and gauges
« Reply #10 on: May 30, 2023, 10:02:27 AM »
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.
Code: [Select]
(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.
« Last Edit: May 30, 2023, 10:09:47 AM by Kawa »

Offline AGKorson

Re: SCI0 - Custom buttons, windows and gauges
« Reply #11 on: May 30, 2023, 10:15:05 AM »
Yeah I may have missed some things in editing.

Maybe you should have used AI to check for errors...

Offline robbo007

Re: SCI0 - Custom buttons, windows and gauges
« Reply #12 on: June 08, 2023, 09:46:23 AM »
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:


Offline Kawa

Re: SCI0 - Custom buttons, windows and gauges
« Reply #13 on: June 08, 2023, 09:57:54 AM »
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?

Offline MusicallyInspired

Re: SCI0 - Custom buttons, windows and gauges
« Reply #14 on: June 11, 2023, 01:46:27 PM »
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.
Brass Lantern Prop Competition


SMF 2.0.19 | SMF © 2021, Simple Machines
Simple Audio Video Embedder

Page created in 0.033 seconds with 23 queries.