"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
User avatar
Xaser
 
 
Posts: 10772
Joined: Sun Jul 20, 2003 12:15 pm
Contact:

Re: "How do I ZScript?"

Post by Xaser »

Nash wrote: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...
It still uses a ThinkerIterator to retrieve the global object after it's been Init'd. There's that plus function call overhead, which currently isn't cheap in scripting-land. Something worth keeping in mind if this function of yours is meant to be called many times in a loop.
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 »

Is there something about SetXYZ I should know about before trying to use it?

I've noticed some problems with it both here and in an unpublished attempt at a ZScript take on this (basically: a looping 1-length spawn state that constantly calls A_SetXYZ(master.pos+48) as long as the master exists and is alive).

In the former, the clip seems not to know where the floor is when it falls, and ends up hanging in midair and incapable of being picked up. (try the (unfixed) example on Map01 by going down to the bottom of the big starting room and killing a zombie on a higher elevation so the clip spawns somewhere on that triangular staircase. Generally works fine if the player is on even ground with or higher than the midway point the clip is being SetXYZ'd to.)

In the latter, the sprite appears where it should but many of them cannot be hit at all.

Is there an additional step that needs to be taken after a SetXYZ call for the engine to know which sector the actor is in, or is this an actual GZDoom bug?
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49067
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: "How do I ZScript?"

Post by Graf Zahl »

Xaser wrote:
Nash wrote: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...
It still uses a ThinkerIterator to retrieve the global object after it's been Init'd. There's that plus function call overhead, which currently isn't cheap in scripting-land. Something worth keeping in mind if this function of yours is meant to be called many times in a loop.
Here, the same applies as for every piece of code. If you can store the result of a costly operation in a local variable, do so. It may not register directly as performance loss but it will add up if done repeatedly.
Vaecrius wrote:Is there something about SetXYZ I should know about before trying to use it?

Yes, you have to be careful. This function only alters the position but does not alter the blockmap links. This can cause some serious glitches.
If you want to change an actor's position in the world, use SetOrigin. SetXYZ is only for some special cases where the actor either isn't linked into the blockmap or for temporarily changing its position and restoring the old one later.
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 »

Thanks! I hadn't noticed any problems when using it for a purely aesthetic sprite actor where the blockmap was irrelevant, but I just chalked it up to not having anything to notice.

(Also thanks for explaining what SetOrigin did... I kept thinking it had something to do with the actor's starting position when it first spawned!)
User avatar
Major Cooke
Posts: 8175
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 »

Graf, since some time has passed since you implemented the strife dialogue into zscript, I figured now might be the time to ask since you weren't sure back then:

How can we possibly access the player's inventory safely and sanely through the menu? If strife conversations can do it, there certainly should be some sane method to do this.

I'd very much like to figure out a way for D4D's upgrade menus to not rely on the hackery that is applying a change to cvar and then letting a custominventory yank every single one of those cvars just to update the player's inventory. And it'd certainly (hopefully) be one step in the right direction towards multiplayer support (out of god knows how many... Yes, I'm aware networking capabilities are totes fucked right now, but still.)
User avatar
Nash
 
 
Posts: 17439
Joined: Mon Oct 27, 2003 12:07 am
Location: Kuala Lumpur, Malaysia
Contact:

Re: "How do I ZScript?"

Post by Nash »

Code: Select all

    virtual void DrawGold()
    {
        if (mShowGold)
        {
            let coin = players[consoleplayer].ConversationPC.FindInventory("Coin");
            let icon = GetDefaultByType("Coin").Icon;
            let goldstr = String.Format("%d", coin != NULL ? coin.Amount : 0);
            screen.DrawText(SmallFont, Font.CR_GRAY, 21, 191, goldstr, DTA_320x200, true, DTA_FillColor, 0, DTA_Alpha, HR_SHADOW);
            screen.DrawTexture(icon, false, 3, 190, DTA_320x200, true, DTA_FillColor, 0, DTA_Alpha, HR_SHADOW);
            screen.DrawText(SmallFont, Font.CR_GRAY, 20, 190, goldstr, DTA_320x200, true);
            screen.DrawTexture(icon, false, 2, 189, DTA_320x200, true);
        }

    }
 
ConversationPC is probably the field you want? This was taken from zscript/menu/conversation.txt.
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 »

Why is SpecialMissileHit not a bool? Are there other possibilities besides -1 and 1 not mentioned in the wiki?
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 »

Am I able to change type-specific DamageFactors for an actor, so as to modify only how much damage certain types, or "elements", will do to the actor?
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 »

How do you even access DamageFactors anyway? I could never find anything even close to doing that.


Also, why don't constant arrays work? I copied the wiki example verbatim and get

Code: Select all

Unexpected 'static'
Expecting end of file or 'include' or 'extend' or 'class' or 'struct' or 'const' or 'enum'
(note: the sequence of words "Can be defined in functions or in the namespace" is complete incomprehensible gibberish to me.)

EDIT: Got it working inside a function but this "in the name space" option is still gibberish to me.
Last edited by Matt on Fri Mar 03, 2017 1:35 am, edited 2 times in total.
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 »

DamageFactor is a property of Actor, and it's not read-only, so unless there's a nuance I'm not aware of, DamageFactor=<number> is valid. But this would only affect the 'global' DamageFactor of the actor, not anything damagetype-specific.
User avatar
Major Cooke
Posts: 8175
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 »

Vaecrius wrote:Why is SpecialMissileHit not a bool? Are there other possibilities besides -1 and 1 not mentioned in the wiki?
1 means pass through.
0 means always die.
-1 means use default behavior (ripper missiles for example will rip.)
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49067
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: "How do I ZScript?"

Post by Graf Zahl »

Vaecrius wrote:Why is SpecialMissileHit not a bool? Are there other possibilities besides -1 and 1 not mentioned in the wiki?
According to actor.h:

// Returns -1 for normal behavior, 0 to return false, and 1 to return true.
// I'm not sure I like it this way, but it will do for now.
// (virtual on the script side only)

p_map.cpp:

switch (tm.thing->SpecialMissileHit(thing))
{
case 0: return false;
case 1: return true;
default: break;
}

This reads as:
0: move is blocked, do not explode
1: move is not blocked, do not explode
-1: perform all the regular checks for a missile

Note that several checks for non-collision have already been performed when this gets called so you cannot force an explosion on a non-solid object.
User avatar
Major Cooke
Posts: 8175
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 »

Note to self, do NOT put a "Cvar" type variable on a player that's in the actor scope space!
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- »

Is there a way to access an actor's bloodcolour property? The wiki references 'bloodcolor' on this page. but whenever I plug that into some code it just errors out referencing an unknown identifier.
User avatar
Major Cooke
Posts: 8175
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 »

Graf temporarily removed access to bloodcolor so he could change it, but it's back now. Update your devbuild.

Also, that mask isn't needed anymore, I don't think.
Locked

Return to “Scripting”