Page 25 of 97

Re: "How do I ZScript?"

PostPosted: Thu Mar 02, 2017 12:10 pm
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.

Re: "How do I ZScript?"

PostPosted: Thu Mar 02, 2017 3:15 pm
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?

Re: "How do I ZScript?"

PostPosted: Thu Mar 02, 2017 3:40 pm
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.

Re: "How do I ZScript?"

PostPosted: Thu Mar 02, 2017 4:15 pm
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!)

Re: "How do I ZScript?"

PostPosted: Thu Mar 02, 2017 6:29 pm
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.)

Re: "How do I ZScript?"

PostPosted: Thu Mar 02, 2017 11:11 pm
by Nash
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.

Re: "How do I ZScript?"

PostPosted: Fri Mar 03, 2017 12:22 am
by Matt
Why is SpecialMissileHit not a bool? Are there other possibilities besides -1 and 1 not mentioned in the wiki?

Re: "How do I ZScript?"

PostPosted: Fri Mar 03, 2017 1:07 am
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?

Re: "How do I ZScript?"

PostPosted: Fri Mar 03, 2017 1:15 am
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 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.

Re: "How do I ZScript?"

PostPosted: Fri Mar 03, 2017 1:17 am
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.

Re: "How do I ZScript?"

PostPosted: Fri Mar 03, 2017 4:58 am
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.)

Re: "How do I ZScript?"

PostPosted: Fri Mar 03, 2017 5:03 am
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.

Re: "How do I ZScript?"

PostPosted: Fri Mar 03, 2017 5:07 am
by Major Cooke
Note to self, do NOT put a "Cvar" type variable on a player that's in the actor scope space!

Re: "How do I ZScript?"

PostPosted: Fri Mar 03, 2017 8:38 am
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.

Re: "How do I ZScript?"

PostPosted: Fri Mar 03, 2017 9:29 am
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.