ScriptCall in ZScript
Moderator: GZDoom Developers
- The Zombie Killer
- Posts: 1528
- Joined: Thu Jul 14, 2011 12:06 am
- Location: Gold Coast, Queensland, Australia
ScriptCall in ZScript
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).
- Major Cooke
- Posts: 8170
- Joined: Sun Jan 28, 2007 3:55 pm
- Preferred Pronouns: He/Him
- Location: QZDoom Maintenance Team
Re: ScriptCall in ZScript
Not sure if I understand this correctly or not but can I get an example?
- The Zombie Killer
- Posts: 1528
- Joined: Thu Jul 14, 2011 12:06 am
- Location: Gold Coast, Queensland, Australia
Re: ScriptCall in ZScript
Code: Select all
class Example
{
static void PrintSomeValue(int value)
{
Console.Printf("%d", value);
}
}
// ...
// in some actor class
void PrintMyHealth()
{
ScriptCall("Example", "PrintSomeValue", health);
}
Re: ScriptCall in ZScript
Have you tried something like this in the actor class?
Code: Select all
Example.PrintSomeValue(health);
- The Zombie Killer
- Posts: 1528
- Joined: Thu Jul 14, 2011 12:06 am
- Location: Gold Coast, Queensland, Australia
Re: ScriptCall in ZScript
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.
Think of a situation where you would need something akin to reflection. You wouldn't be able to call the function directly there.
Re: ScriptCall in ZScript
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.
- 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
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?
In that case you could even read your own classes with the wads read lump functionality and create advanced generic functions.
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);
-
- Posts: 111
- Joined: Wed Jun 15, 2016 2:49 pm
Re: ScriptCall in ZScript
This would be very appreciated! Really hope this happens.
- The Zombie Killer
- Posts: 1528
- Joined: Thu Jul 14, 2011 12:06 am
- Location: Gold Coast, Queensland, Australia
Re: ScriptCall in ZScript
Essentially, yeah. You could almost emulate some sort of "function pointer" system that way.gwHero wrote:Do you also mean to have the possibility of storing the function in a variable like this?
Re: ScriptCall in ZScript
so you want a modular way of calling static functions by a string name?
-
- Posts: 111
- Joined: Wed Jun 15, 2016 2:49 pm
Re: ScriptCall in ZScript
Yesibm5155 wrote:so you want a modular way of calling static functions by a string name?
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.