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

Re: "How do I ZScript?"

Postby Nash » Mon Feb 27, 2017 1:15 pm

Ed the Bat wrote:In case anyone's interested, I found a solution for my question from Page 1:

By giving A_RailAttack the RGF_EXPLICITANGLE flag, and setting the spread_z parameter to BulletSlope()-pitch, I now have a railgun that respects autoaim.



Thanks for sharing, Ed!

////////////////

I am trying to call GetCVar from an EventHandler but it seems that GetCVar is locked to Actors. Is this the correct way to do it, and should I delete a or will that be handled automatically?

Code: Select allExpand view

    int _W_GetUpdateInterval
(void)
    {
        let a = new("Actor");
        int i = a.GetCVar("sv_weatherupdateinterval");
        return i >= 1 && i < 100 ? i : 1;
    }
User avatar
Nash
 
 
 
Joined: 27 Oct 2003
Location: Kuala Lumpur, Malaysia
Github ID: nashmuhandes

Re: "How do I ZScript?"

Postby Gutawer » Mon Feb 27, 2017 2:27 pm

ZScript has no need for GetCVar, just access sv_weatherupdateinterval as if it were a variable.
User avatar
Gutawer
User Accounts Assistant
 
Joined: 16 Apr 2016
Discord: Gutawer#3431

Re: "How do I ZScript?"

Postby Nash » Mon Feb 27, 2017 2:36 pm

That doesn't work... at least not from EventHandler.
User avatar
Nash
 
 
 
Joined: 27 Oct 2003
Location: Kuala Lumpur, Malaysia
Github ID: nashmuhandes

Re: "How do I ZScript?"

Postby Gutawer » Mon Feb 27, 2017 2:41 pm

Hmm. I've been using CVars like that in Chaos Corpses from inside Event Handlers and they seem to work fine for me :/
User avatar
Gutawer
User Accounts Assistant
 
Joined: 16 Apr 2016
Discord: Gutawer#3431

Re: "How do I ZScript?"

Postby Nash » Mon Feb 27, 2017 3:04 pm

D'OH I forgot to add the CVARINFO lump, which was why it couldn't find the variable. Works now. Sorry. XD

Next question:

Code: Select allExpand view
/*
 * Linearly interpolates the value and clamps the result between 0.0 to 1.0.
 * value: (No type restriction)
 *     Value from.
 * maxValue: (No type restriction)
 *     Value to.
 * Return value: (No type restriction)
 *     Result of interpolation. Ranges from 0.0 to 1.0.
 */
function int Interpolate(int value, int maxValue)
{
    return Clamp(FixedDiv(value, maxValue), 0.0, 1.0);
}


I'm horrible with maths and I didn't write this piece of ACS... can someone convert this to ZScript while still making it return the expected values as before?

Thing is, it accepted any kind of number before - either ints or Fixed - and will always result in a Fixed from 0 to 1. Fixed values in ACS have always confused me.
User avatar
Nash
 
 
 
Joined: 27 Oct 2003
Location: Kuala Lumpur, Malaysia
Github ID: nashmuhandes

Re: "How do I ZScript?"

Postby Major Cooke » Mon Feb 27, 2017 3:29 pm

You can simply change FixedDiv(value, maxValue) into value / maxValue.
User avatar
Major Cooke
QZDoom Maintenance Team
 
Joined: 28 Jan 2007

Re: "How do I ZScript?"

Postby Matt » Mon Feb 27, 2017 3:35 pm

So Nash mentioned a non-crash-inducing formatting error in my previous example and I never got around to asking:

So the correct format is no semicolon after +- flags but we must have a semicolon after properties?


Also, if I'm doing random numbers, is there any performance improvement if I keep ranges to powers of 2?
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 » Mon Feb 27, 2017 4:00 pm

Flags are the only things that don't require semicolons. So, yes.

For number ranges, not that I can think of...
User avatar
Major Cooke
QZDoom Maintenance Team
 
Joined: 28 Jan 2007

Re: "How do I ZScript?"

Postby Nash » Mon Feb 27, 2017 8:23 pm

What's the formula to convert all of my ACS fixed angles to ZScript's degrees?

omfg i'm going to loose my mind viewtopic.php?f=3&t=31085
User avatar
Nash
 
 
 
Joined: 27 Oct 2003
Location: Kuala Lumpur, Malaysia
Github ID: nashmuhandes

Re: "How do I ZScript?"

Postby Ed the Bat » Mon Feb 27, 2017 10:49 pm

I have no grasp of these EventHandlers... but could they be the key to my question from before, about replicating ACS' OPEN script type?
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 Nash » Tue Feb 28, 2017 3:28 am

Ed the Bat wrote:I have no grasp of these EventHandlers... but could they be the key to my question from before, about replicating ACS' OPEN script type?


That's exactly what you can do with them! Among other things of course. They're basically entry points to various things ("events") that can happen In the engine.

My Bumi weather engine is now running 100% off ZScript, not even a single line of ACS. :mrgreen:

My Duke3D shadow mod is also using an EventHandler that spawns shadows whenever a monster is spawned. viewtopic.php?f=37&t=54992

Here's a basic example ZSDemo that ZZYZX put up a while ago (I'm re-uploading here because it's impossible to search for it in all the noise)
You do not have the required permissions to view the files attached to this post.
User avatar
Nash
 
 
 
Joined: 27 Oct 2003
Location: Kuala Lumpur, Malaysia
Github ID: nashmuhandes

Re: "How do I ZScript?"

Postby Ed the Bat » Tue Feb 28, 2017 8:55 am

Beautiful! I'll be sure to read this over sometime today. Thanks a bunch!
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 » Tue Feb 28, 2017 9:08 pm

Is there a way to tell if a specific lump has been loaded? (e.g., SHT2A0)
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 ZZYZX » Wed Mar 01, 2017 4:06 am

For images use TexMan.CheckForTexture("something", TexMan.TYPE_Any).Exists();
For everything else use Wads.CheckNumForName("something", namespace, -1, false).
Namespace:
Code: Select allExpand view
   enum WadNamespace
   {
      ns_hidden = -1,

      ns_global = 0,
      ns_sprites,
      ns_flats,
      ns_colormaps,
      ns_acslibrary,
      ns_newtextures,
      ns_bloodraw,
      ns_bloodsfx,
      ns_bloodmisc,
      ns_strifevoices,
      ns_hires,
      ns_voxels,

      ns_specialzipdirectory,
      ns_sounds,
      ns_patches,
      ns_graphics,
      ns_music,

      ns_firstskin,
   }


P.S. direct wad reading when? I'm waiting to implement model-based collision in CanCollideWith for few months already. :/
User avatar
ZZYZX
le chat du rabbin
 
 
 
Joined: 14 Oct 2012
Location: Ukraine
Discord: ZZYZX#1394
Github ID: jewalky

Re: "How do I ZScript?"

Postby Nash » Wed Mar 01, 2017 4:14 am

ZZYZX wrote:P.S. direct wad reading when? I'm waiting to implement model-based collision in CanCollideWith for few months already. :/


Yo that would be sick! It would help a lot with level design, artists can create static meshes that would just be too cumbersome to create with the BSP!
User avatar
Nash
 
 
 
Joined: 27 Oct 2003
Location: Kuala Lumpur, Malaysia
Github ID: nashmuhandes

PreviousNext

Return to Scripting

Who is online

Users browsing this forum: vidaritos and 0 guests