Author Topic: SCI0: Implementing bike riding system  (Read 203 times)

0 Members and 1 Guest are viewing this topic.

Offline robbo007

SCI0: Implementing bike riding system
« on: December 14, 2025, 01:40:57 PM »
Hi guys,
I'm trying to work out the best way to allow ego to ride a bike in certain rooms in the game. I'm trying to do it in a way that is optimised as not to screw with heapspace too much.

I want to archive the following:

Riding of bike in only allowed rooms
Using/initialising the bike view when changing between allowed rooms on the bike
Define control areas in allowed rooms that will make ego fall off bike and die

At present I'm using the following code in my main.sc where I'm using the OneOf procedure to block rooms where I don't want bike riding. It might be using up too much memory as my main.sc is pretty full already. Not sure if this is the best way?

This brings up other questions like, what's the best way to check if ego is on the bike and initialising it when switching between rooms where the bike is allowed? Because most rooms I have configured :(gEgo init: ) which will use my standard ego view.

I also wanted to have room specific control area where ego falls off the bike and dies if crossing. I'm not sure the best way to globally control these. I won't be able to use the same control colour for each room as some rooms would be already using that control colour for something else.

Code: [Select]
((Said 'use,mount/bike')
    ; Check if already on bike
    (if (== (gEgo view?) 719)
        (Print 0 163) ; "You're already on your bike."
        (return TRUE)
    )
   
    (cond
        ((not (gEgo has: 15))
            (Print 0 158) ;You don't have a bike.
        )
        ((OneOf gRoomNumber 6 7 8 11 14 15 16 17 18 19 29 21 22 24 30 31 33 35 36 39 40 41 42 43 44 45 46 47 48 50 51 52 53 55 56 90 91 92 93 94 95 97 98 100 101 102 103 104 111 120 121 122 123) ;rooms not allowed to ride bike
            (Print 0 159) ;Sorry, you can't ride your bike here.
        )
        (else
            (gEgo view: 719)
            (Print 0 160) ; You mount the bike.
        )
    )
    (return TRUE)
)

((Said 'dismount,(get<off)/bike')
    (if (== (gEgo view?) 719)
        (gEgo view: 0) ; Back to normal view
        (Print 0 161) ; You get off the bike and stuff it into your pocket.
    else 
        (Print 0 162) ; You're not riding anything.
    )
    (return TRUE)
)

Thanks,



Offline Kawa

Re: SCI0: Implementing bike riding system
« Reply #1 on: December 14, 2025, 02:23:29 PM »
Quote
what's the best way to check if ego is on the bike and initialising it when switching between rooms where the bike is allowed?
Flag if you care about space, entire global if you care about speed.

Offline lskovlun

Re: SCI0: Implementing bike riding system
« Reply #2 on: December 14, 2025, 02:27:18 PM »
You can use a Region for the bike-specific code.

Offline Cloudee1

Re: SCI0: Implementing bike riding system
« Reply #3 on: December 15, 2025, 01:09:24 AM »
If you are changing your global ego view variable, you are already good to go

When ego gets on the bike, set your ego view in the script, but also throw in a bit to reset the default... (= gDefaultEgoView 4)

Then in any subsequent rooms, you can just use your set up ego, and it will set ego to whatever view is set as default (SetUpEgo -1 0)

The trick is to change the default variable whenever you change the ego view for anything that persists between rooms
Halloween Competition Brass Lantern Prop Competition Groundhog Day Competition

Offline robbo007

Re: SCI0: Implementing bike riding system
« Reply #4 on: December 16, 2025, 12:01:08 PM »
Hey Cloudee1,
Welcome back :)

ok I think I've understood what you're suggesting. It seems to work fine. Does it look correct? When ego is mounted on the bike and changes rooms it maintains the bike view. When dismounted it uses the normal ego view.

The only thing left is to see when starting in a room with gPreviousRoomNumber if there is a way when using the bike view to automatically push the co-ordinates a little over, as the bike view is longer. So if there is a control line on the edge of the room he is going into it trips it and will force ego to go back into the room he came from. It would look crap if I manually edit these coordinates to take into account the new bike view size and make them further away from the edge of the screen, as when using the normal ego view he will look far away from the edge of the screen.

I might try regions as lskovlun mentioned, instead of using  OneOf gRoomNumber. Not sure which would use less memory?

Code: [Select]
((== gPreviousRoomNumber 005) (gEgo posn: 300 167 loop: 1)
)

I've added this to my main.sc

Code: [Select]

Code: [Select]
((Said 'use,mount,ride/bike')
    ; Check if already on bike using DEFAULT view
    (if (== gDefaultEgoView 719)  ; Use 719 view number for bike
        (Print 0 163) ; "You're already on your bike."
        (return TRUE)
    )
   
    (cond
        ((not (gEgo has: 15))
            (Print 0 158) ; "You don't have a bike."
        )
        ((OneOf gRoomNumber 6 7 8 11 14 15 16 17 18 19 29 21 22 24 30 31 33 35 36 39 40 41 42 43 44 45 46 47 48 50 51 52 53 55 56 90 91 92 93 94 95 97 98 100 101 102 103 104 111 120 121 122 123)
            (Print 0 159) ; "Sorry, you can't ride your bike here."
        )
        (else
            ; Change current view AND update persistent default
            (gEgo view: 719)  ; or 719 for bike view
            (= gDefaultEgoView 719)  ; <<< KEY: Set persistent default!
            (Print 0 160) ; "You mount the bike."
        )
    )
    (return TRUE)
)

((Said 'dismount,(get<off)/bike')
    (if (== gDefaultEgoView 719)  ; Check DEFAULT view, not current
        (gEgo view: 0)
        (= gDefaultEgoView 0)     ; <<< KEY: Reset persistent default!
        (Print 0 161) ; "You get off the bike and stuff it into your pocket."
    else 
        (Print 0 162) ; "You're not riding anything."
    )
    (return TRUE)
)

Code: [Select]
(procedure (SetUpEgo theLoop theView)
    (PlayerControl)
    (gEgo edgeHit: EDGE_NONE)
   
    ; Handle -1 parameters (use defaults)
    (if (== theLoop -1)
        (= theLoop (gEgo loop?))  ; Keep current loop
    )
    (if (== theView -1)
        (= theView gDefaultEgoView)  ; Use persistent default view!
    )
   
    (switch argc
        (0
            (SetUpActor gEgo (gEgo loop?) gDefaultEgoView)  ; Use default
        )
        (1
            (SetUpActor gEgo theLoop gDefaultEgoView)       ; Use default
        )
        (2
            (SetUpActor gEgo theLoop theView)              ; Use specified view
        )
    )
)

Offline lskovlun

Re: SCI0: Implementing bike riding system
« Reply #5 on: December 16, 2025, 12:06:52 PM »
Oh, regions are not instead of OneOf. It is a place to put your bicycle code, so that it does not use memory when you are in a non-bike room. A few bits and pieces will still need to be in Main.sc, but not much.


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

Page created in 0.04 seconds with 21 queries.