"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.

Re: "How do I ZScript?"

Postby Xaser » Thu Mar 02, 2017 1:10 pm

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
Xaser
anarchivist
 
 
 
Joined: 20 Jul 2003

Re: "How do I ZScript?"

Postby Matt » Thu Mar 02, 2017 4:15 pm

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
Matt
Putting the XD into *xdeath since 2007
 
 
 
Joined: 04 Jan 2004
Location: Gotham City SAR, Wyld-Lands of the Lotus People, Dominionist PetroConfederacy of Saudi Canadia

Re: "How do I ZScript?"

Postby Graf Zahl » Thu Mar 02, 2017 4:40 pm

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
Graf Zahl
Lead GZDoom Developer
 
Joined: 19 Jul 2003
Location: Germany

Re: "How do I ZScript?"

Postby Matt » Thu Mar 02, 2017 5:15 pm

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
Matt
Putting the XD into *xdeath since 2007
 
 
 
Joined: 04 Jan 2004
Location: Gotham City SAR, Wyld-Lands of the Lotus People, Dominionist PetroConfederacy of Saudi Canadia

Re: "How do I ZScript?"

Postby Major Cooke » Thu Mar 02, 2017 7:29 pm

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
Major Cooke
The road to Hell is paved in the carrion she leaves behind.
 
Joined: 28 Jan 2007
Discord: Major Cooke#0846

Re: "How do I ZScript?"

Postby Nash » Fri Mar 03, 2017 12:11 am

Code: Select allExpand view

    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(SmallFontFont.CR_GRAY21191goldstrDTA_320x200trueDTA_FillColor0DTA_AlphaHR_SHADOW);
            
screen.DrawTexture(iconfalse3190DTA_320x200trueDTA_FillColor0DTA_AlphaHR_SHADOW);
            
screen.DrawText(SmallFontFont.CR_GRAY20190goldstrDTA_320x200true);
            
screen.DrawTexture(iconfalse2189DTA_320x200true);
        }

    }
 


ConversationPC is probably the field you want? This was taken from zscript/menu/conversation.txt.
User avatar
Nash
 
 
 
Joined: 27 Oct 2003
Location: Kuala Lumpur, Malaysia
Github ID: nashmuhandes
Operating System: Windows 10/8.1/8 64-bit
Graphics Processor: nVidia with Vulkan support

Re: "How do I ZScript?"

Postby Matt » Fri Mar 03, 2017 1:22 am

Why is SpecialMissileHit not a bool? Are there other possibilities besides -1 and 1 not mentioned in the wiki?
User avatar
Matt
Putting the XD into *xdeath since 2007
 
 
 
Joined: 04 Jan 2004
Location: Gotham City SAR, Wyld-Lands of the Lotus People, Dominionist PetroConfederacy of Saudi Canadia

Re: "How do I ZScript?"

Postby Ed the Bat » Fri Mar 03, 2017 2:07 am

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
Ed the Bat
I'm tired. I want to go home.
 
Joined: 03 May 2012
Location: Maryland, US

Re: "How do I ZScript?"

Postby Matt » Fri Mar 03, 2017 2:15 am

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 allExpand view
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 2:35 am, edited 2 times in total.
User avatar
Matt
Putting the XD into *xdeath since 2007
 
 
 
Joined: 04 Jan 2004
Location: Gotham City SAR, Wyld-Lands of the Lotus People, Dominionist PetroConfederacy of Saudi Canadia

Re: "How do I ZScript?"

Postby Ed the Bat » Fri Mar 03, 2017 2:17 am

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
Ed the Bat
I'm tired. I want to go home.
 
Joined: 03 May 2012
Location: Maryland, US

Re: "How do I ZScript?"

Postby Major Cooke » Fri Mar 03, 2017 5:58 am

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
Major Cooke
The road to Hell is paved in the carrion she leaves behind.
 
Joined: 28 Jan 2007
Discord: Major Cooke#0846

Re: "How do I ZScript?"

Postby Graf Zahl » Fri Mar 03, 2017 6:03 am

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
Graf Zahl
Lead GZDoom Developer
 
Joined: 19 Jul 2003
Location: Germany

Re: "How do I ZScript?"

Postby Major Cooke » Fri Mar 03, 2017 6:07 am

Note to self, do NOT put a "Cvar" type variable on a player that's in the actor scope space!
User avatar
Major Cooke
The road to Hell is paved in the carrion she leaves behind.
 
Joined: 28 Jan 2007
Discord: Major Cooke#0846

Re: "How do I ZScript?"

Postby Mikk- » Fri Mar 03, 2017 9:38 am

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
Mikk-
yooooooooooo
 
Joined: 30 Jun 2009
Location: Somewhere off Kanagawa
Discord: Mikk0451#3922

Re: "How do I ZScript?"

Postby Major Cooke » Fri Mar 03, 2017 10:29 am

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.
User avatar
Major Cooke
The road to Hell is paved in the carrion she leaves behind.
 
Joined: 28 Jan 2007
Discord: Major Cooke#0846

PreviousNext

Return to Scripting

Who is online

Users browsing this forum: Caligari87 and 2 guests