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
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 »

Graf Zahl wrote:No, they won't. Constants go into the main block. They are not defaults they are class properties, not instance properties.
Corrected on the wiki. What about non-constants though?
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 »

Variable declarations go into the class scope Initialization has to be part of Default, because you may want to initialize them differently in subclasses. The way ZDoom initializes actors the constructor is a bad place for that. That part hasn't been defined yet, though.
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 »

Understood. I take it they will be at some point, as user variables being replaced will make it hard to update to ZScript on first merge without the ability to define them.
By the way...

Code: Select all

class CFlameMissile : FastProjectile native


Where and when will we need the "native" keyword?
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 »

The 'native' keyword means that this class contains a native definition in the engine and tells the compiler to connect the script class with the internal one, just like it does in DECORATE. You won't be able to use this in user side code at all.
User avatar
Xaser
 
 
Posts: 10772
Joined: Sun Jul 20, 2003 12:15 pm
Contact:

Re: ZScript Discussion

Post by Xaser »

To echo Gez's sentiment from the previous thread, I'd like to see the "Default" block be renamed to something like "Properties". I get that it means "default values to set on a new instance of this class", but that definition's going to escape users not familiar with the internals. At first glance it looks like the "wrong" word to use in such a context.

[EDIT] For the sake of contributing something that's not a syntax nitpick: the thing I'm most keen to see is non-anonymous functions of some sort (i.e. custom action functions). Being able to call something like A_FirePsychicPower(...) and move all the stuff that goes into that into a sane function def, that'd make a world of difference.
ZzZombo
Posts: 315
Joined: Mon Jul 16, 2012 2:02 am

Re: ZScript Discussion

Post by ZzZombo »

So I guess it's possible to have an array of references to actors, but not other kinds of containers like dictionaries and whatnot, you know, more advanced ones?
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 »

@Xaser: http://forum.zdoom.org/viewtopic.php?f=4&t=53797

Eventually. Probably won't happen on the first merge though.
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: [EDIT] For the sake of contributing something that's not a syntax nitpick: the thing I'm most keen to see is non-anonymous functions of some sort (i.e. custom action functions). Being able to call something like A_FirePsychicPower(...) and move all the stuff that goes into that into a sane function def, that'd make a world of difference.
Let's go at it step by step. The grammar supports such functions but right now the code generator does not. My first priority is to make the stuff that DECORATE already supports work - because after that I can start cleaning up and restructuring the code generator. And before that isn't done it makes little sense to implement more features.
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 »

ZzZombo wrote:So I guess it's possible to have an array of references to actors, but not other kinds of containers like dictionaries and whatnot, you know, more advanced ones?

Again: What's the point of going after step 20 first, when the implementation right now is only at step 5? The groundwork in the grammar is there, but this all needs to be implemented, and that's not a simple task to get working.
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 »

Here's something I want to get a public opinion first, because unlike the const syntax I believe this is really going to confuse users.
I can't help but notice that the grammar has taken some really bad influence from Lua and this looks like another such example:

If you want to declare initialized local variables it has to be done like this currently:

Code: Select all

			int localint, localotherint, i, j = 0,1,2,3;
instead of what pretty much everybody would expect:

Code: Select all

			int localint = 0, localotherint = 1, i = 2, j = 3;
It's only because I already knew about the Lua stuff that I could guess where this was going when the second approach did not work, but if I as a programmer cannot see the sense in here, what about the future user of this tool?

Edit: It gets worse. This passes the parser but the result is bogus:

Code: Select all

			double localfloat = 1.234, localfloatnotinit;
No, it doesn't declare two variables, it only declares one, 'localfloatnotinit' is considered an initializer for a non-existent second variable. I guess I don't wait for opinion, this is a disaster just waiting to happen with the given syntax.
User avatar
juizzysquirt
Posts: 126
Joined: Sun Jan 04, 2009 3:29 pm
Location: Knee-Deep in L.A. Meltdown

Re: ZScript Discussion

Post by juizzysquirt »

First example feels really, really awkward. I get the idea of "efficiency" there but just imagining reading several lines with 5 or more variables (of someone else's code) makes my head hurt.
Last edited by juizzysquirt on Wed Oct 19, 2016 4:28 am, edited 1 time in total.
User avatar
Nash
 
 
Posts: 17434
Joined: Mon Oct 27, 2003 12:07 am
Location: Kuala Lumpur, Malaysia
Contact:

Re: ZScript Discussion

Post by Nash »

I got cross-eyed reading that. That looks confusing as hell. I hope you can change it to the usual, expected syntax. I'm already used to writing like this for many years:

Code: Select all

int dx = 1,
    dy = 2,
    dz = 3;
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 »

Graf Zahl wrote:Edit: It gets worse. This passes the parser but the result is bogus:

Code: Select all

			double localfloat = 1.234, localfloatnotinit;
No, it doesn't declare two variables, it only declares one, 'localfloatnotinit' is considered an initializer for a non-existent second variable. I guess I don't wait for opinion, this is a disaster just waiting to happen with the given syntax.
So we basically need to go with:

Code: Select all

int num1 = 1;
int num2 = 2;
and your above example is a no-go?

I don't mind that one bit honestly. Since this is how user vars had to be treated, I'm used to it -- with the added bonus of zscript's capable of being assigned immediately instead of relying on the states to do it.
Gez
 
 
Posts: 17833
Joined: Fri Jul 06, 2007 3:22 pm

Re: ZScript Discussion

Post by Gez »

Graf Zahl wrote:Here's something I want to get a public opinion first, because unlike the const syntax I believe this is really going to confuse users.
I can't help but notice that the grammar has taken some really bad influence from Lua and this looks like another such example:

If you want to declare initialized local variables it has to be done like this currently:

Code: Select all

			int localint, localotherint, i, j = 0,1,2,3;
Indeed I don't like it. Not that declaring a lot of variable in the same line is good practice anyway, but separating the variables from their initial value seems like a good way of getting both lists out of syncs if variables get added or removed.

E.g. suppose someone tries to refactor the code to see if localotherint is really needed, and so comments it out for a test...

Code: Select all

			int localint, /*localotherint,*/ i, j = 0,1,2,3;
Yeesh! With the C-style syntax there's no risk of that happening.
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 »

Thanks. That list of reactions pretty much sums up my own. Of course I am changing it.
Locked

Return to “Scripting”