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

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
Major Cooke
Posts: 8221
Joined: Sun Jan 28, 2007 3:55 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): Windows 10
Graphics Processor: nVidia with Vulkan support
Location: GZBoomer Town

Re: "How do I ZScript?"

Post by Major Cooke »

...yeah, the positioning and sizing of sbarinfos and stuff is completely fucked right now.
User avatar
Ed the Bat
Posts: 3060
Joined: Thu May 03, 2012 1:18 pm
Location: Maryland, US

Re: "How do I ZScript?"

Post by Ed the Bat »

How can I ensure a PlayerEntered event only happens when coming in to the map, and not when loading a saved game?
User avatar
Major Cooke
Posts: 8221
Joined: Sun Jan 28, 2007 3:55 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): Windows 10
Graphics Processor: nVidia with Vulkan support
Location: GZBoomer Town

Re: "How do I ZScript?"

Post by Major Cooke »

You can use a transient flagged variable. Those aren't saved.
User avatar
Minigunner
Posts: 754
Joined: Mon Dec 28, 2009 5:13 pm

Re: "How do I ZScript?"

Post by Minigunner »

I've been attempting to get the Actor of a friendly monster's FriendPlayer (the number of the player it follows), and using "players[friendplayer - 1].mo" (I used an int variable to replace friendplayer - 1) always returns NULL. Am I getting something wrong here?
User avatar
Ed the Bat
Posts: 3060
Joined: Thu May 03, 2012 1:18 pm
Location: Maryland, US

Re: "How do I ZScript?"

Post by Ed the Bat »

Major Cooke wrote:You can use a transient flagged variable. Those aren't saved.
I'm... a bit lost, there. Could you show me an example, please?
User avatar
Major Cooke
Posts: 8221
Joined: Sun Jan 28, 2007 3:55 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): Windows 10
Graphics Processor: nVidia with Vulkan support
Location: GZBoomer Town

Re: "How do I ZScript?"

Post by Major Cooke »

Code: Select all

transient int something;
I think that's how it goes. Anyway the point is, that will initialize to 0 when a saved game is loaded because it's not saved. Slap that on an event handler or whatever. It won't ever save.
User avatar
ZZYZX
 
 
Posts: 1384
Joined: Sun Oct 14, 2012 1:43 am
Location: Ukraine

Re: "How do I ZScript?"

Post by ZZYZX »

Ed the Bat wrote:How can I ensure a PlayerEntered event only happens when coming in to the map, and not when loading a saved game?
It should not fire when loading a saved game, if it does, then it's a bug.
User avatar
Ed the Bat
Posts: 3060
Joined: Thu May 03, 2012 1:18 pm
Location: Maryland, US

Re: "How do I ZScript?"

Post by Ed the Bat »

I'll make a bug report for it on the tracker, then.
User avatar
Nash
 
 
Posts: 17512
Joined: Mon Oct 27, 2003 12:07 am
Location: Kuala Lumpur, Malaysia

Re: "How do I ZScript?"

Post by Nash »

ZZYZX wrote: It should not fire when loading a saved game, if it does, then it's a bug.
If that bug is fixed, is there another way to detect a save game is loaded? I remember you actually advertising that as a feature.
User avatar
ZZYZX
 
 
Posts: 1384
Joined: Sun Oct 14, 2012 1:43 am
Location: Ukraine

Re: "How do I ZScript?"

Post by ZZYZX »

Transients or (in a StaticEventHandler) you can check it in WorldLoaded.
User avatar
Nash
 
 
Posts: 17512
Joined: Mon Oct 27, 2003 12:07 am
Location: Kuala Lumpur, Malaysia

Re: "How do I ZScript?"

Post by Nash »

Nash wrote:Screen.DrawText/Texture question:

Is it possible to position something in the same resolution as whatever the current user's resolution is, BUT have the graphic always RENDER at a fixed resolution, say 320x200? So for example, if the user is using 1920x1080, the draw canvas would have more precision for you to position the object, but the graphic that's blitted to the screen should always look blocky like as if the screen was 320x200.

Which Draw Tag should I use to achieve this?
ZZYZX wrote:Use VirtualWidth and VirtualHeight, and just calculate fractional offsets based on the real resolution. (x,y are doubles, as well as VirtualWidthF/VirtualHeightF)
Note: don't forget to DTA_KeepRatio.
This is not working. I set DTA_VirtualWidth/Height to Screen.GetWidth()/GetHeight() and now the graphic is ultra tiny because I'm using 1920x1200.

I need the SCALE to look big, but with the pixel positioning of the user's display resolution.

(Should I feature request explicit scale DTA tags?)
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49252
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: "How do I ZScript?"

Post by Graf Zahl »

ZZYZX wrote:
Nash wrote:If a Thinker (non-Actor) is made using new(), added into an array, and then later is deleted from the array using Delete()... will it be truly removed? Actually what's the safest way to remove it? myArray.Delete(index, 1) or myArray[index].Destroy()?
When last reference to an object is lost, thinker should be deleted, but that's unless there's a global list of thinkers somewhere, like one for Actors. Graf, help.
Of course there's a global thinker list. That is needed to actually process any thinkers.
Any thinker, including any actor will only be destroyed if Destroy is actually being called on it - as long as the thinker chain holds a reference to it it will remain active.
User avatar
Major Cooke
Posts: 8221
Joined: Sun Jan 28, 2007 3:55 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): Windows 10
Graphics Processor: nVidia with Vulkan support
Location: GZBoomer Town

Re: "How do I ZScript?"

Post by Major Cooke »

And that's why I said to call Destroy before deleting the array index, because they can be found by iterators.
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49252
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: "How do I ZScript?"

Post by Graf Zahl »

Nash wrote: (Should I feature request explicit scale DTA tags?)

No: Use DTA_DestWidth/DTA_DestHeight.
User avatar
ZZYZX
 
 
Posts: 1384
Joined: Sun Oct 14, 2012 1:43 am
Location: Ukraine

Re: "How do I ZScript?"

Post by ZZYZX »

Nash wrote:
ZZYZX wrote:Use VirtualWidth and VirtualHeight, and just calculate fractional offsets based on the real resolution. (x,y are doubles, as well as VirtualWidthF/VirtualHeightF)
Note: don't forget to DTA_KeepRatio.
This is not working. I set DTA_VirtualWidth/Height to Screen.GetWidth()/GetHeight() and now the graphic is ultra tiny because I'm using 1920x1200.

I need the SCALE to look big, but with the pixel positioning of the user's display resolution.

(Should I feature request explicit scale DTA tags?)
You aren't doing it right then.
How to do it right:

Code: Select all

void RenderScaled(TextureID tex, double x, double y, double scaleX, double scaleY)
{
  double vw = double(Screen.GetWidth())/scaleX; // let's assume scaleX is 2.0, this means virtualwidth will be divided by 2
  double vh = double(Screen.GetHeight())/scaleY;
  x /= scaleX; // same for x coordinate, so the coordinate is scaled as well (from pixel to virtual)
  y /= scaleY;
  // here use x,y for coordinates and vw/vh for virtualwidthf/virtualheightf
  // coordinates are fractional so there won't be precision loss with low virtualwidth/virtualheight.
}
DTA_KeepRatio=true is needed because otherwise virtualwidth/virtualheight won't work on the actual resolution.

Return to “Scripting”