Author Topic: SC0 vRoom view  (Read 12869 times)

0 Members and 4 Guests are viewing this topic.

Offline robbo007

SC0 vRoom view
« on: January 26, 2023, 09:34:22 AM »
Hi guys,
I'm trying to work out how to add animated views to my pics. I'm testing with a portion of LSL3 code from the room and the casino fountain view.

I've declared at the start of my script the vRoom:
Code: [Select]
(define vRoom 250)
(define lWaterfall 0)

And at the end of my Instance RoomScript of Script this code:

Code: [Select]
(instance aFountain of Script
(properties
view vRoom
loop lWaterfall
x 194
y 148
cycleSpeed 1
)

(method (init)
(super init)
(self
isExtra TRUE,
setCycle Forward,
setPri 11,
)
)
)
) ;End Method
) ;End Instance

I'm getting an expected an expression error. Is this the correct way to add animated views to pics? Sorry for my basic questions.
Regards,



Offline Kawa

Re: SC0 vRoom view
« Reply #1 on: January 26, 2023, 09:45:39 AM »
You're trying to use a Script when you mean to use a Prop, like it says in the LSL3 code you're copying.

Offline robbo007

Re: SC0 vRoom view
« Reply #2 on: January 26, 2023, 09:51:59 AM »
You're trying to use a Script when you mean to use a Prop, like it says in the LSL3 code you're copying.

Sorry your right there. I had it as a Prop but was testing to see if that was the error. It still errors though.

Code: [Select]
(instance aFountain of Prop
(properties
view vRoom
loop lWaterfall
x 194
y 148
cycleSpeed 1
)

(method (init)
(super init)
(self
isExtra TRUE,
setCycle Forward,
setPri 11,
)
)
)
) ;End Method
) ;End Instance

Offline Kawa

Re: SC0 vRoom view
« Reply #3 on: January 26, 2023, 09:55:35 AM »
Your next error is that, going by the indentation, you have way too many closing parens:
Code: [Select]
)
)
)
) ;End Method
) ;End Instance
End which method and instance exactly? Are you trying to put the fountain instance inside of the roomscript instance? Cos that won't work!

Offline robbo007

Re: SC0 vRoom view
« Reply #4 on: January 26, 2023, 10:05:06 AM »
I've placed it after the room script instance.

Code: [Select]
;;; Sierra Script 1.0 - (do not remove this comment)
;
; SCI Template Game
; By Brian Provinciano
; ******************************************************************************
; rm001.sc
; Contains the first room of your game.
(script# 1)
(include sci.sh)
(include game.sh)
(use main)
(use controls)
(use cycle)
(use game)
(use feature)
(use obj)
(use inv)
(use door)
(use jump)
(use dpath)

(public
rm001 0
)

(define vRoom 250)
(define lWaterfall 0)


(instance rm001 of Rm
(properties
picture 201
; Set up the rooms to go to/come from here
north 0
east 002
south 0
west 0
)

(method (init)
; same in every script, starts things up
(super init:)
(self setScript: RoomScript)
; Check which room ego came from and position it
(switch gPreviousRoomNumber
;
;             * Put the cases here for the rooms ego can come from *
;
;            (case north
(send gEgo:
posn(210 110)
loop(2)
)
)
; Set up ego's position if it hasn't come from any room
(else
(gEgo posn: 150 130 loop: 1)
)
)
; Set up the ego
(SetUpEgo)
(gEgo init:)
)
)

;
;         * Set up the room's music to play here *

;;; (send gTheMusic:
;;; prevSignal(0)
;;; stop()
;;; number(scriptNumber)
;;; loop(-1)
;;; play()
;;; )

;         * Add the rest of your initialization stuff here *


(instance RoomScript of Script
(properties)

(method (handleEvent pEvent)
(super handleEvent: pEvent)
;
;         * Handle the possible said phrases here *
(if (Said 'look>')
  (if (Said '/plaque')
    (Print {Oh no. test.})
      (gGame changeScore: 3) ; Will add 3 to the players current score
  else
    (if (Said '/ocean, beach, point, lagoon, bay, water')
      (Print 1 2)(Print 1 2)
      ;(Print {From up here the polluted lagoon looks even more polluted than you remember. Hey surfs up though})
  else   
       (if (Said '/grass, ground, sidewalk')
      (Print {grass})
    else   
       (if (Said '/rail, railing, fence')
      (Print {fence.})
    else
    (if (Said '[ /* , !* ]')
        (Print {look room reponse})
      )
    )
  )
)
(if (Said 'laugh>')
(Print {hahahaha})
)
) ;End Method
) ;End Instance

; Cond version
(if (Said 'look>')
  (cond
    ((Said 'plaque')
      (Print {plaque response})
    )
    ((Said '/water')
      (Print {water response})
    )
     ((Said '/grass')
(Print {grass response})
)
    ((Said 'rail')
      (Print {rail response})
    )
    ((Said '[ /* , !* ]')
      (Print {hello world})
    )
  )
)

) ;End Method
) ;End Instance

(instance aFountain of Prop
(properties
view vRoom
loop lWaterfall
x 194
y 148
cycleSpeed 1
)

(method (init)
(super init)
(self
isExtra TRUE,
setCycle Forward,
setPri 11,
)
)
)

Offline Kawa

Re: SC0 vRoom view
« Reply #5 on: January 26, 2023, 10:24:26 AM »
I reformatted things a bit. Removed some comments for clarity, added my own.
Please read my comments carefully.

Code: [Select]
;;; Sierra Script 1.0 - (do not remove this comment)
(script# 1)
(include sci.sh)
(include game.sh)
(use main)
(use controls)
(use cycle)
(use game)
(use feature)
(use obj)
(use inv)
(use door)
(use jump)
(use dpath)

(public
rm001 0
)

(define vRoom 250)
(define lWaterfall 0)

(instance rm001 of Rm
(properties
picture 201
north 0
east 002
south 0
west 0
)

(method (init)
(super init:)
(self setScript: RoomScript)
(switch gPreviousRoomNumber
(else
(gEgo posn: 150 130 loop: 1)
)
)
; Set up the ego
(SetUpEgo)
(gEgo init:)

; KAWA: This entire block *REALLY* should stay inside of rm001::init
; even though it's commented out, or you're gonna get messy indents
; again, or WORSE.
;;; (send gTheMusic:
;;; prevSignal(0)
;;; stop()
;;; number(scriptNumber)
;;; loop(-1)
;;; play()
;;; )

)
)

(instance RoomScript of Script
(properties)

(method (handleEvent pEvent)
(super handleEvent: pEvent)

(if (Said 'look>')
(if (Said '/plaque')
(Print {Oh no. test.})
(gGame changeScore: 3)
else
(if (Said '/ocean, beach, point, lagoon, bay, water')
(Print 1 2)
(Print 1 2)
else
(if (Said '/grass, ground, sidewalk')
(Print {grass})
else   
(if (Said '/rail, railing, fence')
(Print {fence.})
else
(if (Said '[ /* , !* ]')
(Print {look room reponse})
)
)
)
)
(if (Said 'laugh>')
(Print {hahahaha})
)

; KAWA: OKAY this is bad. Your if-else chain seems to be so messy it caused an inbalance!
; I HIGHLY suggest tossing that and keeping the Cond version below.
) ;End Method
) ;End Instance

; Cond version
(if (Said 'look>')
(cond
((Said 'plaque')
(Print {plaque response})
)
((Said '/water')
(Print {water response})
)
((Said '/grass')
(Print {grass response})
)
((Said 'rail')
(Print {rail response})
)
((Said '[ /* , !* ]')
(Print {hello world})
)
)
)

; KAWA: Because you have both an (inbalanced) If-Else version AND a Cond version,
; both ending in "end method, end instance" lines, you're effectively trying to
; end the method and instance TWICE.
) ;End Method
) ;End Instance

(instance aFountain of Prop
(properties
view vRoom
loop lWaterfall
x 194
y 148
cycleSpeed 1
)

(method (init)
(super init)
(self
isExtra TRUE,
setCycle Forward,
setPri 11,
)
)
)

; KAWA: Missing a ) to end the fountain instance.

Readability is key.

Offline robbo007

Re: SC0 vRoom view
« Reply #6 on: January 26, 2023, 12:29:36 PM »
Thanks for that. Helps get my head around this. So should every instance be treated like a separately inside the script? IE should I close each instance before opening another or close all the instances at the end of the file?

I've played around with the code and removed the else statements and only used condition. Much better. I've removed the double ending of instance and methods also. That all compiles fine until I add at the end the prop statement. I think I have the closing brackets correct?

Code: [Select]
;;; Sierra Script 1.0 - (do not remove this comment)
(script# 1)
(include sci.sh)
(include game.sh)
(use main)
(use controls)
(use cycle)
(use game)
(use feature)
(use obj)
(use inv)
(use door)
(use jump)
(use dpath)

(public
rm001 0
)

(define vRoom 350)
(define lWaterfall 0)

(instance rm001 of Rm
(properties
picture 201
north 0
east 002
south 0
west 0
)

(method (init)
(super init:)
(self setScript: RoomScript)
(switch gPreviousRoomNumber
(else
(gEgo posn: 150 130 loop: 1)
)
)
; Set up the ego
(SetUpEgo)
(gEgo init:)
)
)
;
;         * Set up the room's music to play here *

;;; (send gTheMusic:
;;; prevSignal(0)
;;; stop()
;;; number(scriptNumber)
;;; loop(-1)
;;; play()
;;; )

;         * Add the rest of your initialization stuff here *

; KAWA: This entire block *REALLY* should stay inside of rm001::init
; even though it's commented out, or you're gonna get messy indents
; again, or WORSE.

(instance RoomScript of Script
(properties)

(method (handleEvent pEvent)
(super handleEvent: pEvent)

; Cond version
(if (Said 'look>')
(cond
((Said '/plaque')
(Print {plaque response})
)
((Said '/water')
(Print {water response})
)
((Said '/grass')
(Print {grass response})
)
((Said '/rail')
(Print {rail response})
)
((Said '[ /* , !* ]')
(Print {hello world})
)
)
)
) ;End Method
) ;End Instance
(instance aFountain of Prop
(properties
view vRoom
loop lWaterfall
x 194
y 148
cycleSpeed 1
)

(method (init)
(super init)
(self
isExtra TRUE,
setCycle Forward,
setPri 11,
)
)
)

Offline Kawa

Re: SC0 vRoom view
« Reply #7 on: January 26, 2023, 12:44:30 PM »
Syntax error, a slight difference between the original Sierra code at the time and what Companion uses.
Code: [Select]
(method (init)
(super init:)
(self
isExtra: TRUE
setCycle: Forward
setPri: 11
)
)
Later Sierra games (LSL1 and 5 for example) used colon-comma syntax, so (self isExtra: TRUE, setCycle: Forward, setPri: 11,). If you leave out that last comma, Companion will accept that, too.

Offline robbo007

Re: SC0 vRoom view
« Reply #8 on: January 27, 2023, 04:38:19 AM »
Deeper I go down that rabbit hole :) So that now compiles, amazing. I need to start documenting all this. So I don't forget.

With regards to a vRoom. Am I right in saying that (define vRoom 350) and (define lWaterfall 4) means use view.350, loop number 4 and define it as "lWaterfull" variable for use later on in the script.

Quote
(define   vRoom         350)
   (define   lWaterfall   4)

And this part below uses the previous defined variable "lWaterfall" and places the view.305 file at the coordinates indicated? Do I need to define a priority colour/area on the room picture I'm using? Reason being is the waterfall view.350 is not displayed on my defined room pic after recompiling everything and running the game.

Code: [Select]
(instance aFountain of Prop
(properties
view vRoom
loop lWaterfall
x 235
y 121
cycleSpeed 1
)

(method (init)
(super init:)
(self
isExtra: TRUE
; setCycle: Not sure what value to put here as "forward" does not work.
setPri: 11
)
)
)



Offline Kawa

Re: SC0 vRoom view
« Reply #9 on: January 27, 2023, 04:48:02 AM »
1. It's not a variable. Once you've defined vRoom to mean 350, that will last throughout the file and can't be changed later down the file.
2. A view resource should not be confused with a View instance, of which Prop, Actor, and Ego are subtypes.
3. It's not appearing because rm001::init doesn't call (aFountain init:). Put that right after (gEgo init:).

Offline robbo007

Re: SC0 vRoom view
« Reply #10 on: January 27, 2023, 09:36:47 AM »
ok thanks. Understood.

After playing a bit more I change the code to the following. The SetCycle Forward needed to be Fwd and I had to remove the isExtra TRUE to get the animation of the loop working. Yayeee

Code: [Select]
(method (init)
(super init:)
(self
setCycle: Fwd
setPri: 11
)

Is there any documentation with the parameters that can be used for "Set" stuff like SetCycle etc

Offline Kawa

Re: SC0 vRoom view
« Reply #11 on: January 27, 2023, 10:00:37 AM »
Forward didn't work because the class names were changed for space saving reasons:
Code: [Select]
(class Forward of Cycle
(properties
name {Fwd}
This lets you use "Forward" in your source code, but the final game data will store the shorter "Fwd". And since the templates were made from decompiling that final game data...

Now, the SCI0 template has no useful documentation in the script files themselves but it works much the same in the other versions so I can just quote SCI11:
Quote
Sets a cycler object on the Prop, optionally supplying initialization parameters for the cycler.

Example usage for telling a Prop to cycle forward: (theFrog setCycle: Forward)
Example usage for telling a Prop to cycle to the end, then cue its caller: (theFrog setCycle: EndLoop self)

theCycler: A class derived from class Cycle, or null to remove the current cycler.

How that works internally is that the Prop (or Actor, Ego, or anything else that's a kind of Prop) keeps track of another object, a Cycler, to help animate the Prop. The Cycler in turn has a reference back to the Prop so it knows whose cel property to change. Then, every time the Prop updates, it knows to update its respective Cycler, which in turn changes its client Prop's cels accordingly.

Cyclers in the SCI 0 system scripts include:
Fwd or Forward: just goes through all cels in the current loop in ascending order, then repeats.
Rev or Reverse: like Forward but counts in reverse.
End or EndLoop: goes through all cels in ascending order, then calls back and stops.
Beg or BegLoop: guess.
CT or CycleTo: goes from the current cel to the specified one, then calls back and stops.
Walk: like Forward but only updates when the client moves.

And of course Cycler itself, which you shouldn't use -- it's the base class for the above-listed.

Similar things apply to the SetMotion method and Motion classes, affecting position instead of cel over time.

Offline robbo007

Re: SC0 vRoom view
« Reply #12 on: April 20, 2023, 09:49:05 AM »
Sorry to bring this old topic up. I'm trying to get a wave view working on my beach scene. I was trying different cyclers to get a more realistic effect but still looks a little unnatural.

Is there another way to make a view more random when cycling through its cels or stopping and starting?
Thanks,

Offline Kawa

Re: SC0 vRoom view
« Reply #13 on: April 20, 2023, 10:07:52 AM »
I have a similar thing in my own game, actually. I didn't feel it warranted a completely new cycler or looper, so I just did it in-place.

This is SCI 1.1 code but it should work fine in 0.x. I changed it up a bit to not use the Oscillator cycler, cos that's not in 0.x though it can be backported.
Code: [Select]
(instance theSurf of Prop
  (properties
    view vSurf
    loop 0
    cel 0
    x 160
    y 170
  )

  (method (init)
    (super init:)
    (self
      setPri: 1
      setScript: surfScript
      stopUpd:
    )
  )
)

(instance surfScript of Script
  (method (changeState newState)
    (switchto (= state newState)
      (
        (theSurf stopUpd:)
        ; Wait for 2 to 6 seconds...
        (= seconds (+ 1 (* (Random 0 3) 2)))
      )
      (
        ; Setting a cycler automatically restarts updating.
        (theSurf setCycle: Fwd self)
      )
      (
        (theSurf setCycle: Rev self)
      )
      (
        ; Repeat.
        (self changeState: 0)
        ; A better way might be to (= state -1) (= cycles 1) but nyehh.
      )
    )
  )
)
This uses stopUpd to prevent the surf's screen-spanning view from causing cursor flickering while it's not waving.
One thing you might consider is to also randomly change the prop's cycleSpeed so sometimes you get slow waves and sometimes faster.


You might also want to look into for example King's Quest 5, room 45 and its waves script.

Offline robbo007

Re: SC0 vRoom view
« Reply #14 on: April 21, 2023, 10:15:43 AM »
That works really well. Thanks. I gather I could use something similar when needed to "randomise" actors (NPCs) walking around or other types of views.


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

Page created in 0.045 seconds with 22 queries.