Referencing inventory flags in ZScript?

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!

Moderator: GZDoom Developers

Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.

Please bear in mind that the people helping you do not automatically know how much you know. You may be asked to upload your project file to look at. Don't be afraid to ask questions about what things mean, but also please be patient with the people trying to help you. (And helpers, please be patient with the person you're trying to help!)
User avatar
DenisBelmondo
Posts: 379
Joined: Fri Jun 06, 2008 6:26 pm
Location: Two-Key Return

Referencing inventory flags in ZScript?

Post by DenisBelmondo »

So basically, I'm trying to disable Inventory.NOSCREENFLASH on the fly with an Event Handler and its WorldThingSpawned virtual. Here's some code.

Code: Select all

if (e.thing is "Inventory")
    e.thing.bNoScreenFlash = true;
The second line is problematic because I assume that bNoScreenFlash is not directly a member of Thing. So I tried prefixing it with "Inv", which the member of type Inventory in the base Actor class just for giggles like so:

Code: Select all

if (e.thing is "Inventory")
    e.thing.Inv.bNoScreenFlash = true;
It no longer complains about bNoScreenFlash being an unknown identifier, but the VM crashes with an access violation (address 0).

So finally, I try to modify the check like so:

Code: Select all

if (e.thing.Inv)
    e.thing.Inv.bNoScreenFlash = true;
This doesn't cause the VM to crash, but it has no effect whatsoever.

The only thing that I've done to make it work is having e.thing call A_ChangeFlag(), but as we all know, that function is deprecated.
User avatar
m8f
 
 
Posts: 1445
Joined: Fri Dec 29, 2017 4:15 am
Preferred Pronouns: He/Him
Operating System Version (Optional): Manjaro Linux
Location: Siberia (UTC+7)

Re: Referencing inventory flags in ZScript?

Post by m8f »

"e.thing.Inv" means an inventory that e.thing has. This code needs a cast:

Code: Select all

Inventory inv = Inventory(e.thing);
if (inv) { inv.bNoScreenFlash = true; }
User avatar
DenisBelmondo
Posts: 379
Joined: Fri Jun 06, 2008 6:26 pm
Location: Two-Key Return

Re: Referencing inventory flags in ZScript?

Post by DenisBelmondo »

Thanks a bunch! It certainly gives me some ZScript related insight outside of this context too.

Return to “Scripting”