ZScript Discussion

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.

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!)
Locked
User avatar
Major Cooke
Posts: 8215
Joined: Sun Jan 28, 2007 3:55 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): Windows 10
Graphics Processor: nVidia with Vulkan support
Location: GZBoomer Town
Contact:

Re: ZScript Discussion

Post by Major Cooke »

Eh, this works.

Code: Select all

Class<Inventory> keypick = (Class<Inventory>)(mo.GetClass());
				
					 if (keypick == "D4RedCard")		{	A_Log("Red Card Acquired");	}
				else if (keypick == "D4YellowCard")		{	A_Log("Yellow Card Acquired");	}
				else if (keypick == "D4BlueCard")		{	A_Log("Blue Card Acquired");	}
				else if (keypick == "D4RedSkull")		{	A_Log("Red Skull Acquired");	}
				else if (keypick == "D4YellowSkull")	{	A_Log("Yellow Skull Acquired");	}
				else if (keypick == "D4BlueSkull")		{	A_Log("Blue Skull Acquired");	}
I'm not comfortable using it though since I cannot check inheritance in this particular situation.
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49252
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: ZScript Discussion

Post by Graf Zahl »

Major Cooke wrote:Did some further testing. It seems the inverse of your doubts is true.

Code: Select all

if (mo == (D4RedCard)GetClass()) //This won't load.

if (mo == (D4RedCard)(GetClass()))	//This loads, but doesn't ever work.
So for my own sanity, I'm just going to use mo.CheckClass("NameOfActor"). Since I'm only ever using this on other actors, I can tell this is going to drive me up the wall.

That's because what you did is simply wrong. You try to cast a class pointer to an object pointer. That should always result in a type mismatch error. Apparently the grammar lets some stuff slip through that it shouldn't, as the first line.

So here's a quick instruction of a few options:

1. Check if an object is of a certain class or subclass:

'if (object is "Classname")'
'if (object.CheckClass("Classname", AAPTR_DEFAULT, true)'
'if (Classname(object)'

all yield the same result, the first one is the recommended syntax.

2. Check if an object is an exact class type:

'if (object.GetClass() == "Classname")'
if (object.CheckClass("Classname")'

will do the job.
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49252
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: ZScript Discussion

Post by Graf Zahl »

Major Cooke wrote:Eh, this works.

Code: Select all

Class<Inventory> keypick = (Class<Inventory>)(mo.GetClass());
				
					 if (keypick == "D4RedCard")		{	A_Log("Red Card Acquired");	}
				else if (keypick == "D4YellowCard")		{	A_Log("Yellow Card Acquired");	}
				else if (keypick == "D4BlueCard")		{	A_Log("Blue Card Acquired");	}
				else if (keypick == "D4RedSkull")		{	A_Log("Red Skull Acquired");	}
				else if (keypick == "D4YellowSkull")	{	A_Log("Yellow Skull Acquired");	}
				else if (keypick == "D4BlueSkull")		{	A_Log("Blue Skull Acquired");	}
I'm not comfortable using it though since I cannot check inheritance in this particular situation.
For inheritance you use 'if (mo is "Key")' or whatever class you consider the required base for the check.
What you experience here is typical for working with software that hasn't been documented yet, of course this needs to change eventually.
User avatar
Major Cooke
Posts: 8215
Joined: Sun Jan 28, 2007 3:55 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): Windows 10
Graphics Processor: nVidia with Vulkan support
Location: GZBoomer Town
Contact:

Re: ZScript Discussion

Post by Major Cooke »

Is there any way to convert from Class<Actor> to Name?
User avatar
Nash
 
 
Posts: 17505
Joined: Mon Oct 27, 2003 12:07 am
Location: Kuala Lumpur, Malaysia
Contact:

Re: ZScript Discussion

Post by Nash »

Can you access the class' variables from the extend block?

This works:

Code: Select all

class NashGore_Blood : Blood replaces Blood
{
    double vx, vy, vz;

    void A_RandomSpawnVel(void)
    {
        vx = 1.0;
    }

    States
    {
    Spawn:
        TNT1 A 0 NoDelay
        {
            A_RandomSpawnVel();
        }   
    // etc
}
This doesn't work!

Code: Select all

class NashGore_Blood : Blood replaces Blood
{
    double vx, vy, vz;

    States
    {
    Spawn:
        TNT1 A 0 NoDelay
        {
            A_RandomSpawnVel();
    
    // etc

extend class NashGore_Blood
{
    void A_RandomSpawnVel(void)
    {
        vx = 1.0; // compile error! can't access vx from here
    }
}
 
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49252
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: ZScript Discussion

Post by Graf Zahl »

That should work. The class pieces are merged together before doing any work on them.
User avatar
Major Cooke
Posts: 8215
Joined: Sun Jan 28, 2007 3:55 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): Windows 10
Graphics Processor: nVidia with Vulkan support
Location: GZBoomer Town
Contact:

Re: ZScript Discussion

Post by Major Cooke »

Major Cooke wrote:Is there any way to convert from Class<Actor> to Name?
I ask because I want to avoid doing this crap:

Code: Select all

		static const Class<Inventory> WeaponList[] =
		{
			null,
			"D4Pistol",
			"D4Shotgun",
			"D4Supershotgun",
			"D4Repeater",
			"D4AssaultRifle",
			"D4Chaingun",
			"D4RocketLauncher",
			"D4PlasmaRifle",
			"D4LightningGun",
			"D4GaussCannon",
			"D4VortexRifle",
			"D4StaticRifle",
			"D4BFG",
			"D4CarrionCannon" 	// 14
		};
		
		static const String WeaponNameList[] =
		{
			"",
			"D4Pistol",
			"D4Shotgun",
			"D4Supershotgun",
			"D4Repeater",
			"D4AssaultRifle",
			"D4Chaingun",
			"D4RocketLauncher",
			"D4PlasmaRifle",
			"D4LightningGun",
			"D4GaussCannon",
			"D4VortexRifle",
			"D4StaticRifle",
			"D4BFG",
			"D4CarrionCannon" 	// 14
		};
User avatar
Xaser
 
 
Posts: 10774
Joined: Sun Jul 20, 2003 12:15 pm
Contact:

Re: ZScript Discussion

Post by Xaser »

Another quick question: is there a way of globally defining functions (or defining them on Actor) yet?

Context: trying to add some functions accessible to all my mod's monster replacements, which all inherit from the original monsters and thus have no common ancestor (sans Actor) I can declare the functions on.
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49252
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: ZScript Discussion

Post by Graf Zahl »

No, there are no global functions and there won't be, they wouldn't help you anyway, because they have no self pointer.
It may make sense to allow adding functions to existing classes later, but that obviously must exclude anything that can be injected into previously declared classes, like virtual overrides. Just putting some additional stuff that doesn't affect the class itself into the class's symbol table should be ok, though.
User avatar
Xaser
 
 
Posts: 10774
Joined: Sun Jul 20, 2003 12:15 pm
Contact:

Re: ZScript Discussion

Post by Xaser »

I imagine this "no common custom ancestor" use case is going to come up a lot. Being able to define new actions on Actor would certainly do the trick.
User avatar
Agentbromsnor
Posts: 265
Joined: Wed Mar 28, 2012 2:27 am

Re: ZScript Discussion

Post by Agentbromsnor »

I have to admit, I'm a little bit scared of how complex ZScript is going to be compared to DECORATE.

Is it safe to assume that if you have a solid understanding of DECORATE, you won't have much trouble adjusting to ZScript?
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49252
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: ZScript Discussion

Post by Graf Zahl »

You are not forced to use all those low level features. Everything DECORATE can do will still be there, but with the added advantage that if you need to go more low level you now can.

I'd also guess that eventually people will write some libraries others can use.

In general, if you have a solid understanding of DECORATE and ACS you should be fine, although a bit of real programming experience would help a lot understanding the concepts.
User avatar
Nash
 
 
Posts: 17505
Joined: Mon Oct 27, 2003 12:07 am
Location: Kuala Lumpur, Malaysia
Contact:

Re: ZScript Discussion

Post by Nash »

I am trying to concatenate a string to an int, to randomize the state it will jump to next:

Code: Select all

    States
    {
    Spawn:
        TNT1 A 0 NoDelay
        {
            A_SpawnItem("NashGore_BloodSplash", transfer_translation: true);
            string st = "BloodSpot";
            int r = random(1, 4);
            st = st .. r;
            return ResolveState(st);
        }
    BloodSpot1:
        BSPT A 1;
        goto BloodSpotStatic;
    BloodSpot2:
        BSPT B 1;
        goto BloodSpotStatic;
    BloodSpot3:
        BSPT C 1;
        goto BloodSpotStatic;
    BloodSpot4:
        BSPT D 1;
        goto BloodSpotStatic;
    BloodSpotStatic:
        "####" "#" 0 A_SetTics(NASHGORE_BLOODSPOT_DURATION);
        goto FadeOut;
    FadeOut:
        "####" "#" 2 A_FadeOut(0.005);
        Loop;
    }
 
Is that supposed to even work in the first place? BTW the error is "Cannot convert String to State Label". So I guess my question is, is it possible to pass a string as a state label and how do I convert it?
Last edited by Nash on Mon Nov 28, 2016 4:28 am, edited 1 time in total.
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49252
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: ZScript Discussion

Post by Graf Zahl »

At the moment you cannot convert a runtime string to a state label. That feature hasn't been implemented yet because it never was in the old scripting branch.
It's on my list but more toward the bottom.
User avatar
Nash
 
 
Posts: 17505
Joined: Mon Oct 27, 2003 12:07 am
Location: Kuala Lumpur, Malaysia
Contact:

Re: ZScript Discussion

Post by Nash »

Ah, alright. Well, at least it's good to know that the concatenation indeed works (I added A_Log calls just before the state jump and it seems to be producing the correct strings, "BloodSpot1" "BloodSpot2" etc). I guess I'll try to it another way for now.
Locked

Return to “Scripting”