"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!)
Locked
D2JK
Posts: 543
Joined: Sat Aug 30, 2014 8:21 am

Re: "How do I ZScript?"

Post by D2JK »

I thought this was going to be simple enough, but I'm getting some errors when attempting to create a string array (in an anonymous function):

Code: Select all

string S[3];
S = { "S1" , "S2" , "S3" };
-> Unexpected '{'

Code: Select all

string S[3] = { "S1" , "S2" , "S3" };
-> Compound initializer not implemented yet

Initializing the variables one at a time seems to work (S = x;), but shouldn't it be possible to initialize multiple variables simultaneously?
User avatar
Gutawer
Posts: 469
Joined: Sat Apr 16, 2016 6:01 am
Preferred Pronouns: She/Her

Re: "How do I ZScript?"

Post by Gutawer »

Your syntax is correct, it's just that as the error says, the ability to do that just hasn't been implemented yet.
D2JK
Posts: 543
Joined: Sat Aug 30, 2014 8:21 am

Re: "How do I ZScript?"

Post by D2JK »

Ok. I thought I was doing something wrong, as dynamic arrays and their functions, which I consider much fancier features, are already implemented.
User avatar
Zergeant
Posts: 107
Joined: Tue Aug 31, 2010 7:19 am
Location: Sweden

Re: "How do I ZScript?"

Post by Zergeant »

Another problem I've been struggling with is jumping inside a weapon class. Now I'm trying to check a few variables and execute different stuff depending on what circumstances.

Code: Select all

Fire:
	SOWN A 1
	{
	switch(invoker.loadedShells)
	 {
		case 4:
		case 2:
			if(invoker.rightReady)
				return ResolveState("FireRight");
			break;
		case 3:
		case 1:
			if(invoker.leftReady)
				A_Overlay(2, "FireLeft");
			break;
		case 0:
			return ResolveState("Reload");
	 }
	}

	Goto Ready;
The offending lines would be 'return ResolveState("FireRight");', tossing a "Return type mismatch" error which is really hard to debug.
Blue Shadow
Posts: 4949
Joined: Sun Nov 14, 2010 12:59 am

Re: "How do I ZScript?"

Post by Blue Shadow »

You need a return at the end of the function, outside of the switch statement.
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: "How do I ZScript?"

Post by Matt »

At this point it seems better not to try to match up all the returns, but instead use SetStateLabel("statelabel") and then return when/if needed... I just cringe now whenever I have to go back to my old Decorate anon function code and I see all those returns, yes they are unmaintainably hard to keep track of (if still significantly better than the old A_Jump* sequences, it's only more unmaintainable now because ZScript is letting us do much more complex things to begin with)
User avatar
Zergeant
Posts: 107
Joined: Tue Aug 31, 2010 7:19 am
Location: Sweden

Re: "How do I ZScript?"

Post by Zergeant »

Blue Shadow wrote:You need a return at the end of the function, outside of the switch statement.
That did it, thank you.
User avatar
Ed the Bat
Posts: 3060
Joined: Thu May 03, 2012 1:18 pm
Graphics Processor: nVidia with Vulkan support
Location: Maryland, US
Contact:

Re: "How do I ZScript?"

Post by Ed the Bat »

Is there a way I can check what action pointer a given state has? Or, at the very least, if the action pointer has been altered by DeHackEd? The closest I can get right now is to check the state's bDehacked boolean, but that just tells me if the whole state has been altered, and not how. It would even pass true if the state's sprite, frame, next state, or duration were modified, so it's almost useless for this.
User avatar
Nash
 
 
Posts: 17433
Joined: Mon Oct 27, 2003 12:07 am
Location: Kuala Lumpur, Malaysia
Contact:

Re: "How do I ZScript?"

Post by Nash »

This is seriously blocking my ability to do play-testing and driving me nuts!!!! Why does my custom Tick() stuff continue to run even when I've frozen the game using the "freeze" console command? Please tell me there's a way to freeze my Actor's Tick() when the game is actually frozen!

The animation States are frozen, but the CODE running in the Tick() does not! So if I have a little int counter++ thing running in Tick(), it will continue to increment even when the game is frozen!
User avatar
Mikk-
Posts: 2274
Joined: Tue Jun 30, 2009 1:31 pm
Location: Somewhere off Kanagawa

Re: "How do I ZScript?"

Post by Mikk- »

Couldn't you just check if the world is frozen in the Tick function?
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: "How do I ZScript?"

Post by Matt »

I always have the following 2 lines at the start of any custom Tick():

Code: Select all

ClearInterpolation();
if(globalfreeze||level.Frozen) return;
User avatar
Nash
 
 
Posts: 17433
Joined: Mon Oct 27, 2003 12:07 am
Location: Kuala Lumpur, Malaysia
Contact:

Re: "How do I ZScript?"

Post by Nash »

Vaecrius wrote:I always have the following 2 lines at the start of any custom Tick():

Code: Select all

ClearInterpolation();
if(globalfreeze||level.Frozen) return;
Hmmm, strange that this has to be accounted for manually by the modder but thanks!
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: "How do I ZScript?"

Post by Matt »

Sometimes you could be ticking something that should run with the player so it would not be appropriate then (since the player is never affected by freeze).

Or sometimes you might have a mix: a monster that latches onto a player might update its relative position even when in freeze mode, but otherwise not do anything.
(This might get more complex with weapons)
User avatar
Nash
 
 
Posts: 17433
Joined: Mon Oct 27, 2003 12:07 am
Location: Kuala Lumpur, Malaysia
Contact:

Re: "How do I ZScript?"

Post by Nash »

Vaecrius wrote:Sometimes you could be ticking something that should run with the player so it would not be appropriate then (since the player is never affected by freeze).

Or sometimes you might have a mix: a monster that latches onto a player might update its relative position even when in freeze mode, but otherwise not do anything.
(This might get more complex with weapons)
Ahhh that makes sense and come to think of it, it's actually amazing that ZScript actually lets you have full control this area, instead of forcing you within a certain sandbox, so to speak. Great stuff!
User avatar
JPL
 
 
Posts: 523
Joined: Mon Apr 09, 2012 12:27 pm
Contact:

Re: "How do I ZScript?"

Post by JPL »

Is there a way I can use TexMan.CheckForTexture to determine if a sky texture has been defined in a PWAD versus the IWAD? A bit more context on what I'm trying to do here. I notice there are lots of settings you can pass in for the second and third arguments for CheckForTexture (such as TEX_FirstDefined, TEXMAN_Overridable etc) and it's not clear from looking at the FTextureManager source code what they all do.
Locked

Return to “Scripting”