ZScript Discussion

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
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49056
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: ZScript Discussion

Post by Graf Zahl »

Illasera wrote: Your first two arguments would probably hold more water if zscript could store and load compiled data and not compile things at runtime.
A memset by its very design is dangerous. First, classes are being constructed, so you cannot memset them, it would clobber the internal data.
That leaves local variables - and stack is always zeroed before being used.

To sum it up: There is no need to memset, it would be a scripter's choice if done, but since memset doesn't have even the slightest sanity checks it's simply not going to happen.
User avatar
Xaser
 
 
Posts: 10772
Joined: Sun Jul 20, 2003 12:15 pm
Contact:

Re: ZScript Discussion

Post by Xaser »

Got a couple of broad conceptual questions, since for some reason I've got some knowledge gaps:
  • What precisely causes the "ambiguous context pointer" error to be thrown? There's inevitably an extremely-obvious pattern here that I'm missing. :P
  • What precisely is the 'Name' datatype? Names and Strings seem to be almost interchangeable, but I'd rather use the correct types in code, even if it's nitpicky. Trying to avoid Javascript-esque "use whatever quotation marks you feel like" habits.
User avatar
Gutawer
Posts: 469
Joined: Sat Apr 16, 2016 6:01 am
Preferred Pronouns: She/Her

Re: ZScript Discussion

Post by Gutawer »

For the second ones, Names aren't case-sensitive, so they are often used for stuff like class names (think stuff like if (actor is "someclassname")), and lump names (when applicable, such as creating a font variable). This also means that the case-insenstitive string comparison operator (~==) won't work, since there isn't any point to it on a Name.
Gez
 
 
Posts: 17833
Joined: Fri Jul 06, 2007 3:22 pm

Re: ZScript Discussion

Post by Gez »

Xaser wrote:What precisely is the 'Name' datatype?
Internally a name is an index to a string table, so a name is a lightweight variable. That means that they're much faster than strings for whenever you've got tons of comparisons to make.
Blue Shadow
Posts: 4949
Joined: Sun Nov 14, 2010 12:59 am

Re: ZScript Discussion

Post by Blue Shadow »

Sounds like strings in ACS.
Illasera
Posts: 20
Joined: Thu May 11, 2017 7:22 am

Re: ZScript Discussion

Post by Illasera »

Time for another question, Any support for C standard library math functions via callbacks on zscript? (sqrt, log and friends)
that should be safe to add i believe, I am talking about callbacks in zscript that are directly linked to the c standard library under gzdoom.

If so, how do i access them? if there is a wiki page on it? i did look for it , couldn't find it, do i access it as i would with a normal c function?

i can write them myself under zscript if they do not exist as of yet but i am afraid the overhead will be too great if i am to use them in a recursive manner,
some of them can be really expansive (Due to lack of optimization and prefetching), specially when handling functions that use division operator a lot (For those who don't know, dividing stuff , both integers and floating points can be very expansive on the x86 family of hardware, can span up to hundrads of cycles (SIMD excluded) not taking into account cache misses, but that's another topic).

As far as having a scripter writing them in zscript, Such functions do go through a lot of optimization under most C standard libraries, hence their version is better. a direct callback is preferable.

Thanks in advance for any answer towards the question above.
Blue Shadow
Posts: 4949
Joined: Sun Nov 14, 2010 12:59 am

Re: ZScript Discussion

Post by Blue Shadow »

User avatar
Xaser
 
 
Posts: 10772
Joined: Sun Jul 20, 2003 12:15 pm
Contact:

Re: ZScript Discussion

Post by Xaser »

Gez wrote:Internally a name is an index to a string table, so a name is a lightweight variable. That means that they're much faster than strings for whenever you've got tons of comparisons to make.
Hmm, interesting -- presumably then, it'd also be the datatype to use for static strings in Default blocks (e.g. RenderStyle 'Add') and the like?

I'm mostly just worried about some scenario where I'm supplying type 'x' and it has to spend time internally converting to type 'y', unless the ZScript interpreter is doing this once-and-done on startup in some places. Molehills, I'm sure, but it's always good to know. :P
Illasera
Posts: 20
Joined: Thu May 11, 2017 7:22 am

Re: ZScript Discussion

Post by Illasera »

Oh its in decorate, i was looking under zscript, THANK YOU!
yea i know its an extension to some degree but i forgot all about it, my bad.
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49056
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: ZScript Discussion

Post by Graf Zahl »

Xaser wrote:
Gez wrote:Internally a name is an index to a string table, so a name is a lightweight variable. That means that they're much faster than strings for whenever you've got tons of comparisons to make.
Hmm, interesting -- presumably then, it'd also be the datatype to use for static strings in Default blocks (e.g. RenderStyle 'Add') and the like?
No. The render style is just translated to an actual style value. The string notation comes from a time when it couldn't be done with a symbolic constant, but why change it if it ain't broke.?
User avatar
Xaser
 
 
Posts: 10772
Joined: Sun Jul 20, 2003 12:15 pm
Contact:

Re: ZScript Discussion

Post by Xaser »

Hmm, that one certainly falls in the "doesn't matter" camp, then. Maybe a better example would be something like Inventory.Icon -- since I'm not going to be doing any manipulation of the value, is this a case for a Name?
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49056
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: ZScript Discussion

Post by Graf Zahl »

No, that's a FTextureID internally.
Damage types get stored as a name, for example, as does species, but that's really everything, aside from a few oversights in third-party submissions.
D2JK
Posts: 543
Joined: Sat Aug 30, 2014 8:21 am

Re: ZScript Discussion

Post by D2JK »

Are there any plans for making overlay states possible on monsters and other non-weapon actors? Perhaps "overlay" is a misnomer... actually I'm interested in the ability to make multiple states execute simultaneously, as with weapon actor overlays.

The secondary state(s) executing in the "background" could make something happen over time, for example.
User avatar
Major Cooke
Posts: 8170
Joined: Sun Jan 28, 2007 3:55 pm
Preferred Pronouns: He/Him
Location: QZDoom Maintenance Team

Re: ZScript Discussion

Post by Major Cooke »

'simultaneously' is never really simultaneous. It's actually just one piece of code right after the other.

If you want to make something else happen at the same time, you can create a thinker subclass that does things. They're very light in comparison to actors and they cannot be 'spawned' per se. They have no presence in the world itself at all.

But yes, I would actually like overlays on non-players as well for the ability to use psprites upon.
Illasera
Posts: 20
Joined: Thu May 11, 2017 7:22 am

Re: ZScript Discussion

Post by Illasera »

Quick question, Is there a way to debug zscript?

without debugging gzdoom project as a whole?
and without attempting to print out every variable i want to test?

What practices you guys use when it comes to writing zscript code and testing it?
Locked

Return to “Scripting”