"How do I ZScript?"

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!)
User avatar
Nash
 
 
Posts: 17342
Joined: Mon Oct 27, 2003 12:07 am
Location: Kuala Lumpur, Malaysia

Re: "How do I ZScript?"

Post by Nash »

Ed the Bat wrote:In case anyone's interested, I found a solution for my question from Page 1:

By giving A_RailAttack the RGF_EXPLICITANGLE flag, and setting the spread_z parameter to BulletSlope()-pitch, I now have a railgun that respects autoaim.

Thanks for sharing, Ed!

////////////////

I am trying to call GetCVar from an EventHandler but it seems that GetCVar is locked to Actors. Is this the correct way to do it, and should I delete a or will that be handled automatically?

Code: Select all

    int _W_GetUpdateInterval(void)
    {
        let a = new("Actor");
        int i = a.GetCVar("sv_weatherupdateinterval");
        return i >= 1 && i < 100 ? i : 1;
    }
User avatar
Gutawer
User Accounts Assistant
Posts: 464
Joined: Sat Apr 16, 2016 6:01 am
Preferred Pronouns: She/Her

Re: "How do I ZScript?"

Post by Gutawer »

ZScript has no need for GetCVar, just access sv_weatherupdateinterval as if it were a variable.
User avatar
Nash
 
 
Posts: 17342
Joined: Mon Oct 27, 2003 12:07 am
Location: Kuala Lumpur, Malaysia

Re: "How do I ZScript?"

Post by Nash »

That doesn't work... at least not from EventHandler.
User avatar
Gutawer
User Accounts Assistant
Posts: 464
Joined: Sat Apr 16, 2016 6:01 am
Preferred Pronouns: She/Her

Re: "How do I ZScript?"

Post by Gutawer »

Hmm. I've been using CVars like that in Chaos Corpses from inside Event Handlers and they seem to work fine for me :/
User avatar
Nash
 
 
Posts: 17342
Joined: Mon Oct 27, 2003 12:07 am
Location: Kuala Lumpur, Malaysia

Re: "How do I ZScript?"

Post by Nash »

D'OH I forgot to add the CVARINFO lump, which was why it couldn't find the variable. Works now. Sorry. XD

Next question:

Code: Select all

/*
 * Linearly interpolates the value and clamps the result between 0.0 to 1.0.
 * value: (No type restriction)
 *     Value from.
 * maxValue: (No type restriction)
 *     Value to.
 * Return value: (No type restriction)
 *     Result of interpolation. Ranges from 0.0 to 1.0.
 */
function int Interpolate(int value, int maxValue)
{
    return Clamp(FixedDiv(value, maxValue), 0.0, 1.0);
}
I'm horrible with maths and I didn't write this piece of ACS... can someone convert this to ZScript while still making it return the expected values as before?

Thing is, it accepted any kind of number before - either ints or Fixed - and will always result in a Fixed from 0 to 1. Fixed values in ACS have always confused me.
User avatar
Major Cooke
Posts: 8109
Joined: Sun Jan 28, 2007 3:55 pm

Re: "How do I ZScript?"

Post by Major Cooke »

You can simply change FixedDiv(value, maxValue) into value / maxValue.
User avatar
Matt
Posts: 9686
Joined: Sun Jan 04, 2004 5:37 pm
Location: Gotham City SAR, Wyld-Lands of the Lotus People, Dominionist PetroConfederacy of Saudi Canadia

Re: "How do I ZScript?"

Post by Matt »

So Nash mentioned a non-crash-inducing formatting error in my previous example and I never got around to asking:

So the correct format is no semicolon after +- flags but we must have a semicolon after properties?


Also, if I'm doing random numbers, is there any performance improvement if I keep ranges to powers of 2?
User avatar
Major Cooke
Posts: 8109
Joined: Sun Jan 28, 2007 3:55 pm

Re: "How do I ZScript?"

Post by Major Cooke »

Flags are the only things that don't require semicolons. So, yes.

For number ranges, not that I can think of...
User avatar
Nash
 
 
Posts: 17342
Joined: Mon Oct 27, 2003 12:07 am
Location: Kuala Lumpur, Malaysia

Re: "How do I ZScript?"

Post by Nash »

What's the formula to convert all of my ACS fixed angles to ZScript's degrees?

omfg i'm going to loose my mind viewtopic.php?f=3&t=31085
User avatar
Ed the Bat
Posts: 3060
Joined: Thu May 03, 2012 1:18 pm
Graphics Processor: nVidia with Vulkan support
Location: Maryland, US

Re: "How do I ZScript?"

Post by Ed the Bat »

I have no grasp of these EventHandlers... but could they be the key to my question from before, about replicating ACS' OPEN script type?
User avatar
Nash
 
 
Posts: 17342
Joined: Mon Oct 27, 2003 12:07 am
Location: Kuala Lumpur, Malaysia

Re: "How do I ZScript?"

Post by Nash »

Ed the Bat wrote:I have no grasp of these EventHandlers... but could they be the key to my question from before, about replicating ACS' OPEN script type?
That's exactly what you can do with them! Among other things of course. They're basically entry points to various things ("events") that can happen In the engine.

My Bumi weather engine is now running 100% off ZScript, not even a single line of ACS. :mrgreen:

My Duke3D shadow mod is also using an EventHandler that spawns shadows whenever a monster is spawned. viewtopic.php?f=37&t=54992

Here's a basic example ZSDemo that ZZYZX put up a while ago (I'm re-uploading here because it's impossible to search for it in all the noise)
You do not have the required permissions to view the files attached to this post.
User avatar
Ed the Bat
Posts: 3060
Joined: Thu May 03, 2012 1:18 pm
Graphics Processor: nVidia with Vulkan support
Location: Maryland, US

Re: "How do I ZScript?"

Post by Ed the Bat »

Beautiful! I'll be sure to read this over sometime today. Thanks a bunch!
User avatar
Matt
Posts: 9686
Joined: Sun Jan 04, 2004 5:37 pm
Location: Gotham City SAR, Wyld-Lands of the Lotus People, Dominionist PetroConfederacy of Saudi Canadia

Re: "How do I ZScript?"

Post by Matt »

Is there a way to tell if a specific lump has been loaded? (e.g., SHT2A0)
User avatar
ZZYZX
 
 
Posts: 1382
Joined: Sun Oct 14, 2012 1:43 am
Location: Ukraine

Re: "How do I ZScript?"

Post by ZZYZX »

For images use TexMan.CheckForTexture("something", TexMan.TYPE_Any).Exists();
For everything else use Wads.CheckNumForName("something", namespace, -1, false).
Namespace:

Code: Select all

	enum WadNamespace
	{
		ns_hidden = -1,

		ns_global = 0,
		ns_sprites,
		ns_flats,
		ns_colormaps,
		ns_acslibrary,
		ns_newtextures,
		ns_bloodraw,
		ns_bloodsfx,
		ns_bloodmisc,
		ns_strifevoices,
		ns_hires,
		ns_voxels,

		ns_specialzipdirectory,
		ns_sounds,
		ns_patches,
		ns_graphics,
		ns_music,

		ns_firstskin,
	}
P.S. direct wad reading when? I'm waiting to implement model-based collision in CanCollideWith for few months already. :/
User avatar
Nash
 
 
Posts: 17342
Joined: Mon Oct 27, 2003 12:07 am
Location: Kuala Lumpur, Malaysia

Re: "How do I ZScript?"

Post by Nash »

ZZYZX wrote: P.S. direct wad reading when? I'm waiting to implement model-based collision in CanCollideWith for few months already. :/
Yo that would be sick! It would help a lot with level design, artists can create static meshes that would just be too cumbersome to create with the BSP!

Return to “Scripting”