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

Re: "How do I ZScript?"

Postby gwHero » Thu Nov 09, 2017 4:59 pm

ZippeyKeys12 wrote:
Blue Shadow wrote:
ZippeyKeys12 wrote:How does one add strings together?

Check here. 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 allExpand view
string s1 = "test";
string s2 = s1..
   string.format("%s %s", "test2", "test3");


Result:
testtest2 test3
User avatar
gwHero
Be your own Siddhartha
 
Joined: 08 May 2017
Location: The Netherlands

Re: "How do I ZScript?"

Postby ZippeyKeys12 » Thu Nov 09, 2017 8:58 pm

Yeah I ended up using String.Format, thx

EDIT: Are there constructors for non-Actor classes?
ZippeyKeys12
 
Joined: 15 Jun 2016

Re: "How do I ZScript?"

Postby Nash » Fri Nov 10, 2017 4:11 am

ZippeyKeys12 wrote:
EDIT: Are there constructors for non-Actor classes?


Not yet...
User avatar
Nash
Nash Muhandes
 
 
 
Joined: 27 Oct 2003
Location: Kuala Lumpur, Malaysia

Re: "How do I ZScript?"

Postby ZippeyKeys12 » Fri Nov 10, 2017 2:04 pm

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?
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"
ZippeyKeys12
 
Joined: 15 Jun 2016

Re: "How do I ZScript?"

Postby Uberkreatur » Mon Nov 13, 2017 7:27 am

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?
Uberkreatur
 
Joined: 26 Dec 2014
Location: Russia

Re: "How do I ZScript?"

Postby Apeirogon » Tue Nov 14, 2017 2:19 pm

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?
Apeirogon
I have a strange sense of humour
 
Joined: 12 Jun 2017

Re: "How do I ZScript?"

Postby dodopod » Tue Nov 14, 2017 3:34 pm

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 allExpand view
    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 allExpand view
    if (--movecount < 0 || !MonsterMove())
    {
        NewChaseDir();
    }


    NewChaseDir(), in turn, calls TryWalk(), which resets movecount.
dodopod
 
Joined: 04 Oct 2017

Re: "How do I ZScript?"

Postby gwHero » Thu Nov 16, 2017 8:29 pm

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 allExpand view
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 allExpand view
TextureId textlight = TexMan.CheckForTexture ("-", TexMan.Type_Any);
User avatar
gwHero
Be your own Siddhartha
 
Joined: 08 May 2017
Location: The Netherlands

Re: "How do I ZScript?"

Postby Apeirogon » Mon Nov 20, 2017 7:02 am

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?
Apeirogon
I have a strange sense of humour
 
Joined: 12 Jun 2017

Re: "How do I ZScript?"

Postby Xaser » Mon Nov 20, 2017 11:24 am

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 allExpand view
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
Xaser
anarchivist
 
 
 
Joined: 20 Jul 2003

Re: "How do I ZScript?"

Postby Zergeant » Mon Nov 20, 2017 12:44 pm

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
Zergeant
 
Joined: 31 Aug 2010
Location: Sweden

Re: "How do I ZScript?"

Postby Apeirogon » Mon Nov 20, 2017 12:59 pm

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?
Apeirogon
I have a strange sense of humour
 
Joined: 12 Jun 2017

Previous

Return to Scripting

Who is online

Users browsing this forum: No registered users and 0 guests