"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: 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 »

Xaser wrote:
ZZYZX wrote:Non-DECORATE-like features are not stable and not recommended to use, especially for a newbie.
Where is this idea coming from? What features in the current release build of GZDoom are considered "not stable and not recommended to use"?
I'm assuming "all ZScript not in the latest release"
User avatar
ZZYZX
 
 
Posts: 1383
Joined: Sun Oct 14, 2012 1:43 am
Location: Ukraine

Re: "How do I ZScript?"

Post by ZZYZX »

Xaser wrote:
ZZYZX wrote:Non-DECORATE-like features are not stable and not recommended to use, especially for a newbie.
Where is this idea coming from? What features in the current release build of GZDoom are considered "not stable and not recommended to use"?
Event handlers, menus, statusbar (if any yet).
Especially event handlers. They are somewhat fixed compared to the very first merged version, but render part is still not decided.
Menus are somewhat complete but still subject to random modification according to what Graf said about devbuilds.
User avatar
Jaxxoon R
Posts: 772
Joined: Sun May 04, 2014 7:22 pm

Re: "How do I ZScript?"

Post by Jaxxoon R »

So uh... is there a way to get a parent actor's pitch? It's probably one of the zscript actor functions that does it, but there's so many that I don't know where to look. I was thinking of giving a disc-shaped flatsprite projectile some depth using warped actors. For one of them I was simply using A_Warp and the COPYPITCH and it works really well for that one, but for the second I'll need to roll it to match the parent's pitch.
User avatar
ZZYZX
 
 
Posts: 1383
Joined: Sun Oct 14, 2012 1:43 am
Location: Ukraine

Re: "How do I ZScript?"

Post by ZZYZX »

You might want to use either my or Nash's code from this page that applies angle+pitch rotation to a flatsprite. It uses sector floor angle, but changing it to use angle/pitch variables from an actor is straightforward.
Also, parent's angles are received using master.angle/master.pitch/master.roll/whatever. Or target, or tracer, whatever you use for storing the parent pointer.
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 »

If I only need precision within 1 degree, but for possibly dozens of actors polling multiple times every tic, is it worth doing a lookup table for sine and cosine values? (I'm trying to keep a certain object directly in front of another at a fixed distance, or in other cases calculating a movement trajectory or a position relative to someone's FOV... well a lot of things really)
User avatar
Xaser
 
 
Posts: 10772
Joined: Sun Jul 20, 2003 12:15 pm

Re: "How do I ZScript?"

Post by Xaser »

ZZYZX wrote:Event handlers, menus, statusbar (if any yet).
I think the sentiment we ought to be expressing is "try to shy away from dev builds," then. "Non-DECORATE-like features" seemingly refers to a wide range of features (custom functions, structs, iterators, etc.) which are stable in the latest official build, and we certainly don't want to be discourage use and exploration of those.
User avatar
ZZYZX
 
 
Posts: 1383
Joined: Sun Oct 14, 2012 1:43 am
Location: Ukraine

Re: "How do I ZScript?"

Post by ZZYZX »

Yes. Sorry for the bad wording.
User avatar
Xaser
 
 
Posts: 10772
Joined: Sun Jul 20, 2003 12:15 pm

Re: "How do I ZScript?"

Post by Xaser »

It's cool -- we're on the same page, so all's well. I point these things out not to be a meanie-butt (though it probably comes across that way sometimes D:) but because we're kinda in that critical early phase where the adoption rate hasn't really taken off yet. I don't think ZScript's at any particular risk, but every bit helps.

*reminds self to continue working on his ZScript projects at some point.*
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 know EventHandlers are new and still subject to change, and my grasp of them is very basic at this point anyway, but could I ask for help in making an event that plays with a keypress? For years now, I did this:
KEYCONF:

Code: Select all

addmenukey "Taunt" taunt
alias taunt "pukename MGTaunt"
ACS:

Code: Select all

script "MGTaunt"(void)
	{PlaySound(0,"*taunt",CHAN_VOICE);}
...and everything I can convert from ACS to ZScript is another victory in my book.
User avatar
Major Cooke
Posts: 8144
Joined: Sun Jan 28, 2007 3:55 pm
Preferred Pronouns: He/Him
Location: QZDoom Maintenance Team

Re: "How do I ZScript?"

Post by Major Cooke »

ZZYZX seriously needs to write something about that in the wiki, for whatever is good to go. Everything else it's understandable that they remain undocumented, a la the rendering stuff, since they're bound to change.
User avatar
Nash
 
 
Posts: 17394
Joined: Mon Oct 27, 2003 12:07 am
Location: Kuala Lumpur, Malaysia

Re: "How do I ZScript?"

Post by Nash »

Ed:

Download this file [ https://mantis.zdoom.org/file_download. ... 3&type=bug ] or if hot-linking doesn't work, go here and scroll down to the comments and download sprint key.pk3 [ https://mantis.zdoom.org/view.php?id=362 ]

(PS don't mind the bug thread, the bug is already fixed with the latest devbuilds, well at least from all my testing)

The jist of it is, you now bind your control to "event xxx" or "netevent xxx" (should be self-explanatory which is which I hope). You then create an EventHandler that checks for those things. Just look inside sprint key.pk3.

I forgot to setup a MENUDEF for it in my example WAD, so you have to bind the key yourself. Open the console and type bind Shift "netevent SprintKeyHandler". In a real project, you'd it up in the Controls menu in MENUDEF, or KEYCONF or whatever.

You must setup any event handlers you want to be enabled inside the MAPINFO. You can add as many EventHandlers as you want inside MAPINFO, it's not limited to just one.
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 »

Excellent, thank you! I've got a working EventHandler right now that replaces my old ACS ENTER script, but I was less certain about where to go from there on more complex things. Thanks again!
User avatar
Nash
 
 
Posts: 17394
Joined: Mon Oct 27, 2003 12:07 am
Location: Kuala Lumpur, Malaysia

Re: "How do I ZScript?"

Post by Nash »

Graf Zahl wrote:Do I understand this correctly that you cannot access the fields of a function return value directly?

Code: Select all

class A : ZombieMan
{

    Vector2 v2;

    Vector2 GetVec2(void)
    {
        return v2;
    }

    void DoSomething(void)
    {
        Vector2 cool;
        Vector3 blah;

        cool = GetVec2();

        // not possible
        blah = (GetVec2().X, GetVec2().Y, 0);

    }

}
Correct. This doesn't work. Bug or not possible?
User avatar
Xaser
 
 
Posts: 10772
Joined: Sun Jul 20, 2003 12:15 pm

Re: "How do I ZScript?"

Post by Xaser »

@Nash: While this indeed seems like a bug (and therefore worth fixing for sure), it's worth emphasizing that for your particular case, it's better to keep the local variable so you don't have the overhead of calling the get function (BumiHandler._W_GetWind(), in your proper case) twice.
User avatar
Nash
 
 
Posts: 17394
Joined: Mon Oct 27, 2003 12:07 am
Location: Kuala Lumpur, Malaysia

Re: "How do I ZScript?"

Post by Nash »

Alright, noted... just how expensive is calling the global thinker, by the way? Since the code only does the Init once and never again after that...

Return to “Scripting”