Dereferencing Actor Pointers?

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
Valencer
Posts: 22
Joined: Wed Mar 28, 2018 6:58 am

Dereferencing Actor Pointers?

Post by Valencer »

Hello All!

I am wondering how exactly ZScript works with pointers in terms of type casting and pointers.

This is how an actor pointer would be type casted in ZScript

Code: Select all

SomeClassThing classThing;
classThing = SomeClassThing( actorPointer );
If I were to do this...

Code: Select all

classThing.member++;
Am I incrementing the original SomeClassThing's member ( from the given pointer ), or the member from a local copy of SomeClassThing.

If it is a local copy, is there any way to write to the original class instance and its members?

I've seen this syntax around, which I thought indicates that it is a class pointer, but I do not know how to use it ( in terms of 'dereferencing' it and writing to its members ).

Code: Select all

Class< SomeClassThing > classThingPtr;
User avatar
phantombeta
Posts: 2090
Joined: Thu May 02, 2013 1:27 am
Operating System Version (Optional): Windows 10
Graphics Processor: nVidia with Vulkan support
Location: Brazil

Re: Dereferencing Actor Pointers?

Post by phantombeta »

ZScript class pointers don't need to be manually dereferenced.
I've seen this syntax around, which I thought indicates that it is a class pointer, but I do not know how to use it ( in terms of 'dereferencing' it and writing to its members ).

Code: Select all

Class< SomeClassThing > classThingPtr;
That's not related to pointers at all. That stores a class type. You can use it like this:

Code: Select all

class test : Actor {
    states {
    Spawn:
        BAL1 A -1;
        stop;
    }
}
[...]
class<Actor> actorToSpawn = 'test';
Actor.Spawn (actorToSpawn, (0, 0, 0));
This will spawn an actor of type "test" at XYZ coordinates (0, 0, 0).
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49073
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: Dereferencing Actor Pointers?

Post by Graf Zahl »

Valencer wrote: Am I incrementing the original SomeClassThing's member ( from the given pointer ), or the member from a local copy of SomeClassThing.

If it is a local copy, is there any way to write to the original class instance and its members?
There is no copy of the object, you merely create a copy of the pointer. They will both point to the same object. ZScript does not allow duplication of objects, unless some class provides an explicit method for that.
Valencer
Posts: 22
Joined: Wed Mar 28, 2018 6:58 am

Re: Dereferencing Actor Pointers?

Post by Valencer »

Thanks for responses everyone, its been very helpful!
phantombeta wrote:ZScript class pointers don't need to be manually dereferenced.
Graf Zahl wrote: There is no copy of the object, you merely create a copy of the pointer. They will both point to the same object. ZScript does not allow duplication of objects, unless some class provides an explicit method for that.
I thought that it may work similar to what it is in C++, but that does not seem to be the case :D ( Awesome! ).
It then may seem that there is an error somewhere else in my code!
phantombeta wrote: That's not related to pointers at all. That stores a class type. You can use it like this:

Code: Select all

class test : Actor {
    states {
    Spawn:
        BAL1 A -1;
        stop;
    }
}
[...]
class<Actor> actorToSpawn = 'test';
Actor.Spawn (actorToSpawn, (0, 0, 0));
This will spawn an actor of type "test" at XYZ coordinates (0, 0, 0).
This is very useful! I may be able to write all sorts of Zscript functions that take a class as an argument.

Thanks all for your help!
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49073
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: Dereferencing Actor Pointers?

Post by Graf Zahl »

Valencer wrote: I thought that it may work similar to what it is in C++, but that does not seem to be the case :D ( Awesome! ).

It works like a C++ pointer (e.g. AActor *actor) not like a C++ instance (e.g. AActor actor).
Post Reply

Return to “Scripting”