[ZScript] Check if Actor has a mixin

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!)

[ZScript] Check if Actor has a mixin

Postby difficultoldstuff » Thu Jun 23, 2022 4:17 am

Hello guys! After googling a bi- a LOT I came to the forums for hints & tips yet again. What I'm trying to do is detect if a certain actor has a mixin. Short example would be:

Code: Select allExpand view
mixin class Worms {}

class Can : Actor
{
    mixin Worms;

    States
    {
        Spawn:
            ACAN A -1;
            Stop;
    }
}


A simple check like this:

Code: Select allExpand view
Actor actCan = SomehowGetActor();
if (actCan is "Worms") {console.printf("we have worms!");}

errors out with an "Unknown class name Worms of type Object", so apparently that's a no go, and I'm fresh out of ideas.

Any kind of smart trickery I can implement to solve this problem? I'd have a ton of items in my project, some of them need a certain additional mixin for functionality, but building and maintaining a list of objects to compare each item to would seem like a slower, more mundane solution. Help and input appreciated as always, thank you for your time!
difficultoldstuff
 
Joined: 17 Jul 2020
Twitch ID: difficultoldstuff
Operating System: Windows Vista/7/2008 64-bit
OS Test Version: No (Using Stable Public Version)
Graphics Processor: nVidia with Vulkan support

Re: [ZScript] Check if Actor has a mixin

Postby Gutawer » Thu Jun 23, 2022 3:14 pm

Mixins are basically a syntax-checked copy-paste, and by the time code is actually compiled they don't even exist anymore, so you can't do anything to check for them. It's hard to tell you exactly what to do without knowing your specific problem, but it's probably something involving virtual functions.
User avatar
Gutawer
User Accounts Assistant
 
Joined: 16 Apr 2016
Discord: Gutawer#3431

Re: [ZScript] Check if Actor has a mixin

Postby difficultoldstuff » Thu Jun 23, 2022 3:35 pm

Gotcha, thank you! It was mainly just a thought experiment to do something "the lazy way around", ended up using a quick test against some classes and it works pretty much alright. It's good to clarify this tho, cuts down on research time.
difficultoldstuff
 
Joined: 17 Jul 2020
Twitch ID: difficultoldstuff
Operating System: Windows Vista/7/2008 64-bit
OS Test Version: No (Using Stable Public Version)
Graphics Processor: nVidia with Vulkan support


Return to Scripting

Who is online

Users browsing this forum: Dark-Assassin and 1 guest