Re: "How do I ZScript?"

Thu Nov 09, 2017 3: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:
string s1 = "test";
string s2 = s1..
   string.format("%s %s", "test2", "test3");


Result:
testtest2 test3

Re: "How do I ZScript?"

Thu Nov 09, 2017 7:58 pm

Yeah I ended up using String.Format, thx

EDIT: Are there constructors for non-Actor classes?

Re: "How do I ZScript?"

Fri Nov 10, 2017 3:11 am

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


Not yet...

Re: "How do I ZScript?"

Fri Nov 10, 2017 1: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"

Re: "How do I ZScript?"

Mon Nov 13, 2017 6: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?

Re: "How do I ZScript?"

Tue Nov 14, 2017 1: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?

Re: "How do I ZScript?"

Tue Nov 14, 2017 2: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:
    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:
    if (--movecount < 0 || !MonsterMove())
    {
        NewChaseDir();
    }


    NewChaseDir(), in turn, calls TryWalk(), which resets movecount.

Re: "How do I ZScript?"

Thu Nov 16, 2017 7: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:
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:
TextureId textlight = TexMan.CheckForTexture ("-", TexMan.Type_Any);

Re: "How do I ZScript?"

Mon Nov 20, 2017 6: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?

Re: "How do I ZScript?"

Mon Nov 20, 2017 10: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:
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!

Re: "How do I ZScript?"

Mon Nov 20, 2017 11:44 am

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?

Re: "How do I ZScript?"

Mon Nov 20, 2017 11:59 am

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?