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.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...
"How do I ZScript?"
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!)
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!)
-
-
- Posts: 10773
- Joined: Sun Jul 20, 2003 12:15 pm
Re: "How do I ZScript?"
-
- 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?"
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?
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?
-
- Lead GZDoom+Raze Developer
- Posts: 49183
- Joined: Sat Jul 19, 2003 10:19 am
- Location: Germany
Re: "How do I ZScript?"
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.Xaser wrote: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.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...
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.
-
- 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?"
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!)
(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!)
-
- Posts: 8196
- Joined: Sun Jan 28, 2007 3:55 pm
- Preferred Pronouns: He/Him
- Location: QZDoom Maintenance Team
Re: "How do I ZScript?"
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.)
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.)
-
-
- Posts: 17465
- Joined: Mon Oct 27, 2003 12:07 am
- Location: Kuala Lumpur, Malaysia
Re: "How do I ZScript?"
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);
}
}
-
- 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?"
Why is SpecialMissileHit not a bool? Are there other possibilities besides -1 and 1 not mentioned in the wiki?
-
- Posts: 3060
- Joined: Thu May 03, 2012 1:18 pm
- Graphics Processor: nVidia with Vulkan support
- Location: Maryland, US
Re: "How do I ZScript?"
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?
-
- 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?"
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
(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.
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'
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.
-
- Posts: 3060
- Joined: Thu May 03, 2012 1:18 pm
- Graphics Processor: nVidia with Vulkan support
- Location: Maryland, US
Re: "How do I ZScript?"
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.
-
- Posts: 8196
- Joined: Sun Jan 28, 2007 3:55 pm
- Preferred Pronouns: He/Him
- Location: QZDoom Maintenance Team
Re: "How do I ZScript?"
1 means pass through.Vaecrius wrote:Why is SpecialMissileHit not a bool? Are there other possibilities besides -1 and 1 not mentioned in the wiki?
0 means always die.
-1 means use default behavior (ripper missiles for example will rip.)
-
- Lead GZDoom+Raze Developer
- Posts: 49183
- Joined: Sat Jul 19, 2003 10:19 am
- Location: Germany
Re: "How do I ZScript?"
According to actor.h:Vaecrius wrote:Why is SpecialMissileHit not a bool? Are there other possibilities besides -1 and 1 not mentioned in the wiki?
// 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.
-
- Posts: 8196
- Joined: Sun Jan 28, 2007 3:55 pm
- Preferred Pronouns: He/Him
- Location: QZDoom Maintenance Team
Re: "How do I ZScript?"
Note to self, do NOT put a "Cvar" type variable on a player that's in the actor scope space!
-
- Posts: 2274
- Joined: Tue Jun 30, 2009 1:31 pm
Re: "How do I ZScript?"
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.
-
- Posts: 8196
- Joined: Sun Jan 28, 2007 3:55 pm
- Preferred Pronouns: He/Him
- Location: QZDoom Maintenance Team
Re: "How do I ZScript?"
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.
Also, that mask isn't needed anymore, I don't think.