"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
Matt
Posts: 9663
Joined: Sun Jan 04, 2004 5:37 pm
Location: Gotham City SAR, Wyld-Lands of the Lotus People, Dominionist PetroConfederacy of Saudi Canadia

Re: ZScript-only "How do I..." thread

Post by Matt »

They never needed to be, nor should have been, in quotes when defining a state.

Xaser: Yes, that was what I had been asking - I was still stuck in the bad old days when A_CheckSight could only check if the calling actor was within sight of a player!

Thanks for that and the BlockThingsIterator!
Last edited by Matt on Tue Jan 31, 2017 6:17 pm, edited 1 time in total.
User avatar
ibm5155
Posts: 1268
Joined: Wed Jul 20, 2011 4:24 pm

Re: ZScript-only "How do I..." thread

Post by ibm5155 »

is there a way to convert an enum to int in zscript?
like:

enum onoff
{
off,
on,
};
onoff XX;
....
XX = CheckSight(...); // XX = (int) CheckSight(...); doesn't work :S
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 47962
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: ZScript-only "How do I..." thread

Post by Graf Zahl »

CheckSight returns a bool, so use a bool variable and not some homegrown substitute.

Enums are not fully implemented, so you'll run into some issues. For the time being, do not use enum type variables, it may well be that your mod may break once they are being made functional.
User avatar
Matt
Posts: 9663
Joined: Sun Jan 04, 2004 5:37 pm
Location: Gotham City SAR, Wyld-Lands of the Lotus People, Dominionist PetroConfederacy of Saudi Canadia

Re: ZScript-only "How do I..." thread

Post by Matt »

Are A_Explode, A_RadiusThrust and A_RadiusGive equivalent to BlockThingsIterator or ThinkerIterator or something else entirely in terms of how they go through what things should be affected?
User avatar
Xaser
 
 
Posts: 10771
Joined: Sun Jul 20, 2003 12:15 pm

Re: ZScript-only "How do I..." thread

Post by Xaser »

They all use BlockThingsIterator internally (the native-code version of it, at least).

The wiki does currently have a big fat warning about BlockThingsIterator being less performant than the other iterator types, but that's really only gonna be an issue if you use a crazy-large radius... or play somebody's ridiculous map that crams 10,000 zombiemen in a 128-unit radius. :P


[It's probably worth also-disclaiming that the scripted versions of things do have a lot more overhead than their native counterparts, but that again only matters if you're really trying to push the limits for some wacky reason.]
User avatar
Matt
Posts: 9663
Joined: Sun Jan 04, 2004 5:37 pm
Location: Gotham City SAR, Wyld-Lands of the Lotus People, Dominionist PetroConfederacy of Saudi Canadia

Re: ZScript-only "How do I..." thread

Post by Matt »

I really should do something about that mancubus fireball in Hideous Destructor that explodes every see frame... and the chaingun bullets that all A_RadiusGive an inventory flag... and... yeah...


Another question: I want to do something like this:

Code: Select all

actor blahblahblah=spawn("Blah",self.pos);
blahblahblah.blahblah=5;
where "blahblah" is a variable defined in "Blah". But I keep getting an error that says it can't be done.

Is there any way to make it "known" to the calling actor somehow, so I don't have to find some existing unused property (accuracy, stamina, etc.) to exploit?
User avatar
Ed the Bat
Posts: 3060
Joined: Thu May 03, 2012 1:18 pm
Operating System: Windows 10/8.1/8/201x 64-bit
OS Test Version: No (Using Stable Public Version)
Graphics Processor: nVidia with Vulkan support
Location: Maryland, US

Re: ZScript-only "How do I..." thread

Post by Ed the Bat »

You made blahblahblah an actor, when you should make it a Blah, so the caller knows it has the blahblah variable in it.
User avatar
Matt
Posts: 9663
Joined: Sun Jan 04, 2004 5:37 pm
Location: Gotham City SAR, Wyld-Lands of the Lotus People, Dominionist PetroConfederacy of Saudi Canadia

Re: ZScript-only "How do I..." thread

Post by Matt »

So I could just define any "Blah" and do this?

Code: Select all

Blah blahblahblah=spawn("Blah"...


Even then it doesn't quite work for some other things I have in mind, though - like a static function that can be called by a fastprojectile or a monster or a puff.

EDIT: I think I have my answer in here with "let". Thanks for the help anyway, Ed!
Last edited by Matt on Tue Jan 31, 2017 8:57 pm, edited 1 time in total.
User avatar
Ed the Bat
Posts: 3060
Joined: Thu May 03, 2012 1:18 pm
Operating System: Windows 10/8.1/8/201x 64-bit
OS Test Version: No (Using Stable Public Version)
Graphics Processor: nVidia with Vulkan support
Location: Maryland, US

Re: ZScript-only "How do I..." thread

Post by Ed the Bat »

Static functions can be called from anyone, though. I don't see how making blahblahblah into a Blah instead of an Actor (Blah is a descendant of Actor anyway, right? It'll have everything Actor has) would impede that.

"Let" is a way to automatically determine the type. In the cases that it works, it's a great shortcut. I've run into a few edge cases where it didn't give me what I truly wanted, though, so there's still merit to manually typing your objects in some instances.
User avatar
Major Cooke
Posts: 8055
Joined: Sun Jan 28, 2007 3:55 pm

Re: ZScript-only "How do I..." thread

Post by Major Cooke »

It fucked me over a couple times myself, though they were rare. I never could figure out what the hell was going on because it crashed a long time ago when trying to get the class but I think it's been fixed since then.
User avatar
Matt
Posts: 9663
Joined: Sun Jan 04, 2004 5:37 pm
Location: Gotham City SAR, Wyld-Lands of the Lotus People, Dominionist PetroConfederacy of Saudi Canadia

Re: ZScript-only "How do I..." thread

Post by Matt »

I'm trying to see if I can do a really bare-bones stripped-down actor for debris.

What is it that's called to keep something on a moving platform (some of which lower faster than a thing spawned in midair would drop, but the things on them lower without incident anyway) or conveyer?

Also, is there a ZScript function that grabs the first actor that's blocking a line extending from one point to another? A_CheckLOF is aggravating to use for reasons.


EDIT: Is there a built-in way to sort an array (alphabetical, descending, etc.), or does that need to be coded explicitly?
Beed28
Posts: 595
Joined: Sun Feb 24, 2013 4:07 pm
Location: United Kingdom

Re: ZScript-only "How do I..." thread

Post by Beed28 »

Question; is it possible for an actor using A_Explode to hurt and only hurt actors that have the +OLDRADIUSDMG flag?
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 47962
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: ZScript-only "How do I..." thread

Post by Graf Zahl »

No. For that you'd have to replace P_RadiusAttack, i.e. rewrite that function to do what you want.
User avatar
kodi
 
 
Posts: 1351
Joined: Mon May 06, 2013 8:02 am

Re: ZScript-only "How do I..." thread

Post by kodi »

I want an actor to store the player in a custom pointer when he or she walks up to it and presses the Use key. Preferably without messing with the standard activation flags if that's possible.

Spoiler:

The above (definition for the SwitchableDecoration actor) didn't give me any clue, but perhaps it might help someone else help me :)
User avatar
ibm5155
Posts: 1268
Joined: Wed Jul 20, 2011 4:24 pm

Re: ZScript-only "How do I..." thread

Post by ibm5155 »

About This
Graf wrote:No bug here. If you want to get reliable results for invisible things you have to pass SF_IGNOREINVISIBILITY for the flags parameter.

First: what the heck is SF_IGNOREINVISIBILITY that I cannot even find into the fórum/wiki neither the source code O__________O ????

Second: Here's the updated test wad: https://1drv.ms/u/s!AurELTq1jbljkZBjQg-M6YrdvJR79A, each skill has a different object, and as you can see, both acs and zscript version of checksight return different patterns in some cases.
So I then repeat my question, how do I make the zscript code return the same thing as the acs code without calling acs scripts???????

Also the code is here in case you do not want to download the test wad

Code: Select all

class SightChecker : Actor
{
   Default
   {
   }
   Actor Act;
   
   States
   {
      Spawn:   
      TNT1 A 1;       
      TNT1 A 1 FindActors();
      goto Myloop;
      
      Myloop:
      TNT1 A 1 ACS_Execute(2,0,CheckVisibility());
      Goto Myloop;

   
   }
   void FindActors()// or FindLightSourcePointers
   {
      ActorIterator It;
      class<Actor> _type = "Actor";
      It = ActorIterator.create(666,_type);
      Act = It.Next();
   }
   
   bool CheckVisibility()
   {
      return CheckSight(Act);
   }
}


patterns found:
MAPSPOT: return as random(0,1); On acs it's Always 1
HATETARGET: return 0 on the first tic and later Always 1. On acs it's Always 1
CANDLESTICK return 0 on the first tic and later Always 1. On acs it's Always 1
INVISIBLEBRIDGE: return 0 on the first tic and later Always 1. On acs it's Always 1

EDIT: Maybe on the first tic it's zero because the zscript didn't send his checksight value at that tic

Return to “Scripting”