Informations from virtual function

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!)
Post Reply
User avatar
Apeirogon
Posts: 1605
Joined: Mon Jun 12, 2017 12:57 am

Informations from virtual function

Post by Apeirogon »

Is there are any way to obtain data from virtual function? And I talk not about result, but for pointers. Mostly pointers...

Like, inside damage modj processed pointer "inflictor" and "source". I want extract that pointers, without rewriting damage mobj functions.
Is it possible?
User avatar
Matt
Posts: 9696
Joined: Sun Jan 04, 2004 5:37 pm
Preferred Pronouns: They/Them
Operating System Version (Optional): Debian Bullseye
Location: Gotham City SAR, Wyld-Lands of the Lotus People, Dominionist PetroConfederacy of Saudi Canadia
Contact:

Re: Informations from virtual function

Post by Matt »

The only way I can think of is to create a pointer in the calling actor/thinker and store it in that...
User avatar
Arctangent
Posts: 1235
Joined: Thu Nov 06, 2014 1:53 pm
Contact:

Re: Informations from virtual function

Post by Arctangent »

I mean, if you mean actually rewriting the functions as opposed to avoiding overriding them entirely, you can just call i.e. return Super.DamageMobj( inflictor, source, damage, mod, flags, angle ); at the end of your overriden DamageMobj( inflictor, source, damage, mod, flags, angle ) and you'll retain the standard DamageMobj() functionality while being able to tack on your own, such as storing inflictor and source elsewhere.
User avatar
Matt
Posts: 9696
Joined: Sun Jan 04, 2004 5:37 pm
Preferred Pronouns: They/Them
Operating System Version (Optional): Debian Bullseye
Location: Gotham City SAR, Wyld-Lands of the Lotus People, Dominionist PetroConfederacy of Saudi Canadia
Contact:

Re: Informations from virtual function

Post by Matt »

Arctangent: "And I talk not about result, but for pointers."

I think Apeirogon means that sometimes an overridden virtual does some extra stuff that results in new data being produced that could be useful outside of the function. E.g., damagemobj might get you new information on damagetype, source, source's actual intended target, mass of inflictor, etc.

One other alternative would be to take whatever it is you want to do and actually put it inside that function, but that can get a bit bloaty.
User avatar
Apeirogon
Posts: 1605
Joined: Mon Jun 12, 2017 12:57 am

Re: Informations from virtual function

Post by Apeirogon »

When I say "dont rewrite virtual functions" I mean "DONT TOUCH IT AT ALL, and left it pure and innocent as it was".

Like, I want make monster that remember all actors that hit it, pushing it into array "thing that I hate!!!!ONEONE", and pick target to chase from it depending of how much damage each of this actors inflict to it. Like, if caco inflict 30 damage to cyberdemon, imp 44 and player 12, cyberdemon first seek and destroy imp, then caco and only then player. Of course only if some one hit cyberdemon, while he chase player/dont have any target yet.

This can be easily, well....relatively easy, done with overiding damage mobj virtual. But it only works only for this cyberdemon/all actors that inherit from this base actor.
If I want do this for monster from other mod I need copy-paste code from my mod or change inheritance tree in other mod to make it inherit from my "monster base class".

I try do so using inventory items, give out each monster "thing that I hate" token/mark using spawn event handler, but they can get access to owners virtual functions "owner.super.damagemobj (paramethers)".
I focused on pointers, in case if this cant be done exactly as I want, save pointers and damage, to at least have monster that act "You hit me!? DIE!! And you hit me?! DIE!!! And you! And you! Oooo.... I see you come back from dead... I still remeber what you did last summer five minutes ago!!! DIE!!".

Maybe I should write this in first post...but this just example that I came up with one minutes ago...
User avatar
gwHero
Posts: 360
Joined: Mon May 08, 2017 3:23 am
Graphics Processor: Intel with Vulkan/Metal Support
Location: The Netherlands

Re: Informations from virtual function

Post by gwHero »

Just thinking.. maybe the event WorldThingDamaged would be of help?
User avatar
Apeirogon
Posts: 1605
Joined: Mon Jun 12, 2017 12:57 am

Re: Informations from virtual function

Post by Apeirogon »

It work only for this particular case.
But do we have, as example, can collide with events?

Looks like in this moment there are no way to obtain anything from virtual functions, without rewriting it.
User avatar
gwHero
Posts: 360
Joined: Mon May 08, 2017 3:23 am
Graphics Processor: Intel with Vulkan/Metal Support
Location: The Netherlands

Re: Informations from virtual function

Post by gwHero »

Correct, it was more for this specific case.
Post Reply

Return to “Scripting”