Author Topic: Public Procedure for SetFlag etc  (Read 273 times)

0 Members and 1 Guest are viewing this topic.

Offline robbo007

Public Procedure for SetFlag etc
« on: May 09, 2025, 07:26:26 AM »
Hi guys,
I'm trying to get my head around how the SetFlag, TestFlag, ClearFlag and ToggleFlag procedures are working and used in Al's LSL3 source. I'm comparing this to the RE source by sluicebox.

First problem. If I define these procedures in my main.sc they don't seem to be working when I calling them in my rooms scripts, eg: (TestFlag 15). I have to add the procedure to the top of the room script in order for it to work. It does not seem to like being declared in the main.sc Do I have to declare them somewhere else if I want the room scripts to have access to them?

main.sc
Code: [Select]
(procedure (SetFlag flag)
(= [gFlagArray (/ flag 16)]
(| [gFlagArray (/ flag 16)] (>> $8000 (mod flag 16)))
)
)

(procedure (ClearFlag flag)
(= [gFlagArray (/ flag 16)]
(& [gFlagArray (/ flag 16)] (~ (>> $8000 (mod flag 16))))
)
)

(procedure (ToggleFlag flag) ; UNUSED
(= [gFlagArray (/ flag 16)]
(^ [gFlagArray (/ flag 16)] (>> $8000 (mod flag 16)))
)
)

(procedure (TestFlag flag)
(return
(if (& [gFlagArray (/ flag 16)] (>> $8000 (mod flag 16))) 1 else 0)
)
)

Second question: In Al's LSL3 source he declares the flagArray with enum's in the GAME.SH. I like the way he has defined enum names for these flags as it makes this easier to track when using something similar. Where is the best place to define these so they are accessible to all my rooms scripts? In the main.sc or in the SCI Companion's default template GAME.SH?

Code: [Select]
flagArray 111 ;** Access only from SetFlg, ClrFlg,
(enum ;** TglFlg and TstFlg Procedures.
logging ;** 111
loadDebugNext
showFrag
cantSave
preventAutoSave
noCursor
drankRiverWater
drankSinkWater
needsShower
seenPatti
needsSoap
scoredTan
lookedInMirror
sawAl&BillPoof
inQA
forceAtest

beenIn206 ;** 112
beenIn200
beenIn203
beenIn210
beenIn216
beenIn220
beenIn250
beenIn350
sawCredits200
sawCredits210
sawCredits213
sawCredits216
sawCredits220
sawCredits250
sawCredits253
sawCredits260

beenIn266 ;** 113
beenIn360
beenIn395
beenIn440
beenIn330
beenIn510
beenIn323
scoredTowel
scoredLocker
scoredSweats
scoredWater ;** filled the bottle with water
scoredDuckPoints
scoredCombination
scoredSuzi
passedSRcopyCheck
tippedMaitreD

seenCherri ;** 114
showerRunning
wetBody
lockerRippedOff
hadBambi
missedBambi
scoredOrchids
madeLei
seenDale
scoredDale
pickedPot
woreGrassSkirt
sprayedDeodorant
saidHiToTawni
needsDeodorant
usedElevator

seenJodiStrip ;** 115
gaveHead
beenIn480
tipsIn450
killedPorky
tookShortcut
missedKeycardPoints
seenBambi
pantyhoseOff
braLess
braLoaded
scoredBraLess
scoredBraLoaded
skippedLogRide
nextFlag
)

Thanks,



Offline Kawa

Re: Public Procedure for SetFlag etc
« Reply #1 on: May 09, 2025, 09:10:54 AM »
First, putting a procedure in Main.sc does not automatically make it available to other scripts. There should be a (public ...) block in Main.sc that lists the publically-available instances and procedures, like this:
Code: [Select]
(public
CatDate 0
Btst 1 ;<-- that's what my TestFlag et al are called.
Bset 2
Bclr 3
RestorePreviousHandsOn 4
StepOn 5
SetUpEgo 6
Score 7
; ...
)
The order doesn't matter, just don't have duplicate numbers and keep your main game instance as #0.

Now, any other script that has (use Main) can access these things.

For your second question, defining enumerations in Main.sc will not and can not make those enumerations available in other script files. Use Game.sh.

Offline robbo007

Re: Public Procedure for SetFlag etc
« Reply #2 on: May 11, 2025, 04:54:14 PM »
Amazing, thanks. :)


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

Page created in 0.047 seconds with 23 queries.