ZScript Discussion
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!)
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!)
-
- Lead GZDoom+Raze Developer
- Posts: 49130
- Joined: Sat Jul 19, 2003 10:19 am
- Location: Germany
Re: ZScript Discussion
You cannot override a function in its own class - only in a subclass.
-
- Posts: 3060
- Joined: Thu May 03, 2012 1:18 pm
- Graphics Processor: nVidia with Vulkan support
- Location: Maryland, US
Re: ZScript Discussion
Instead of let, try this:Major Cooke wrote:Can something like this be done?
Because this doesn't work. PL isn't recognized.Code: Select all
// "MyActor" has an int variable PL. Actor t = Spawn("MyActor",pos); let s = t; if (s) { s.PL = 1; }
I ask because I have an array of Class<Actor>s to determine randomly which actor to spawn, and I haven't found a working solution to auto-resolve the class fully without requiring yet another cast to be around it.
Something tells me I need the list of actors to inherit from someone with the variable...
Code: Select all
MyActor s = MyActor(t);
-
- Posts: 7
- Joined: Sat Dec 10, 2016 9:31 am
Re: ZScript Discussion
What the zscript keyword "let" does? I cant remember very well.
-
- Posts: 3060
- Joined: Thu May 03, 2012 1:18 pm
- Graphics Processor: nVidia with Vulkan support
- Location: Maryland, US
Re: ZScript Discussion
Attempts to automatically choose a type for the variable being defined, I believe.
-
- Lead GZDoom+Raze Developer
- Posts: 49130
- Joined: Sat Jul 19, 2003 10:19 am
- Location: Germany
Re: ZScript Discussion
'let assigns the type of the right-side expression of the '=' operator to the variable, it's meant as a shorthand for stuff where otherwise some repetition would be needed or where exact knowledge of the type is not needed and it' just supposed to match a variable.
'let a = Inventory(b)' is the same as 'Inventory a = Inventory(b)'.
Other example:
let v = thing.vel; thing.VelFromAngle(); thing.vel += v;
There's no need to know what precise type this is, as long as it's compatible with the following operation.
Essentially it's equivalent to C++'s auto keyword.
'let a = Inventory(b)' is the same as 'Inventory a = Inventory(b)'.
Other example:
let v = thing.vel; thing.VelFromAngle(); thing.vel += v;
There's no need to know what precise type this is, as long as it's compatible with the following operation.
Essentially it's equivalent to C++'s auto keyword.
-
-
- Posts: 1384
- Joined: Sun Oct 14, 2012 1:43 am
- Location: Ukraine
Re: ZScript Discussion
[11:40 AM] ZZYZX: I wrote this
[11:40 AM] ZZYZX: http://pastebin.com/4W9MXAnt
[11:40 AM] ZZYZX: problem is
[11:40 AM] ZZYZX: it says no function GetClassName
[11:40 AM] ZZYZX: While I'm currently looking at base.txt and actor.txt
[11:40 AM] ZZYZX: from gzdoom.pk3
[11:41 AM] ZZYZX: And see that Actor : Thinker, and Thinker : Object, and Object has native Name GetClassName();
What's wrong here?
[11:40 AM] ZZYZX: http://pastebin.com/4W9MXAnt
[11:40 AM] ZZYZX: problem is
[11:40 AM] ZZYZX: it says no function GetClassName
[11:40 AM] ZZYZX: While I'm currently looking at base.txt and actor.txt
[11:40 AM] ZZYZX: from gzdoom.pk3
[11:41 AM] ZZYZX: And see that Actor : Thinker, and Thinker : Object, and Object has native Name GetClassName();
What's wrong here?
-
- Posts: 786
- Joined: Wed Feb 23, 2011 11:04 am
- Preferred Pronouns: No Preference
Re: ZScript Discussion
What's the difference between this:
and this:
?
Code: Select all
if(target is "DoomPlayer")
Code: Select all
if(DoomPlayer(target))
-
- Posts: 13720
- Joined: Tue Jan 13, 2004 1:31 pm
- Preferred Pronouns: She/Her
Re: ZScript Discussion
The last typecasts "target" into DoomPlayer. If the cast fails (i.e. target cannot be casted into DoomPlayer) it returns "nullptr" or false.
I am not sure exactly what conditions trigger a successful casting condition, but I would imagine any class that inherits from DoomPlayer would successfully trigger the condition specified in the if statement.
I am not sure exactly what conditions trigger a successful casting condition, but I would imagine any class that inherits from DoomPlayer would successfully trigger the condition specified in the if statement.
-
- Posts: 786
- Joined: Wed Feb 23, 2011 11:04 am
- Preferred Pronouns: No Preference
Re: ZScript Discussion
@ZZYZX
At the time of making this post, GetClassName isn't present in the latest dev build. (GZDoom g2.3pre-1072-ga37db1c)
That's probably why you're getting the error.
EDIT: ActorIterator won't do anything if the search TID is 0. What you want to do instead is use ThinkerIterator.
IE replace this
with this
Also make sure to typecast ai.Next() into Actor.
At the time of making this post, GetClassName isn't present in the latest dev build. (GZDoom g2.3pre-1072-ga37db1c)
That's probably why you're getting the error.
EDIT: ActorIterator won't do anything if the search TID is 0. What you want to do instead is use ThinkerIterator.
IE replace this
Code: Select all
ActorIterator ai = ActorIterator.Create(0);
Code: Select all
ThinkerIterator ai = ThinkerIterator.Create();
Last edited by Fishytza on Wed Dec 28, 2016 5:05 am, edited 1 time in total.
-
- Lead GZDoom+Raze Developer
- Posts: 49130
- Joined: Sat Jul 19, 2003 10:19 am
- Location: Germany
Re: ZScript Discussion
FishyClockwork wrote:What's the difference between this:and this:Code: Select all
if(target is "DoomPlayer")
?Code: Select all
if(DoomPlayer(target))
None. The main difference is that the first expression is a boolean result and the second one a pointer to the target type, but that only matters if you need to work with the pointer - inside an 'if' it doesn't matter.
Code: Select all
(target is "DoomPlayer")
Code: Select all
(DoomPlayer(target) != null)
Code: Select all
if (target is tracer.GetClass())
-
- Lead GZDoom+Raze Developer
- Posts: 49130
- Joined: Sat Jul 19, 2003 10:19 am
- Location: Germany
Re: ZScript Discussion
It's just like in C++. You can cast a pointer to a type if the referenced object is a subclass of that type.Eruanna wrote:The last typecasts "target" into DoomPlayer. If the cast fails (i.e. target cannot be casted into DoomPlayer) it returns "nullptr" or false.
I am not sure exactly what conditions trigger a successful casting condition, but I would imagine any class that inherits from DoomPlayer would successfully trigger the condition specified in the if statement.
-
-
- Posts: 1384
- Joined: Sun Oct 14, 2012 1:43 am
- Location: Ukraine
Re: ZScript Discussion
Is there any way to get the name of an object's class though? I need to somehow obtain at least RELATIVELY unique human readable data to see what actors are affected...
Also, GetClassName seems to be implemented for me here
Might be that I'm looking at more recent code revision here than the one built at DRDTeam. Sorries in that case.
Also, GetClassName seems to be implemented for me here
Code: Select all
DEFINE_ACTION_FUNCTION(DObject, GetClassName)
{
PARAM_SELF_PROLOGUE(DObject);
ACTION_RETURN_INT(self->GetClass()->TypeName);
}
Last edited by ZZYZX on Wed Dec 28, 2016 5:01 am, edited 1 time in total.
-
- Lead GZDoom+Raze Developer
- Posts: 49130
- Joined: Sat Jul 19, 2003 10:19 am
- Location: Germany
Re: ZScript Discussion
Just implemented yesterday: GetClassName()
-
-
- Posts: 1384
- Joined: Sun Oct 14, 2012 1:43 am
- Location: Ukraine
Re: ZScript Discussion
ThinkerIterator.Create("Actor") works, thanks.FishyClockwork wrote:EDIT: ActorIterator won't do anything if the search TID is 0. What you want to do instead is use ThinkerIterator.
IE replace thiswith thisCode: Select all
ActorIterator ai = ActorIterator.Create(0);
Also make sure to typecast ai.Next() into Actor.Code: Select all
ThinkerIterator ai = ThinkerIterator.Create();
Complete code looks like this now:
Code: Select all
ThinkerIterator ti = ThinkerIterator.Create("Actor");
Actor mo;
while (mo = Actor(ti.Next()))
{
A_Log(mo.GetClassName());
}
-
- Posts: 3060
- Joined: Thu May 03, 2012 1:18 pm
- Graphics Processor: nVidia with Vulkan support
- Location: Maryland, US
Re: ZScript Discussion
YES! This is an absolute lifesaver! This satisfies my queries from before about how to get the name of a player's class! Thank you so much, Graf!Graf Zahl wrote:Just implemented yesterday: GetClassName()