ScriptCall in ZScript

Moderator: GZDoom Developers

Post Reply
User avatar
The Zombie Killer
Posts: 1528
Joined: Thu Jul 14, 2011 12:06 am
Location: Gold Coast, Queensland, Australia

ScriptCall in ZScript

Post by The Zombie Killer »

It'd be super useful to be able to call static methods via their string names. Currently this functionality is only exposed to ACS (as far as I'm aware), so you have to marshal a bunch of data between the languages to do this, and on top of that, you can only use primitive types (int, string, etc).
User avatar
Major Cooke
Posts: 8170
Joined: Sun Jan 28, 2007 3:55 pm
Preferred Pronouns: He/Him
Location: QZDoom Maintenance Team

Re: ScriptCall in ZScript

Post by Major Cooke »

Not sure if I understand this correctly or not but can I get an example?
User avatar
The Zombie Killer
Posts: 1528
Joined: Thu Jul 14, 2011 12:06 am
Location: Gold Coast, Queensland, Australia

Re: ScriptCall in ZScript

Post by The Zombie Killer »

Code: Select all

class Example
{
    static void PrintSomeValue(int value)
    {
        Console.Printf("%d", value);
    }
}

// ...

// in some actor class
void PrintMyHealth()
{
    ScriptCall("Example", "PrintSomeValue", health);
}
The above shows how it'd be used.
User avatar
AFADoomer
Posts: 1322
Joined: Tue Jul 15, 2003 4:18 pm
Contact:

Re: ScriptCall in ZScript

Post by AFADoomer »

Have you tried something like this in the actor class?

Code: Select all

Example.PrintSomeValue(health);
User avatar
The Zombie Killer
Posts: 1528
Joined: Thu Jul 14, 2011 12:06 am
Location: Gold Coast, Queensland, Australia

Re: ScriptCall in ZScript

Post by The Zombie Killer »

You could do that, yeah, but that was only an example of usage, not any advantage the feature would provide.
Think of a situation where you would need something akin to reflection. You wouldn't be able to call the function directly there.
User avatar
AFADoomer
Posts: 1322
Joined: Tue Jul 15, 2003 4:18 pm
Contact:

Re: ScriptCall in ZScript

Post by AFADoomer »

Ah, sorry. Can you give a more detailed description of a use case? I don't think I understand what you're trying to do.
User avatar
gwHero
Posts: 360
Joined: Mon May 08, 2017 3:23 am
Graphics Processor: Intel with Vulkan/Metal Support
Location: The Netherlands

Re: ScriptCall in ZScript

Post by gwHero »

Not before you mentioned "reflection" I understood what you meant.

Interesting but maybe quite demanding. Do you also mean to have the possibility of storing the function in a variable like this?

Code: Select all

string myfunction = "PrintMyHealth"; 
ScriptCall("Example", myfunction , health);
In that case you could even read your own classes with the wads read lump functionality and create advanced generic functions.
ZippeyKeys12
Posts: 111
Joined: Wed Jun 15, 2016 2:49 pm

Re: ScriptCall in ZScript

Post by ZippeyKeys12 »

This would be very appreciated! Really hope this happens.
User avatar
The Zombie Killer
Posts: 1528
Joined: Thu Jul 14, 2011 12:06 am
Location: Gold Coast, Queensland, Australia

Re: ScriptCall in ZScript

Post by The Zombie Killer »

gwHero wrote:Do you also mean to have the possibility of storing the function in a variable like this?
Essentially, yeah. You could almost emulate some sort of "function pointer" system that way.
User avatar
ibm5155
Posts: 1268
Joined: Wed Jul 20, 2011 4:24 pm
Contact:

Re: ScriptCall in ZScript

Post by ibm5155 »

so you want a modular way of calling static functions by a string name?
ZippeyKeys12
Posts: 111
Joined: Wed Jun 15, 2016 2:49 pm

Re: ScriptCall in ZScript

Post by ZippeyKeys12 »

ibm5155 wrote:so you want a modular way of calling static functions by a string name?
Yes
It's about 20 days :? doesn't seem like an extreme bump.
This seems relatively easy(to a person who doesn't really understand how the ACS ScriptCall works) if the ACS ScriptCall's functionality is simply a method in the source; surely one would just have to expose it to ZScript?

:? Probably am wrong, though.
Post Reply

Return to “Closed Feature Suggestions [GZDoom]”