ZScript Discussion

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
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49066
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: ZScript Discussion

Post by Graf Zahl »

The compiler is well capable of resolving an anonymous function with just a single function in it to call the inner function directly.
User avatar
Major Cooke
Posts: 8175
Joined: Sun Jan 28, 2007 3:55 pm
Preferred Pronouns: He/Him
Location: QZDoom Maintenance Team

Re: ZScript Discussion

Post by Major Cooke »

What about multiple functions inside of the anonymous function?
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49066
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: ZScript Discussion

Post by Graf Zahl »

In that case a VM script function needs to be created because a state can only hold one function pointer.
User avatar
Gutawer
Posts: 469
Joined: Sat Apr 16, 2016 6:01 am
Preferred Pronouns: She/Her

Re: ZScript Discussion

Post by Gutawer »

https://streamable.com/w9dcc
Should this be doable? Seems like it should be unintended, but I don't want to make a report on mantis since I'm not sure this is actually a bug. Done with this code, for testing:

Code: Select all

Class BreakEverythingMaybe : EventHandler {
	override void UiTick() {
		EventHandler.SendNetworkEvent("BreakEverything?");
	}
	
	override void NetworkProcess(ConsoleEvent e) {
		if (e.Name == "BreakEverything?") {
			ThinkerIterator spinnyIterator = ThinkerIterator.Create("Zombieman");
			Actor(spinnyIterator.Next()).angle += 1;
		}
	}
}
User avatar
ZZYZX
 
 
Posts: 1384
Joined: Sun Oct 14, 2012 1:43 am
Location: Ukraine
Contact:

Re: ZScript Discussion

Post by ZZYZX »

That's exactly what SendNetworkEvent is for.
User avatar
Xaser
 
 
Posts: 10772
Joined: Sun Jul 20, 2003 12:15 pm
Contact:

Re: ZScript Discussion

Post by Xaser »

Quick question: can we define const arrays in the namespace yet? The wiki claims so, but the example provided (and a few other permutations I tried) causes a syntax error when used outside of a function.
User avatar
Major Cooke
Posts: 8175
Joined: Sun Jan 28, 2007 3:55 pm
Preferred Pronouns: He/Him
Location: QZDoom Maintenance Team

Re: ZScript Discussion

Post by Major Cooke »

Meant anonymous functions, not namespace. Fixed.

Anyway, no, it's not possible right now outside of functions. That or my memory is fried.
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49066
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: ZScript Discussion

Post by Graf Zahl »

I have added static const arrays inside classes. Unless something broke they should work. The initial problem here was the memory organization as implemented by Randi. I had to refactor a lot of the data into static memory before I could make these arrays work without becoming a drag, that's wgy it took longer.
D2JK
Posts: 543
Joined: Sat Aug 30, 2014 8:21 am

Re: ZScript Discussion

Post by D2JK »

Would it be possible to extend the usable range of the AimTarget() function, or preferably, add a range option as a parameter? I'm using this function in my sniper rifle code, but its current maximum range is insufficient with distant targets.
Lavender Moon
Posts: 30
Joined: Thu May 21, 2015 5:33 am

Re: ZScript Discussion

Post by Lavender Moon »

How do you convert a String to a StateLabel? I need an array of state labels, and ZScript doesn't support arrays of StateLabels.
User avatar
Gutawer
Posts: 469
Joined: Sat Apr 16, 2016 6:01 am
Preferred Pronouns: She/Her

Re: ZScript Discussion

Post by Gutawer »

This is better suited for the "How do I ZScript?" (viewtopic.php?f=3&t=55073) thread, but to answer the question - you can use the ResolveState function, for example:

Code: Select all

ResolveState(<state string>)
Lavender Moon
Posts: 30
Joined: Thu May 21, 2015 5:33 am

Re: ZScript Discussion

Post by Lavender Moon »

Whoops, got this thread confused for that one. ResolveState doesn't work, BTW. It only accepts strings at compile time, not runtime.
User avatar
Major Cooke
Posts: 8175
Joined: Sun Jan 28, 2007 3:55 pm
Preferred Pronouns: He/Him
Location: QZDoom Maintenance Team

Re: ZScript Discussion

Post by Major Cooke »

Use a StateLabel instead of a String as the variable type.

Code: Select all

StateLabel next = "yourstatehere";
return ResolveState(next);
User avatar
Chl
Posts: 219
Joined: Sat Dec 05, 2015 2:18 pm

Re: ZScript Discussion

Post by Chl »

I've been out of the loop for over a year and now I'm trying to read up on what this is. But I'm no programmer so I can't really understand what I can do with this. So my question is, what can I do with ZS that wasn't possible before? And with that I mean stuff that affects gameplay/visuals/engine and that is not possible with ACS or decorate.
User avatar
Enjay
 
 
Posts: 26533
Joined: Tue Jul 15, 2003 4:58 pm
Location: Scotland
Contact:

Re: ZScript Discussion

Post by Enjay »

Sorry if this has been discussed already but there are 118 pages here.

I understand that on startup, ZScript is processed first, then DECORATE. What would happen if a ZScript actor made reference to a DECORATE actor in its definition (e.g. the ZScript actor spawned a DECORATE actor (say as a projectile), or had an inventory check for a DECORATE actor etc etc.)
Locked

Return to “Scripting”