Community

SCI Programming => SCI Syntax Help => Topic started by: lwc on December 30, 2023, 07:53:59 AM

Title: Event flags VS Object flags VS ScummVM debugger console
Post by: lwc on December 30, 2023, 07:53:59 AM
Unlike most SCI games (including its prequel), EcoQuest 2 barely uses flag events (from global110). It instead mostly uses a Main.sc (https://github.com/sluicebox/sci-scripts/blob/main/eco2-dos-1.000.000/src/Main.sc) (script #0) local variable called gCurrentRegionFlags which uses set/test/clear procedures that are defined in Flags.sc (https://github.com/sluicebox/sci-scripts/blob/main/eco2-dos-1.000.000/src/Flags.sc) (script #985).

Thankfully, the kind people here made EcoQuest2's restored debug (https://sciprogramming.com/community/index.php?topic=9150.0) smart enough to handle both types using a yes/no question of "Flag Object?" (for alt+b/l/k). If the player chooses yes, it uses gCurrentRegionFlags set/test/clear and if the player chooses no, it uses the standard SetFlag/TestFlag/ClearFlag.

So my questions are:

Stats:

Thanks!
Title: Re: Event flags VS Object flags VS ScummVM debugger console
Post by: lskovlun on December 30, 2023, 03:34:39 PM
That seems like a general decision to keep data pertaining to specific regions separate. It does the same thing with inventory items: Usually, inventory items are put on the inventory list once at startup and leaves them there for the duration - Eco2 instead adds and deletes items throughout. Oh, and there's the Ecorder flags too.
Title: Re: Event flags VS Object flags VS ScummVM debugger console
Post by: lwc on December 31, 2023, 02:14:11 PM
But there's no separation really because while gCurrentRegionFlags is technically a local, it's declared in Main.sc and thus treated like a global anyway - in the console running l 0 150 is equal to running vv g 150 - in either case the output is 002f:0508 (object 'goldFlags').

About question 3, you would think if bpe can't be used, at least Flags::set should work, but it doesn't. This is even though according to this (https://bugs.scummvm.org/timeline?from=2017-05-15T22%3A03%3A39Z&precision=second) in KQ6 bpx KQ6Print::say works, whereas KQ6Print is a class just like Flags and say is a method just like set (see code (https://github.com/sluicebox/sci-scripts/blob/main/kq6-cd-dos-1.000.00G/src/KQ6Print.s)). According to this (https://bugs.scummvm.org/ticket/10730), it should also be similar to Laura Bow 2's bpx bugsWithMeat::cue (see code (https://github.com/sluicebox/sci-scripts/blob/main/ra-cd-dos-1.1/src/rm600.sc)).

But I've found an interim solution - bpa 000e:00a7 - I don't like it because there's no pasting in ScummVM's console and who wants to type down this address, but it works nonetheless.

Here's how I deduced that Flags' set can be called directly with address 000e:00a7:
Title: Re: Event flags VS Object flags VS ScummVM debugger console
Post by: doomlazer on December 31, 2023, 03:51:13 PM
...why did the people here that restored the debugger consider the answer of "no" to "Flag Object?" to mean using a global that stores many flags?

I recall the debugger script for EQ2 still exists in the resources, so that code was from the Sierra devs and not a conscious decision from anyone here.

Did you report the flag object issue to the ScummVM devs?
Title: Re: Event flags VS Object flags VS ScummVM debugger console
Post by: lskovlun on December 31, 2023, 03:59:27 PM
But there's no separation really because while gCurrentRegionFlags is technically a local, it's declared in Main.sc and thus treated like a global anyway - in the console running l 0 150 is equal to running vv g 150 - in either case the output is 002f:0508 (object 'goldFlags').
No, gCurrentRegionFlags is a pointer to the currently accessible flags. So if gCurrentRegionFlags is pointing to goldFlags, I can't access batFlags, for instance. That script won't even be loaded, so I can't access its flags.
Of course it's a global variable, because every script needs to be able to dereference it.
Title: Re: Event flags VS Object flags VS ScummVM debugger console
Post by: lwc on December 31, 2023, 05:48:16 PM
Quote
Did you report the flag object issue to the ScummVM devs?
Report what? Since the game also uses standard flags, ScummVM is unlikely to add a special secondary support, especially since last time I asked something about the console (to add a basic "clear" console command (https://bugs.scummvm.org/ticket/13386)) they told me to stay away from console requests as it's an "internal" too.

No, gCurrentRegionFlags is a pointer to the currently accessible flags. So if gCurrentRegionFlags is pointing to goldFlags, I can't access batFlags, for instance. That script won't even be loaded, so I can't access its flags.
Of course it's a global variable, because every script needs to be able to dereference it.
In Main.sc it appears as:
Code: [Select]
(local
gCurrentRegionFlags
Where do you see it's a pointer? Other than being declared, it's not defined. It's just used with Flags.sc's set/test/clear.
Title: Re: Event flags VS Object flags VS ScummVM debugger console
Post by: lskovlun on December 31, 2023, 05:55:34 PM
I see these:
Code: [Select]
Bats.sc: (= gCurrentRegionFlags batFlags)
Cibola.sc: (= gCurrentRegionFlags cibolaFlags)
Docks.sc: (= gCurrentRegionFlags dockFlags)
Flood.sc: (= gCurrentRegionFlags floodFlags)
Gold.sc: (= gCurrentRegionFlags goldFlags)
Jungle.sc: (= gCurrentRegionFlags jungleFlags)
Village.sc: (= gCurrentRegionFlags villageFlags)
which set gCurrentRegionFlags to point at each of those instances at the right time. And yes, they are instances, for example:
Code: [Select]
(instance villageFlags of Flags
        (properties
                size 80
        )
)
Title: Re: Event flags VS Object flags VS ScummVM debugger console
Post by: lwc on December 31, 2023, 07:06:49 PM
True, although from what I've seen so far (just a couple of rooms in different areas) they still don't use the same flag number twice, even though you've established they can.
Now I just wonder how to be able catch Flags' set/test/clear with either bpe or bpx instead of having to use bpa which relies on addresses.
Title: Re: Event flags VS Object flags VS ScummVM debugger console
Post by: lwc on January 04, 2024, 02:46:36 PM
So any idea why bpa works in this case while bpx doesn't?
Title: Re: Event flags VS Object flags VS ScummVM debugger console
Post by: lskovlun on January 04, 2024, 03:26:50 PM
Because gCurrentRegionFlags doesn't point to Flags, but to dockFlags etc. You can say
Code: [Select]
bpx dockFlags::testjust fine.
Title: Re: Event flags VS Object flags VS ScummVM debugger console
Post by: lwc on January 04, 2024, 04:44:53 PM
But in each area it's different. In the initial example of room 840 it's goldFlags, not dockFlags, so it would be:
Code: [Select]
bpx goldFlags::setSo:
Title: Re: Event flags VS Object flags VS ScummVM debugger console
Post by: Kawa on January 04, 2024, 04:51:02 PM
I was wondering that myself, how to peek at the value of gCurrentRegionFlags and invoke methods on an object by address instead of name. I don't use the debuggers much lol.
Title: Re: Event flags VS Object flags VS ScummVM debugger console
Post by: lwc on January 04, 2024, 04:55:02 PM
I was wondering that myself, how to peek at the value of gCurrentRegionFlags and invoke methods on an object by address instead of name. I don't use the debuggers much lol.
I've explained above the flow to get the address of set/test/clear and then use it in bpa. This should work in 100% of the rooms, but it's not comfortable to work with addresses.
I just look for a bpx alternative with a static name.