"How do I ZScript?"

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!
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!)
User avatar
hideousdestructor
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

Re: "How do I ZScript?"

Post by hideousdestructor »

Is there yet a way now to log something but only for the calling player (as opposed to broadcasting it to everyone)?
User avatar
Major Cooke
Posts: 8221
Joined: Sun Jan 28, 2007 3:55 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): Windows 10
Graphics Processor: nVidia with Vulkan support
Location: GZBoomer Town

Re: "How do I ZScript?"

Post by Major Cooke »

Jaxxoon R wrote:Thanks, I think it works now.
I must've had the most corrosive brainfart when I posted that solution. You could just as easily do this instead:

Code: Select all

Angle = master.Angle;
A_FaceTarget(80);
User avatar
Nash
 
 
Posts: 17513
Joined: Mon Oct 27, 2003 12:07 am
Location: Kuala Lumpur, Malaysia

Re: "How do I ZScript?"

Post by Nash »

I've read some generic programming advice that over-reliance of using "auto" isn't recommended and it's always better to specify the type you want, whenever possible.

Is the same advice relevant for ZScript and "let"? Should I be worried that I'm generally just let'ting stuff everywhere without much forethought?
Blue Shadow
Posts: 5046
Joined: Sun Nov 14, 2010 12:59 am

Re: "How do I ZScript?"

Post by Blue Shadow »

The downside I see is that when you're reading the code, you might not immediately deduce the data type of the variable you're declaring, and you might have to look in other places to figure that out, e.g calling a function and storing what it returns into the variable - in this case you need to check the function's return type.
User avatar
Nash
 
 
Posts: 17513
Joined: Mon Oct 27, 2003 12:07 am
Location: Kuala Lumpur, Malaysia

Re: "How do I ZScript?"

Post by Nash »

I can imagine that being annoying when you're trying to read something you didn't make yourself. And to make things worse, no Intellisense for ZScript...
User avatar
Ed the Bat
Posts: 3060
Joined: Thu May 03, 2012 1:18 pm
Location: Maryland, US

Re: "How do I ZScript?"

Post by Ed the Bat »

Following up on my question... I seem to have the impression that the player's StartItem list is stored as DropItem...? If that's the case, maybe a way to read DropItem will get me where I want to be. I'm at square one on that one too, though...
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49252
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: "How do I ZScript?"

Post by Graf Zahl »

Ed the Bat wrote:What I really wanted was a more elegant and automated way to blank out songs that I hate, so I wouldn't have to rely so much on batch files. Hearing a note before I begin playing makes me feel sloppy.
What precisely do you want to do? If you just want to blank out or replace specific music pieces, using SNDINFO and $musicalias might be a better option.
Ed the Bat wrote: Anyhow, new question... is there a way to read the contents of a player's StartItem list?
It's stored in the drop item list which is accessible. Check the boss brain code, which also repurposes it.
User avatar
Nash
 
 
Posts: 17513
Joined: Mon Oct 27, 2003 12:07 am
Location: Kuala Lumpur, Malaysia

Re: "How do I ZScript?"

Post by Nash »

How do I make a custom variable and property behave like DropItem / StartItem? It allows you to assign many classes additively to it.
User avatar
Ed the Bat
Posts: 3060
Joined: Thu May 03, 2012 1:18 pm
Location: Maryland, US

Re: "How do I ZScript?"

Post by Ed the Bat »

Graf Zahl wrote:What precisely do you want to do? If you just want to blank out or replace specific music pieces, using SNDINFO and $musicalias might be a better option.
That's what I've been doing for a couple of years. I was just hoping I could stop using a batch file to track which SNDINFO lumps to load for which PWADs, and have the engine itself check some conditionals and do it on-the-fly.
Graf Zahl wrote:It's stored in the drop item list which is accessible. Check the boss brain code, which also repurposes it.
Excellent, I'll look there. Thanks for the tip!
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49252
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: "How do I ZScript?"

Post by Graf Zahl »

Ed the Bat wrote:
Graf Zahl wrote:What precisely do you want to do? If you just want to blank out or replace specific music pieces, using SNDINFO and $musicalias might be a better option.
That's what I've been doing for a couple of years. I was just hoping I could stop using a batch file to track which SNDINFO lumps to load for which PWADs, and have the engine itself check some conditionals and do it on-the-fly.
Use SLADE to insert the lumps into the WADs. Problem solved forever. I have been doing that for years.
User avatar
Nash
 
 
Posts: 17513
Joined: Mon Oct 27, 2003 12:07 am
Location: Kuala Lumpur, Malaysia

Re: "How do I ZScript?"

Post by Nash »

If a Thinker (non-Actor) is made using new(), added into an array, and then later is deleted from the array using Delete()... will it be truly removed? Actually what's the safest way to remove it? myArray.Delete(index, 1) or myArray[index].Destroy()?
User avatar
AFADoomer
Posts: 1346
Joined: Tue Jul 15, 2003 4:18 pm

Re: "How do I ZScript?"

Post by AFADoomer »

Nash wrote:If a Thinker (non-Actor) is made using new(), added into an array, and then later is deleted from the array using Delete()... will it be truly removed? Actually what's the safest way to remove it? myArray.Delete(index, 1) or myArray[index].Destroy()?
Or do we need to call .Destroy() to destroy the thinker object, then call .Delete() to clear the array index?
User avatar
kodi
 
 
Posts: 1361
Joined: Mon May 06, 2013 8:02 am

Re: "How do I ZScript?"

Post by kodi »

Is it possible to make a projectile not collide with one specific actor in one of its pointers?
User avatar
Major Cooke
Posts: 8221
Joined: Sun Jan 28, 2007 3:55 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): Windows 10
Graphics Processor: nVidia with Vulkan support
Location: GZBoomer Town

Re: "How do I ZScript?"

Post by Major Cooke »

@Nash: If you intend on destroying the thinker, you must call Destroy first, then shrink the array using ShrinkToFit... Or just delete for that index. The arrays are merely pointers to other actors, and all thinkers are stored in internal thinker arrays so removing it from your dynamic array will not actually destroy it.

So... Call myArray[index].Destroy() first and then the Delete/ShrinkToFit function.

@kodi: Override CanCollideWith. Do a check for non-passive on the actor with the pointer, see if it's that pointer and return false. True for all other cases.

Code: Select all

override bool CanCollideWith(Actor other, bool passive)
{
	if (!passive)
	{
		if (other == tracer)
			return false;
	}
	return true;
}
User avatar
ZZYZX
 
 
Posts: 1384
Joined: Sun Oct 14, 2012 1:43 am
Location: Ukraine

Re: "How do I ZScript?"

Post by ZZYZX »

Nash wrote:If a Thinker (non-Actor) is made using new(), added into an array, and then later is deleted from the array using Delete()... will it be truly removed? Actually what's the safest way to remove it? myArray.Delete(index, 1) or myArray[index].Destroy()?
When last reference to an object is lost, thinker should be deleted, but that's unless there's a global list of thinkers somewhere, like one for Actors. Graf, help.
Anyway, you can try testing this by printing something in OnDestroy of your class and thus checking if OnDestroy gets called when you remove it from the array.
Note: can be called in few seconds or even minutes (remember how EventHandlers were garbage collected only after some time and certain circumstances made it faster?)

Edit: if it's STAT_STATIC, do destroy manually.

Return to “Scripting”