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.

Re: ZScript Discussion

Postby FishyClockwork » Wed Oct 19, 2016 6:50 am

From another thread:
Graf Zahl wrote:You also need to cast 'target' to the proper type first if you want to access information from a child-class.
I'm a bit confused by this so... If I wanted to know what the player's current weapon is, how convoluted does it have to get?

Would this be good enough?:
Code: Select allExpand view
if( target != NULL && target->player != NULL && target->player->ReadyWeapon != NULL )
{
    if( static_cast<Actor>(target->player->ReadyWeapon).CheckClass("BFG9000") )
    {
        A_ChangeFlag("FRIGHTENED", true);
        speed *= 2; //run away faster.
    }
}


Wait, since ReadyWeapon is a pointer, shouldn't it be static_cast<Actor*>? Or is it fine without the * ?
User avatar
FishyClockwork
 
Joined: 23 Feb 2011

Re: ZScript Discussion

Postby Major Cooke » Wed Oct 19, 2016 6:52 am

Fishy: Why would you want to do the static_cast<> stuff...? That just sounds awful. ZScript's aim is to eliminate needing to do that, I think. Not to mention, there's no pointer stars to be used. All that is handled on the C++ side of things.
Last edited by Major Cooke on Wed Oct 19, 2016 7:08 am, edited 1 time in total.
User avatar
Major Cooke
Do unto others as you would have unto you. Judge yourself first.
 
Joined: 28 Jan 2007

Re: ZScript Discussion

Postby FishyClockwork » Wed Oct 19, 2016 6:58 am

Major Cooke wrote:Why would you want to do the static_cast<> stuff...? That just sounds awful. ZScript's aim is to eliminate needing to do that, I think.

Oh, good. I wasn't actually sure which is why I asked.

So is this acceptable?
Code: Select allExpand view
Actor enemyweap = target->player->ReadyWeapon;
if(enemyweap.CheckClass("Bleh"))
{
...
}
User avatar
FishyClockwork
 
Joined: 23 Feb 2011

Re: ZScript Discussion

Postby Major Cooke » Wed Oct 19, 2016 6:59 am

I don't think -> is something we'll have. We have periods though. But I'm not sure myself. If anything, it'll be overlays instead of readyweapon (don't quote me on that).
Last edited by Major Cooke on Wed Oct 19, 2016 7:10 am, edited 1 time in total.
User avatar
Major Cooke
Do unto others as you would have unto you. Judge yourself first.
 
Joined: 28 Jan 2007

Re: ZScript Discussion

Postby FishyClockwork » Wed Oct 19, 2016 7:00 am

So how will it work, then? How do I get a player's 'ReadyWeapon'? Is that even possible?

Let me be clear. This is for comparing the weapon the player currently wields so as not having to call GetWeapon() from ACS.
User avatar
FishyClockwork
 
Joined: 23 Feb 2011

Re: ZScript Discussion

Postby Graf Zahl » Wed Oct 19, 2016 8:03 am

There will only be class casts which are implicitly dynamic.

So, if you got an actor and want an inventory it's

Code: Select allExpand view
   Inventory i = Inventory(a);


or for checking if it is an inventory

Code: Select allExpand view
  if (Inventory(a)) ...


Of course, if you want to check and then use the child class, do the cast first and the check on the resulting variable.

So how will it work, then? How do I get a player's 'ReadyWeapon'? Is that even possible?


Assuming everything is implemented, and you got a PlayerPawn in the action function:

Code: Select allExpand view
 if (self.player)
 {
   Weapon rw = self.player.ReadyWeapon;
   if (rw)
   {
      // do stuff
   }
 }
User avatar
Graf Zahl
Lead GZDoom Developer
Lead GZDoom Developer
 
Joined: 19 Jul 2003
Location: Germany

Re: ZScript Discussion

Postby Major Cooke » Wed Oct 19, 2016 8:14 am

Graf Zahl wrote:Assuming everything is implemented

This being key, Fishy. The ability to do that sort of thing might not be available until sometime after the first merge, and at any point it may or may not change before then.

One other thing, Graf, you said there's something to change about A_Jump functions? I'm looking around for it so I can document what needs to happen with those.
User avatar
Major Cooke
Do unto others as you would have unto you. Judge yourself first.
 
Joined: 28 Jan 2007

Re: ZScript Discussion

Postby FishyClockwork » Wed Oct 19, 2016 8:23 am

Major Cooke wrote:This being key, Fishy. The ability to do that sort of thing might not be available until sometime after the first merge, and at any point it may or may not change before then.

Yes, yes, I know. Don't think about step 20 if you haven't got to step 5 yet, I get it.
But take it easy, mate. Seeing this stuff is super exciting so I have to ask questions just to get a basic picture of what to expect. Just bear with me a little. :P
User avatar
FishyClockwork
 
Joined: 23 Feb 2011

Re: ZScript Discussion

Postby Major Cooke » Wed Oct 19, 2016 8:25 am

I only said it because I know someone else is going to ask, or someone may misunderstand that bit and jump to the conclusion that it'll be in the first commit right then. :P

Since not everyone's going to be browsing all the posts from start to finish, it'll work as a good reminder for those who skip straight to this page.
User avatar
Major Cooke
Do unto others as you would have unto you. Judge yourself first.
 
Joined: 28 Jan 2007

Re: ZScript Discussion

Postby arookas » Wed Oct 19, 2016 9:01 am

I wonder just how much of the engine's hardcoded internals can be exported to zscript once this is all finally working. The ReadyWeapon snippet looks very interesting!

Just wondering: how is it planned for a user to interface with zcc (or whatever the compiler may be called)? Will it be entirely builtin (automatic compilation on startup) or will it also feature an external compiler? Actor code compilation for DECORATE is already pretty fast so I don't think startup time is really a factor.
User avatar
arookas
...but only sometimes.
 
Joined: 24 Jan 2011

Re: ZScript Discussion

Postby Major Cooke » Wed Oct 19, 2016 9:03 am

It'll be an internal compiler, much like the DECORATE one.
User avatar
Major Cooke
Do unto others as you would have unto you. Judge yourself first.
 
Joined: 28 Jan 2007

Re: ZScript Discussion

Postby Leonard2 » Wed Oct 19, 2016 4:33 pm

Graf Zahl wrote:And the map is not an object in that sense.

I didn't mean it that way.
Does that mean that map data won't be made available?
I mean being able to access something like "level.mapname" could be useful.

Graf Zahl wrote:Before even thinking about virtual functions and stuff like that the code generator needs to get working, and that's what I am currently at, and before that isn't done I won't waste any thought about how to hook it all in later. The goal clearly is to extend classes via scripting, but you have to be aware that in order to extend a class this class needs to be set up to be extended. ZScript won't be the magic wand to solve all problems, and in order to hook into some subsystems they will need quite a bit of refactoring first.

I know that.
You asked to discuss upcoming features so I thought this could have been interesting.
User avatar
Leonard2
 
Joined: 14 Aug 2012

Re: ZScript Discussion

Postby Graf Zahl » Wed Oct 19, 2016 4:45 pm

Of course you will get access to the map data. But since the map is not an object and especially not a thinker it doesn't have any real means to do stuff on its own. But it's completely open what features you may get. It's far too early to say.
User avatar
Graf Zahl
Lead GZDoom Developer
Lead GZDoom Developer
 
Joined: 19 Jul 2003
Location: Germany

Re: ZScript Discussion

Postby Major Cooke » Thu Oct 20, 2016 10:27 am

Graf Zahl's Commit wrote:create proper variable data from the function prototype instead of assuming that there's just 3 pointers.


I forgot to ask, for pointers, is the cast type "Actor" or is there some other means to setting up a pointer for zscript?
User avatar
Major Cooke
Do unto others as you would have unto you. Judge yourself first.
 
Joined: 28 Jan 2007

Re: ZScript Discussion

Postby Graf Zahl » Thu Oct 20, 2016 11:28 am

The cast is whatever class type you want it to point to.
User avatar
Graf Zahl
Lead GZDoom Developer
Lead GZDoom Developer
 
Joined: 19 Jul 2003
Location: Germany

PreviousNext

Return to Scripting

Who is online

Users browsing this forum: Quantum3113, Semrush [Bot] and 5 guests