"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
Major Cooke
Posts: 8215
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 »

Don't use damagefactors in that case. You'll want to override TakeSpecialDamage and modify the damage yourself or DamageMobj itself.
User avatar
Major Cooke
Posts: 8215
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 »

Seismos wrote:Hello peeps, I have an interesting question: "When do I ZScript?"

If I have a goal I that want to accomplish, and there are multiple ways of doing so, under what circumstance should I use ZScript and when should I use, for example, ACS?
I say immediately but meh. Problem is, you have to find that out for yourself on how you want to do it. Also it currently doesn't replace everything ACS can do, but it can already do a massive amount of it.
User avatar
krokots
Posts: 296
Joined: Tue Jan 19, 2010 5:07 pm

Re: "How do I ZScript?"

Post by krokots »

Major Cooke wrote:Don't use damagefactors in that case. You'll want to override TakeSpecialDamage and modify the damage yourself or DamageMobj itself.
Something like this? Inside Imp class (all classes have int user_fireresist)

Code: Select all

	override int TakeSpecialDamage (Actor inflictor, Actor source, int damage, Name damagetype)
	{
		if (damagetype == 'Fire')
		damage-=(damage*user_fireresist/100);
		super.takeSpecialDamage(inflictor, source, damage, damagetype);
		return damage;
	}
I have two imp classes, one have balls (yes) that have DamageType "Fire". Then I set "user_fireresist" of the second one to 100.
But it doesn't work, second imp still take damage from fireballs, something wrong with Name of damagetype?


OOOKKAY never mind, of course I had to do some stupid mistake. Like actually I forgot to change the imp balls in the first class...
So it works! Thanks again!
User avatar
Major Cooke
Posts: 8215
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 »

Also you don't need to have the user_ append anymore if you don't want to.
User avatar
ZZYZX
 
 
Posts: 1384
Joined: Sun Oct 14, 2012 1:43 am
Location: Ukraine

Re: "How do I ZScript?"

Post by ZZYZX »

Seismos wrote:Hello peeps, I have an interesting question: "When do I ZScript?"

If I have a goal I that want to accomplish, and there are multiple ways of doing so, under what circumstance should I use ZScript and when should I use, for example, ACS?
Use ZScript whenever it's easier than ACS. And the other way around. The same about DECORATE.
Map scripts (things like "open door X when something Y died") are better to keep as ACS. On the other side, complex ACS monster scripting that's called from DECORATE definitely should be replaced with ZScript and the old DECORATE+ACS code burned in fires. Also, small one-line actors are pretty ok if you write them in DECORATE.
User avatar
Xaser
 
 
Posts: 10774
Joined: Sun Jul 20, 2003 12:15 pm

Re: "How do I ZScript?"

Post by Xaser »

While I agree with the ACS bit, I don't understand the DECORATE part. ZScript is a superset of its features, and quite literally obsoletes it.
User avatar
Major Cooke
Posts: 8215
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 »

Yeah, don't mix ZScript with Decorate.
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 »

On the topic of ZScript vs (or alongside) ACS... is there a way to call ACS scripts upon another object? For instance, if I try to do this:

Code: Select all

Actor itd=Spawn("ZombieMan");
itd.ACS_Execute(1);
... I get the error 'Unknown Function ACS_Execute'.
So far, I've been working around this by giving the actor a CustomInventory that, in turn, calls ACS for it. I feel like there has to be a better way, though.
User avatar
ZZYZX
 
 
Posts: 1384
Joined: Sun Oct 14, 2012 1:43 am
Location: Ukraine

Re: "How do I ZScript?"

Post by ZZYZX »

Xaser wrote:While I agree with the ACS bit, I don't understand the DECORATE part. ZScript is a superset of its features, and quite literally obsoletes it.
For whatever reason people may be more comfortable with writing DECORATE.
For example, they want DoomEdNums in the script and not in MAPINFO.
I don't think it's correct to tell people that their stylistic habits are wrong and they should code the other way instead, unless it violates common sense severely.
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

Re: "How do I ZScript?"

Post by Matt »

Seismos wrote:Hello peeps, I have an interesting question: "When do I ZScript?"

If I have a goal I that want to accomplish, and there are multiple ways of doing so, under what circumstance should I use ZScript and when should I use, for example, ACS?
With ACS, I'm going by "whenever it can be done in ZScript without a gross hack that would likely have to be completely rewritten once the needed feature is in place, because I am fucking sick of having to maintain this stupid separate pre-compiled blob". (This has not happened to the player code in Hideous Destructor mostly for the reason that I really don't want to touch that gigantic knot of a mess until I can take a week off work to do nothing else or something - which is, of course, related to/exacerbated by the blob problem.)

With DECORATE, for now I'm not converting anything to ZScript if I'm not intent on changing it to use something that uses ZScript, unless there's an obvious and immediate reward in maintainability or efficiency. (There are surprisingly many, per my previous posts here about performance and debris actors.)

Starting anything new, might as well use ZScript for everything until you run into something that only ACS or SBARINFO can do at the moment. A lot of projects going through upgrades now would be mixing ZS with DEC but that seems obviously suboptimal - it's like reading poetry in translation when you're natively fluent in the original language (and are not just proofreading the translation).
User avatar
Xaser
 
 
Posts: 10774
Joined: Sun Jul 20, 2003 12:15 pm

Re: "How do I ZScript?"

Post by Xaser »

ZZYZX wrote:I don't think it's correct to tell people that their stylistic habits are wrong and they should code the other way instead, unless it violates common sense severely.
Writing new DECORATE in a project that contains ZScript is certainly a common sense violation. Having both in a project is totally sensible if code is in the process of being transitioned over to ZScript or if all the prior existing DECORATE stuff "works good enough" and there's not really a need to convert it (see Vaecrius's second paragraph), but for modders/projects that have made the jump to ZScript, the practice of reverting back to DECORATE for select bits is an exceptionally bizarre thing to encourage.


[To clarify, I'm not trying to say "all modders ZSCRIPT NOW or you're FUCKIN' UP"; transitioning isn't too hard IMO, but it does take a nonzero amount of re-learning. Just as long as folks aren't un-learning after they do it. :P ]
User avatar
Major Cooke
Posts: 8215
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 »

Unfortunately, rust is a thing. :P
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 »

Will waiting on my ACS_Execute question, I thought of another question. What is the best way to check if a string variable is empty or not? if(variable!=null) throws an error.
User avatar
Major Cooke
Posts: 8215
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 »

.length != 0 (or length()? Don't remember.)
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'll keep that in mind. Thanks!

Return to “Scripting”