How to deal with weapon action function in scripting

Discuss anything ZDoom-related that doesn't fall into one of the other categories.
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 48039
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: How to deal with weapon action function in scripting

Post by Graf Zahl »

Haven't you read this thread? It was all about dealing with the bad access. Of course you have to add null pointer checks.
User avatar
Major Cooke
Posts: 8070
Joined: Sun Jan 28, 2007 3:55 pm

Re: How to deal with weapon action function in scripting

Post by Major Cooke »

Yes, I did. I meant crash prevention itself.
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 48039
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: How to deal with weapon action function in scripting

Post by Graf Zahl »

The best you can get is a message 'null pointer access in function 'blahblah' and have the game terminate. It should be clear that this will put a lot more responsibility in the hands of modders.
User avatar
Major Cooke
Posts: 8070
Joined: Sun Jan 28, 2007 3:55 pm

Re: How to deal with weapon action function in scripting

Post by Major Cooke »

Ah, so we would do

Code: Select all

if (target != null && target.num != null)
to ensure they have the variable?
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 48039
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: How to deal with weapon action function in scripting

Post by Graf Zahl »

If you do not have num it'd give you an error at compile time. This is not Javascript where you can attach any arbitrary new variable to an object.
You also need to cast 'target' to the proper type first if you want to access information from a child-class. It also means that, if you want to give a new property to multiple classes, they need to have the same base class where you define that new property.
User avatar
Major Cooke
Posts: 8070
Joined: Sun Jan 28, 2007 3:55 pm

Re: How to deal with weapon action function in scripting

Post by Major Cooke »

So something like this, for target casting type?

Code: Select all

class MCD : Actor 
{
	Default
	{
		int whatever = 2;
	}
}

class Checker : Actor // Should this be inheriting from MCD?
{
	States
	{
	Spawn:
		TNT1 A 0 NoDelay
		{
			if (CheckClass("MCD",AAPTR_TARGET))
			{
				MCD SpecialTarget = target;
				if (SpecialTarget)
				{
					bool check = (SpecialTarget.whatever > 0) ? true : false;
				}
			}
		}
		Stop
	}
}
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 48039
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: How to deal with weapon action function in scripting

Post by Graf Zahl »

More like this:

Code: Select all

class Checker : Actor // Should this be inheriting from MCD?
{
   States
   {
   Spawn:
      TNT1 A 0 NoDelay
      {
            MCD SpecialTarget = MCD(target);
            if (SpecialTarget)
            {
               bool check = (SpecialTarget.whatever > 0);
            }
      }
      Stop
   }
}
User avatar
FishyClockwork
Posts: 726
Joined: Wed Feb 23, 2011 11:04 am
Preferred Pronouns: No Preference

Re: How to deal with weapon action function in scripting

Post by FishyClockwork »

Okay, so something like this will work?

Code: Select all

//Instead of calling GetWeapon() from ACS
if( Actor(target.player.ReadyWeapon).CheckClass("BFG9000") ) //assuming nothing is NULL
{
   //stuff
}
User avatar
Major Cooke
Posts: 8070
Joined: Sun Jan 28, 2007 3:55 pm

Re: How to deal with weapon action function in scripting

Post by Major Cooke »

User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 48039
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: How to deal with weapon action function in scripting

Post by Graf Zahl »

FishyClockwork wrote:Okay, so something like this will work?

Code: Select all

//Instead of calling GetWeapon() from ACS
if( Actor(target.player.ReadyWeapon).CheckClass("BFG9000") ) //assuming nothing is NULL
{
   //stuff
}

Code: Select all

if( BFG9000(target.player.ReadyWeapon)) //assuming nothing is NULL
{
   //stuff
}
No need to cast to intermediate types.
User avatar
FishyClockwork
Posts: 726
Joined: Wed Feb 23, 2011 11:04 am
Preferred Pronouns: No Preference

Re: How to deal with weapon action function in scripting

Post by FishyClockwork »

I had a feeling I could do that.

So how do I get an actor's classname and store that in a variable to compare it with other things?
In particular, say I have two actors: target and tracer. I don't know what classess they are and I don't care.
What I do care is if the two actors are the same class but not the same entity. How do I do that?
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 48039
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: How to deal with weapon action function in scripting

Post by Graf Zahl »

That's not defined yet.
I guess something like 'typeof(object)', but don't nail me on it.
User avatar
Xaser
 
 
Posts: 10771
Joined: Sun Jul 20, 2003 12:15 pm

Re: How to deal with weapon action function in scripting

Post by Xaser »

Seems like the decision is pretty much a done deal, but +1 from me anyway on Graf's goal to keep self as the player and have invoker be the weapon. This matches what DECORATE modders expect, plus we finally get to access those pesky weapon vars through invoker.
User avatar
FishyClockwork
Posts: 726
Joined: Wed Feb 23, 2011 11:04 am
Preferred Pronouns: No Preference

Re: How to deal with weapon action function in scripting

Post by FishyClockwork »

Graf Zahl wrote:

Code: Select all

if( BFG9000(target.player.ReadyWeapon))
This got me wondering, is load order going to be an issue?

IE is this gonna get me an error?

Code: Select all

//'A' references 'B' even though 'A' is defined before 'B'
class A : Actor
{
    B other;
    States
    {
        ...
        ...
        BLEH A 2 { other = B(tracer); };
        ...
        ...

    }
}
class B : Actor
{
     //stuff
}
Last edited by FishyClockwork on Wed Oct 19, 2016 11:30 am, edited 1 time in total.
User avatar
Major Cooke
Posts: 8070
Joined: Sun Jan 28, 2007 3:55 pm

Re: How to deal with weapon action function in scripting

Post by Major Cooke »

And at long last overlays can have their own variables to initialize and use.

Oh man. Other actors having overlays is going to be fun. I suspect with zscript they'll currently be able to perform multiple states similar to how overlays work, only they don't draw images... yet.

Return to “General”