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

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
gwHero
Posts: 360
Joined: Mon May 08, 2017 3:23 am
Graphics Processor: Intel with Vulkan/Metal Support
Location: The Netherlands

Re: "How do I ZScript?"

Post by gwHero »

ZippeyKeys12 wrote:
Blue Shadow wrote:
ZippeyKeys12 wrote:How does one add strings together?
Check [wiki=String]here[/wiki]. You might find the answer.
I tried that, maybe I'm doing something else wrong.
Several ways. With .. you can concatenate, and with string.format() strings and more.
Example with both methods:

Code: Select all

string s1 = "test";
string s2 = s1..
	string.format("%s %s", "test2", "test3");
Result:
testtest2 test3
ZippeyKeys12
Posts: 111
Joined: Wed Jun 15, 2016 2:49 pm

Re: "How do I ZScript?"

Post by ZippeyKeys12 »

Yeah I ended up using String.Format, thx

EDIT: Are there constructors for non-Actor classes?
User avatar
Nash
 
 
Posts: 17434
Joined: Mon Oct 27, 2003 12:07 am
Location: Kuala Lumpur, Malaysia
Contact:

Re: "How do I ZScript?"

Post by Nash »

ZippeyKeys12 wrote:
EDIT: Are there constructors for non-Actor classes?
Not yet...
ZippeyKeys12
Posts: 111
Joined: Wed Jun 15, 2016 2:49 pm

Re: "How do I ZScript?"

Post by ZippeyKeys12 »

Nash wrote:
ZippeyKeys12 wrote:
EDIT: Are there constructors for non-Actor classes?
Not yet...
I saw that, but it was several months ago so I thought mayb they were here :cry: 😩 :cry:

And also plz, somebody 🙏, can one register eventhandlers from ZScript rather than MAPINFO

EDIT 2: Why can't I return null for a String function? How would I do that?
EDIT 3: Also, when I try replacing \n in a string, if \n is inside a const array it won't work
i.e
Spoiler: Example Code
Seems like backslash expressions lose their meaning in a constant array. Should I file a bug report or is there something I'm missing?[/s] I'm really tired right now :shock:
Weird that there were no errors from having no commas in the array, though. :?

EDIT 4: Is there a way to evaluate a string as a math expression, i.e: "100/3+4"
Uberkreatur
Posts: 27
Joined: Fri Dec 26, 2014 10:54 am
Location: Russia

Re: "How do I ZScript?"

Post by Uberkreatur »

Zscript is still documented not enough.
1. What is the difference between MonsterMove() and TryWalk()?
2. MonsterMove() and TryWalk() works like A_Chase with CHF_DONTTURN flag. If monster changes angle, it continues to move in the original direction. How to set this direction?
User avatar
Apeirogon
Posts: 1605
Joined: Mon Jun 12, 2017 12:57 am

Re: "How do I ZScript?"

Post by Apeirogon »

How work with DoEffect?
I want item that take every half of second one plasma cell and give at whole seond one point of health, to maximum health. How make it?
dodopod
Posts: 66
Joined: Wed Oct 04, 2017 2:00 pm
Contact:

Re: "How do I ZScript?"

Post by dodopod »

Uberkreatur wrote:Zscript is still documented not enough.
1. What is the difference between MonsterMove() and TryWalk()?
2. MonsterMove() and TryWalk() works like A_Chase with CHF_DONTTURN flag. If monster changes angle, it continues to move in the original direction. How to set this direction?
  1. I'm not an expert on this, but I believe that MonsterMove() just tries to move an actor in its current direction (movedir). It returns true if the actor is able to move, and false it it's blocked. If you look in gzdoom.pk3, you'll see that TryWalk is defined as

    Code: Select all

    bool TryWalk ()
    {
        if (!MonsterMove ())
        {
            return false;
        }
        movecount = random[TryWalk]() & 15; // Sets movecount to a random number less than 16
        return true;
    }
    
    movecount is a countdown used by A_Chase. When it reaches 0, the actor either attacks, or if it can't, it randomly changes direction.
  2. Here's roughly what A_Chase did in the original Doom source code (translated into ZScript):

    Code: Select all

    if (--movecount < 0 || !MonsterMove())
    {
        NewChaseDir();
    }
    
    NewChaseDir(), in turn, calls TryWalk(), which resets movecount.
User avatar
gwHero
Posts: 360
Joined: Mon May 08, 2017 3:23 am
Graphics Processor: Intel with Vulkan/Metal Support
Location: The Netherlands

Re: "How do I ZScript?"

Post by gwHero »

Does somebody know how to clear a midtexture from a linedef with ZScript?
I have some midtexture lights on several linedefs. Now switching the lights on works as follows:

Code: Select all

TextureId textlight = TexMan.CheckForTexture ("ZLIGHTLM", TexMan.Type_Any);
int linenum = 0;	
int LightLineTag = 666;
LineIdIterator lit = LineIdIterator.Create(LightLineTag);			
while ((linenum = lit.Next()) >= 0)			
{	
	level.lines[linenum].sidedef[1].SetTexture(1, textlight); // sidedef[1] = back
}
But I don't know how to switch them off.

[EDIT] Found it: (just similar to the hack commonly used in ACS SetLineTexture with "-"):
assigning the TextureId like this before using the SetTexture:

Code: Select all

TextureId textlight = TexMan.CheckForTexture ("-", TexMan.Type_Any);
User avatar
Apeirogon
Posts: 1605
Joined: Mon Jun 12, 2017 12:57 am

Re: "How do I ZScript?"

Post by Apeirogon »

Does zscript have pointers for children? And if have, how they named?

I make imp that after some damage split to 7-13 its shadow_part, which count as his children, who after death kill all it sibling and warp instead of oneself it master.
I want add to that imp ability warp to one randomly pick shadow_image child. How make it?
User avatar
Xaser
 
 
Posts: 10772
Joined: Sun Jul 20, 2003 12:15 pm
Contact:

Re: "How do I ZScript?"

Post by Xaser »

Direct pointers to children don't exist, rather each child has a pointer to its master. The "canon" way to do get all children (used by internal functions like A_GiveToChildren) is to use a ThinkerIterator and check if the "master" pointer is equal to something.

The ZScript syntax is a bit different than the C++ example above, so here's a quick example on how to do this (from Eriguns, copy+pasted from here, with new comments):

Code: Select all

action void X_DetonateBolts()
{
	// Eriguns's Irebolt weapon fires sticky bolts that can be remotely detonated with
	// Altfire. When each bolt is fired, its "master" pointer is set to the player that
	// fired it. This function handles finding all the child bolts and detonating 'em.

	// Firstly, since we know that all children will be of class "IreboltShot", we can
	// explicitly tell our iterator that we're only looking for actors of this class
	// for a bit of a performance boost.

	ThinkerIterator boltIterator = ThinkerIterator.Create("IreboltShot");
	IreboltShot bolt;

	// Do the iteration. boltIterator.Next() returns an Actor, so we want to cast it to
	// IreboltShot in order to call a custom function on it.

	while(bolt = IreboltShot(boltIterator.Next() ) ) {

		// Here, I'm checking that the bolt's "master" is the player; since I'm calling
		// the function from the weapon, "self" is the player. Most likely, you'll
		// be adding this function to your custom imp class, so "self" will be the imp
		// itself too, meaning this is probably the check you're looking for.

		if(bolt.master == self) {

			// Do your special logic here.
			bolt.X_BoltDetonate();
		}
	}
}
Hope this helps a bit!
User avatar
Zergeant
Posts: 107
Joined: Tue Aug 31, 2010 7:19 am
Location: Sweden

Re: "How do I ZScript?"

Post by Zergeant »

I'm trying to fetch the distance to the wall an actor is facing towards, so far I've looked at AimLineAttack and BlockLinesIterator but I'm not sure how to use either to fetch the desirable wall and the distance.

Anyone got ideas or suggestions for the most optimal way for this?
User avatar
Apeirogon
Posts: 1605
Joined: Mon Jun 12, 2017 12:57 am

Re: "How do I ZScript?"

Post by Apeirogon »

And how randomly pick up one child from thinkeriterator list?
If I correct, after activating thinker(Le Penseur)iterator it run all over the map with notebook and pencil and ask every single object "is you actor class "shadow_split"?"
If he receive "true" it write it in notebook and continue, else just continue.
After it check all map it start execute custom action.
If I adapt it code as is
Spoiler:
imp-master try to warp simultaneously to all found shadow and, maybe, crash gzdoom.

Or I can "teach" thinkeriterator how give to every found imp shadow some symbol?
Locked

Return to “Scripting”