Author Topic: SCI0: Inventory  (Read 10521 times)

0 Members and 1 Guest are viewing this topic.

Offline robbo007

SCI0: Inventory
« on: February 03, 2023, 09:35:45 AM »
Hi everyone,
I'm trying to get my head around the different ways for picking up objects for the inventory and using control colours or coordinates.

I've seen in the LSL3 source they define a word (sorry don't know the correct terminology for it) which is then to detect if ego is on the control colour or not. If on the control colour ego can then pickup the object.

Code: [Select]
(define nearWood (& (ego onControl) cBrown))
Code: [Select]
(if (Said 'get/wood')
(cond
((!= egoState NORMAL)
(NotNow)
)
((not (InRoom iWood))
(Print "There is no wood lying around here.")
)
((not nearWood)
(Print "Move over until you are beside the small tree
with the gray trunk in the lower right-hand corner
of the scene.")
)
(else
(self changeState getIt)
)
)
)
)

Code: [Select]
;** Pick up the Wood

(getIt
(delay 0)
(= cycles 0)
(Ok)
(HandsOff)
(if (< (ego x) (aWood x))
(ego
illegalBits 0,
setMotion MoveTo (- (aWood x) stoopingOffsetX) (ego y) self,
)
else
(ego
illegalBits 0,
setMotion: MoveTo (+ (aWood x) stoopingOffsetX) (ego y) self,
)
)
)

(atIt
(ego
view vLstooping,
loop (> (ego x) (aWood x)),
cel 0,
cycleSpeed 1,
setCycle EndLoop self,
)
)

(DrBenDover
(aWood hide)
(ego
get iWood,
setCycle BegLoop self,
)
)

(getDone
(NormalEgo)
(theGame changeScore 2)
(Print "You take the beautiful chunk of granadilla wood
from beneath the tree.")
)
)
)
)

Brian's code is a little different as his examples are using co-ordinates and not colour controls.

Code: [Select]
(if(Said('take/key'))
  (if(send gEgo:has(INV_KEY))
    Print("You already have it!")
  )(else
    (if(send gEgo:inRect(150 150 170 170))
      Print("O.K.")
      (send gEgo:get(INV_KEY))
      (theKey:hide())
    )(else
      Print("You're not close enough!")
    )
  )
)

So my questions are which way is the better way to have Ego pickup an object? Using colour control or sending ego to coordinates? Maybe the Sierra way is a little more complex to start off than a basic check if ego is close to object and doe snot have it already, then pickup.

With regards to the Sierra source would this:

Code: [Select]
(define nearWood (& (ego onControl) cBrown))
Work like this:

Code: [Select]
(define nearWood (send gEgo:onControl()) ctlBROWN)



Offline Kawa

Re: SCI0: Inventory
« Reply #1 on: February 03, 2023, 09:53:39 AM »
The main question is a bit off, I think. What this code does is
1) check if you are anywhere near the piece of granadilla wood;
2) if you are, move into a more precise location so the pickup animation looks right.

Both methods to check if you're in range (inRect or onControl) are fine, really, and neither have anything to do with picking up inventory items specifically since it's also done for other kinds of interaction like looking at the plaque or using the binoculars. Or in this case picking up the onscreen representation of the granadilla wood, which is not the same as the inventory item.

Offline robbo007

Re: SCI0: Inventory
« Reply #2 on: February 03, 2023, 12:16:11 PM »
Both methods to check if you're in range (inRect or onControl) are fine, really, and neither have anything to do with picking up inventory items specifically since it's also done for other kinds of interaction like looking at the plaque or using the binoculars. Or in this case picking up the onscreen representation of the granadilla wood, which is not the same as the inventory item.

Ok thanks. Sorry I did not word my question correctly What I'm testing is first, detecting if ego is close enough to something and second to either look/use that object or to pickup the object so it appears in the inventory.

Using Brian's code I've tried converting to SCI for SciCompanion but I think Its missing something. I've defined INV_WOOD in the main.sc and game.sh Its also "initialised" with (Inv add: WOOD)

Code: [Select]
(if (Said('take/wood'))
(if (send gEgo:has(INV_WOOD))
(Print {You already have it!}))
(else
(if (send eEgo:InRect(150 150 170 170))
(Print {O.K})
(send gEgo:get(INV_WOOD))
(Wood:hide())
(else
(Print {You're not close enough!}
)
)
)

I think its best to stick with this code at present as my brain is melting also with the LSL3 examples trying to convert them for use with SCICompanion.


Offline Kawa

Re: SCI0: Inventory
« Reply #3 on: February 03, 2023, 12:26:20 PM »
Protip if you want to save yourself a headache in translating: don't use SCI Studio syntax, use what Companion calls Sierra syntax. It's much closer to the LSL3 code to begin with.

Offline Doan Sephim

Re: SCI0: Inventory
« Reply #4 on: February 03, 2023, 02:57:14 PM »
What I'm testing is first, detecting if ego is close enough to something and second to either look/use that object or to pickup the object so it appears in the inventory.
I write it something like this:
Code: [Select]
(if(Said 'take,(pick<up)/mushroom')
(if (not (gEgo has: INV_MUSHROOM))
(if (<= (gEgo distanceTo: mushroom) 30)
(gEgo get: INV_MUSHROOM)
else
(PrintNotCloseEnough)
)
else
(PrintAlreadyTookIt)
)
)

Offline Kawa

Re: SCI0: Inventory
« Reply #5 on: February 03, 2023, 03:06:29 PM »
So no fancy pickup animation for you?

Offline Doan Sephim

Re: SCI0: Inventory
« Reply #6 on: February 04, 2023, 04:15:45 PM »
So no fancy pickup animation for you?
Sometimes I have an animation that goes with it  ;D

Offline robbo007

Re: SCI0: Inventory
« Reply #7 on: February 06, 2023, 09:14:50 AM »
Thanks @Doan Sephim That worked perfectly :) I think it will have to do until I work out the SCI code below adding a pick animation. I was trying to hide the item when picked up and managed to hide ego. haha I haven't worked out how to hide the view once picked up into inventory.

Code: [Select]
(if(Said 'take,(pick<up)/wood')
(if (not (gEgo has: INV_WOOD))
(if (<= (gEgo distanceTo: aWood) 20)
(gEgo get:INV_WOOD)
(gGame changeScore: 3)
(Print {You take the beautiful chunk of granadilla wood.})
else
(PrintNotCloseEnough)
)
else
(PrintAlreadyTookIt)
)
)

What I'm testing is first, detecting if ego is close enough to something and second to either look/use that object or to pickup the object so it appears in the inventory.
I write it something like this:
Code: [Select]
(if(Said 'take,(pick<up)/mushroom')
(if (not (gEgo has: INV_MUSHROOM))
(if (<= (gEgo distanceTo: mushroom) 30)
(gEgo get: INV_MUSHROOM)
else
(PrintNotCloseEnough)
)
else
(PrintAlreadyTookIt)
)
)

@kawa So to add the Dr Ben Dover (as Al Lowe puts it) script to the pickup item I see the LSL3 code gets quite complex and needs possible converting to SC?

First they define the name. That code does not work in SCICompanion. Guess it needs changing the syntax around?
Code: [Select]
(define nearWood (& (ego onControl) cBrown))
Then I see they add room state values??? Some are used for the picking up of the wood. Those seem to work in SC.

Code: [Select]
(enum ;** RoomScript state values
intro
learnThePlot
readMsg2
plotDone
getIt
atIt
DrBenDover
getDone
)

Is this a check to see if ego has done something first before the wood view is displayed or taken the wood already? Seems to define a "InRoom"  to do with the wood. Not sure that the InRoom does?

Code: [Select]
(if (InRoom iWood)
(Load VIEW vLstooping)
(aWood init)
)
(method (handleEvent event &tmp i)
(if (and (not (super handleEvent: event))
(not (event claimed))
modelessDialog
(== (event message) ENTER)
(== (event type) keyDown))
(event claimed TRUE)
(cls)
(self cue)
)

(if (or (!= (event type) saidEvent) (event claimed)) (return))

(if (Said 'look>')
(if (Said '/tree')
(Printf "The granadilla is short and graceful,
with a gray trunk, and delicately spreading branches.%s"
(if (InRoom iWood)
{ Beneath its outstretched boughs lies a beautiful
piece of wood, probably cut by a native then forgotten.}
else
{}
)
)
)

(if (and (InRoom iWood)
(Said '/stick, wood'))
(Print "Beneath the granadilla lies a beautiful piece of wood.")
)

(if (Said '[/room]')
(Print "The native corporation (Natives, Inc.) has done an
excellent job of preserving the environment of the jungle,
at least in this location!
A beautiful, specimen granadilla tree grows here.")
)
)

(if (Said 'get/wood')
(cond
((!= egoState NORMAL)
(NotNow)
)
((not (InRoom iWood))
(Print "There is no wood lying around here.")
)
((not nearWood)
(Print "Move over until you are beside the small tree
with the gray trunk in the lower right-hand corner
of the scene.")
)
(else
(self changeState getIt)
)
)
)
)


(method (changeState newState)
(switch (= state newState)

(intro
(cond
((not (TstFlg beenIn210))
(= cycles 30)
)
((not (TstFlg beenIn216))
(= cycles 20)
(++ state)
)
)

Then the actual pickup animation is run? It moves the ego into position to then pickup right? SetMotion MoveTo the defined view aWood.

Code: [Select]
;** Pick up the Wood

(getIt
(delay 0)
(= cycles 0)
(Ok)
(HandsOff)
(if (< (ego x) (aWood x))
(ego
illegalBits 0,
setMotion MoveTo (- (aWood x) stoopingOffsetX) (ego y) self,
)
else
(ego
illegalBits 0,
setMotion: MoveTo (+ (aWood x) stoopingOffsetX) (ego y) self,
)
)
)

(atIt
(ego
view vLstooping,
loop (> (ego x) (aWood x)),
cel 0,
cycleSpeed 1,
setCycle EndLoop self,
)
)

(DrBenDover
(aWood hide)
(ego
get iWood,
setCycle BegLoop self,
)
)

(getDone
(NormalEgo)
(theGame changeScore 2)
(Print "You take the beautiful chunk of granadilla wood
from beneath the tree.")
)
)
)
)


....mind starts to melt..

Offline Kawa

Re: SCI0: Inventory
« Reply #8 on: February 06, 2023, 09:53:17 AM »
1. (define nearWood (& (ego onControl) cBrown)) doesn't work in SCI Companion because it, as opposed to Sierra's in-house compiler, can only handle single values. So wherever you see nearWood in the code later on, you must substitute in (& (ego onControl) cBrown) yourself.

2. Enums are fine, yeah, but this part is really just confusing the matter because of the whole "dissolving credits" and "plot explanation popup" thing. I suggest you ignore it. They are, in the end, just names for numbers of increasing value.

3. InRoom is a function from the Main script to save effort in determining if a specific inventory item has the current room set as its owner. Note that inventory items do not visually appear in their owner rooms. It's aWood that visually represents the granadilla when you haven't picked it up yet. So if InRoom says the granadilla is still in this jungle path, it knows to A) preload the animation of Larry picking it up so that GET WOOD doesn't cause a sudden load delay, and B) initialize aWood, making it appear.

4. When you type GET WOOD, it first checks if you're close enough (nearWood comes in here) and if so, sets the room script's state to getIt (4).
4.1. The room script, when it reaches that state (which can only happen when you try to take the wood because state 3 halts at the end) will take away your controls and tell Larry to move into position in an intricate way to allow him to take the wood from either the left or right. Larry, that is ego, will call back to the room script (self) when he's there, causing state 5, atIt to run.
4.2. Larry is told to play the stooping animation, facing the right way, and call back again. This causes the room script to reach state 6, DrBenDover.
4.3. aWood is hidden from view and the stooping animation is played in reverse. Finishing this animation causes the script to reach its final state, getDone.
4.4. "You take the beautiful chunk of granadilla wood from beneath the tree." and get two points. Reset Larry to normal operation with the NormalEgo function from the main script, which also restores user control.




Here's an example from my own game, in SCI 1.1+.
Code: [Select]
(instance aPuddle of cdFeature
;...
(verbs
(V_LOOK
; some irrelevant stuff to either say one thing or the other depending on you having checked the puddle up close.
(V_DO
(if (Btst fDayOnePuddleChecked)
; say you've already done that.
else
(Bset fDayOnePuddleChecked) ; remember having checked the puddle.
(curRoom setScript: InspectPuddleScript)
)
)
)
)
This part is analogous to said checks in your room script's handleEvent. If we clicked the hand cursor on the puddle and haven't done so before, set the room's script to InspectPuddleScript/tt]. This is unlike what the jungle path in LSL3 did, having a single script for both the credits and plot, and picking up the granadilla wood.

Code: [Select]
(instance InspectPuddleScript of Script
(method (changeState newState)
(switchto (= state newState)
(
(HandsOff)
(ego setMotion: PolyPath 100 160 self)
)
(
(ego view: vSpecific loop: lTastePuddle cel: 0 setCycle: EndLoop self)
)
(
(Score 20)
; "Yup, that's water alright. Which can mean only one thing!"
)
(
(ego cel: cCrouched setCycle: BegLoop self)
)
(
(ego view: 0 loop: 8 cel: 1 resetCycler:)
; Warning: I'm not too sure if this is correct.
(curRoom setScript: RoomScript)
)
)
)
)
Basically, we make a little cutscene. Take away the player's control so we can't horribly break everything, then have our main character smartly move over next to the puddle. We don't do anything like Larry taking the wood from either direction, we always lick it from the right.
« Last Edit: February 06, 2023, 10:04:51 AM by Kawa »

Offline robbo007

Re: SCI0: Inventory
« Reply #9 on: February 08, 2023, 12:27:51 PM »
Thanks Kawa. Its clearer now. It will take me a while to work out how to implement the Dr Ben Dover stuff to my room as I'll have to start converting it to SC syntax with trial an error. For now my mile stone was I finally worked out how to hide the darn wood (view) once picked up. Took me a while to get it. Wohoooooo

I needed to add
Code: [Select]
(aWood hide:) to the code that Doan Sephim posted earlier.

Code: [Select]
(if(Said 'take,(pick<up)/wood')
(if (not (gEgo has: INV_WOOD))
(if (<= (gEgo distanceTo: aWood) 20)
(gEgo get:INV_WOOD)
(aWood hide:)
(gGame changeScore: 3)
(Print {You take the beautiful chunk of granadilla wood.})
else
(PrintNotCloseEnough)
)
else
(PrintAlreadyTookIt)
)
)


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

Page created in 0.042 seconds with 21 queries.