Author Topic: SCI0: Events claimed Flags etc  (Read 1560 times)

0 Members and 1 Guest are viewing this topic.

Offline robbo007

SCI0: Events claimed Flags etc
« on: July 31, 2024, 06:33:36 PM »
Hi guys,
Could someone help out and shed some light on how flags and claimed events work? I'm trying to have a changestate run once in a room. When ego walks back into the room I don't want the changestate to run again. I was trying to copy the LSL3 source using a flag procedure but its not working.

Code: [Select]
(procedure (SetFlag flag)
(= [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)
)
)

Code: [Select]
(if (not (TestFlag 20))
(aTaxi init:)
)

Code: [Select]
(method (changeState newState)
    (switch (= state newState)
(0
(ProgramControl) ;hands off
(= seconds 5) ; wait 10 seconds
(Print {"A year later...})
)
(1
(Print {"Seeya round buddy", shouts the taxi driver.})
(client
illegalBits: 0
cycleSpeed: 0
setLoop: -1
setCycle: Rev
setMotion: MoveTo -52 97 self
)
(PlayerControl) ;hands on
(SetFlag 20)
)
)
)
)

Thanks :)



Offline mnicolella

Re: SCI0: Events claimed Flags etc
« Reply #1 on: July 31, 2024, 06:45:38 PM »
What does the code look like that you're trying to copy?

If gFlagArray is an int array, then each element of the array is a 16bit integer

So dividing the flag index by 16 looks correct for accessing the element of the flag array, and then mod'ing the flag index by 16 looks correct for accessing the index of the flag inside the 16-bit block

How is your gFlagArray initialized? What 'isnt working' about this?

Offline lskovlun

Re: SCI0: Events claimed Flags etc
« Reply #2 on: July 31, 2024, 10:06:31 PM »
Okay, so assuming that aTaxi here
Code: [Select]
(if (not (TestFlag 20))
(aTaxi init:)
)
refers to a view, that will only cause the view to not appear. What you need to do is find the setScript: call that activates your script (which you don't name) and put the test there.

Offline robbo007

Re: SCI0: Events claimed Flags etc
« Reply #3 on: August 03, 2024, 07:20:09 AM »
Here is the full taxi script:

Code: [Select]
(instance aTaxi of Act
(properties
view 607
x 9
y 97
loop 0
)

(method (init)
(super init:)
(self
setPri: 6
;setCycle: End
setScript: aTaxiScript
cycleSpeed: 4
;stopUpd:
)
)
)

(instance aTaxiScript of Script ;
  (method (handleEvent pEvent)
  (super handleEvent: pEvent)
 )
  (method (changeState newState)
    (switch (= state newState)
(0
(ProgramControl) ;hands off
(= seconds 5) ; wait 10 seconds
(Print {"A year later...})
)
(1
(Print {"Seeya round buddy", shouts the taxi driver.})
(client
illegalBits: 0
cycleSpeed: 0
setLoop: -1
setCycle: Rev
setMotion: MoveTo -52 97 self
)
(PlayerControl) ;hands on
(SetFlag 20)
)

)
)
)

So what I was trying to do with the setflag procedure was if not detected flag 20 (eg the changestate has not been run yet and the flag was not set)  then init the taxi. If the changestate has been run and the flag has been set then don't init the taxi.

Maybe there is a better way to do this? I was copying the setflag and testflag from some of the rooms in LSL3. I've also seen event claimed when using SAID but not sure if that can be used to control if a changestate like my taxi script has been run or not?
Regards,

Offline lskovlun

Re: SCI0: Events claimed Flags etc
« Reply #4 on: August 03, 2024, 10:18:54 PM »
Well, that explains my confusion. You're following modern conventions in OOP, which I guess is fine - it's just not what Sierra would do. Sierra's View instances rarely override their constructors - they generally put that code in the Room init. But OK then. I'm still having trouble understanding what events and claiming have to do with it. Yes, calling Said and having it succeed does claim the event (this helps to speed up the main game loop).

So maybe just do as Sierra usually did?

Offline robbo007

Re: SCI0: Events claimed Flags etc
« Reply #5 on: August 11, 2024, 04:58:12 PM »
I think I was trying to use the events and flags for something that could easily be achieved with less hassle. I managed to do the following:

Code: [Select]
(if (== gPreviousRoomNumber 976)
(aTaxi init:)
else(aTaxi hide:)
)

This only runs the intro taxi sequence when coming from the Initroom at the start of the game.

I still don't understand how events claimed work or how to use flags and where to use all this.

Offline deckarep

Re: SCI0: Events claimed Flags etc
« Reply #6 on: August 21, 2024, 07:38:30 PM »
Hello,

For the event system:

The event system is designed in such a way that an event object is fired from the end-user such as a mouse click. This will get filled out with information indicating the type of event and additionally indicating some other data such as x/y coordinates.

When an event is fired, it's passed into the game giving many objects a chance to handle it. If for example, an object has handled it then it would set the claimed property to a 1 otherwise claimed remains zero and the event is further propagated or bubbled further and further down the "event handling" hierarchy. If you have handled the event, and you have set claimed to 1, then the event no longer needs to propagate down to each component of your game and basically has been used up.

For the flags:

The SCI code has a few procedures for setting, getting and testing flags. Every game has some number of global fags which are actually represented as packed bits. You the programmer can think of them as either on or off, true or false, yes or no, etc. But, internally it's just a single bit that gets enabled or disabled accordingly. The flags are a very compact way to represent some boolean state for your game. Since memory was precious back then, the flags system was written in a way to keep memory usage to a bare minimum.

This may have changed across versions of SCI but SCI allowed up to 128 flags stored within 8 16-bit global vars. This means that the flags are truly to global to your game and available everywhere. Also, it means only 8 16-bit slots are needed to store 128 flags.

As you can see having the ability to have 128 flags for your use only takes up 8 global slots. But, this means you need to use the flags API correctly and the way you do this is by using the define keyword to create a flag name. Something like: fRadioPlaying

So you would do something like: define fRadioPlaying 0 (the 0th flag) This just defines the flag.
Then you can turn on the radio like: setFlag(fRadioPlaying) // This enables the flag.
You can turn it off like: clearFlag(fRadioPlaying) // This disables or clears the flag.
You can toggle itlike: toggleFlag(fRadioPlaying) // This just flips the flag from whatever it's currently set to.
You can also check if some defined constant is a flag: isFlag(fRadioPlaying) // This tells you if it's a flag or not (declared in the range of one of the 8 global 16-bit vars)


Offline Charles

Re: SCI0: Events claimed Flags etc
« Reply #7 on: August 22, 2024, 09:07:07 PM »
If it helps to see things a bit more visually, I made this quick infographic.


This show a hypothetical four global variables (in an 8-bit system, like SCI0) with their values in them. Each of the Decimal, of Hexadecimal, or Binary is the exact same value, just how it's represented in each of those number formats.

I think it's very easy to get the concept of a single variable. At it's simplest, you give it a name and you can put a number in there that you can refer to later or change or whatever.

The concept of a "flag" in SCI or programming in general is just that: a concept. It has no special construct in and of itself. It's just means a variable that is only ever binary. On/off, yes/no (or more commonly true/false i.e. 1/0). Kinda like a mailbox flag... it's either up or it's not.

You could use a full variable for your 1/0 value, but because each variable is really made up of bunch of bits, and memory space is oh so very precious, why not use each of those bits individually. That gives you 8 times as many yes/no variables (on an 8-bit system like SCI0, or 16 times as many yes/no's on a 16-bit system like SCI1).

The bitwise functions BTst, BSet, BClr do all the legwork to figure out which specific bit in which specific variable to manipulate, but essentially what it's doing is only changing a small part of one variable out of a bunch of variables set aside for the flags.

Offline Kawa

Re: SCI0: Events claimed Flags etc
« Reply #8 on: August 23, 2024, 02:10:09 AM »
(in an 8-bit system, like SCI0)
(on an 8-bit system like SCI0, or 16 times as many yes/no's on a 16-bit system like SCI1).
SCI0 was just as 16-bit as SCI1.

Offline Charles

Re: SCI0: Events claimed Flags etc
« Reply #9 on: August 23, 2024, 08:36:21 AM »
Whoops. Man, that makes a lot more sense ? I felt like 255 was way too low to be the highest value a variable could hold. Thanks. Well I hope the visual still helps anybody who needs it.


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

Page created in 0.066 seconds with 23 queries.