How to deal with weapon action function in scripting
-
- Lead GZDoom+Raze Developer
- Posts: 49182
- Joined: Sat Jul 19, 2003 10:19 am
- Location: Germany
Re: How to deal with weapon action function in scripting
Haven't you read this thread? It was all about dealing with the bad access. Of course you have to add null pointer checks.
-
- Posts: 8196
- Joined: Sun Jan 28, 2007 3:55 pm
- Preferred Pronouns: He/Him
- Location: QZDoom Maintenance Team
Re: How to deal with weapon action function in scripting
Yes, I did. I meant crash prevention itself.
-
- Lead GZDoom+Raze Developer
- Posts: 49182
- Joined: Sat Jul 19, 2003 10:19 am
- Location: Germany
Re: How to deal with weapon action function in scripting
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.
-
- Posts: 8196
- Joined: Sun Jan 28, 2007 3:55 pm
- Preferred Pronouns: He/Him
- Location: QZDoom Maintenance Team
Re: How to deal with weapon action function in scripting
Ah, so we would do
to ensure they have the variable?
Code: Select all
if (target != null && target.num != null)
-
- Lead GZDoom+Raze Developer
- Posts: 49182
- Joined: Sat Jul 19, 2003 10:19 am
- Location: Germany
Re: How to deal with weapon action function in scripting
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.
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.
-
- Posts: 8196
- Joined: Sun Jan 28, 2007 3:55 pm
- Preferred Pronouns: He/Him
- Location: QZDoom Maintenance Team
Re: How to deal with weapon action function in scripting
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
}
}
-
- Lead GZDoom+Raze Developer
- Posts: 49182
- Joined: Sat Jul 19, 2003 10:19 am
- Location: Germany
Re: How to deal with weapon action function in scripting
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
}
}
-
- Posts: 788
- Joined: Wed Feb 23, 2011 11:04 am
- Preferred Pronouns: No Preference
Re: How to deal with weapon action function in scripting
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
}
-
- Posts: 8196
- Joined: Sun Jan 28, 2007 3:55 pm
- Preferred Pronouns: He/Him
- Location: QZDoom Maintenance Team
-
- Lead GZDoom+Raze Developer
- Posts: 49182
- Joined: Sat Jul 19, 2003 10:19 am
- Location: Germany
Re: How to deal with weapon action function in scripting
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
}
-
- Posts: 788
- Joined: Wed Feb 23, 2011 11:04 am
- Preferred Pronouns: No Preference
Re: How to deal with weapon action function in scripting
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?
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?
-
- Lead GZDoom+Raze Developer
- Posts: 49182
- Joined: Sat Jul 19, 2003 10:19 am
- Location: Germany
Re: How to deal with weapon action function in scripting
That's not defined yet.
I guess something like 'typeof(object)', but don't nail me on it.
I guess something like 'typeof(object)', but don't nail me on it.
-
-
- Posts: 10773
- Joined: Sun Jul 20, 2003 12:15 pm
Re: How to deal with weapon action function in scripting
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.
-
- Posts: 788
- Joined: Wed Feb 23, 2011 11:04 am
- Preferred Pronouns: No Preference
Re: How to deal with weapon action function in scripting
This got me wondering, is load order going to be an issue?Graf Zahl wrote:Code: Select all
if( BFG9000(target.player.ReadyWeapon))
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 Fishytza on Wed Oct 19, 2016 11:30 am, edited 1 time in total.
-
- Posts: 8196
- Joined: Sun Jan 28, 2007 3:55 pm
- Preferred Pronouns: He/Him
- Location: QZDoom Maintenance Team
Re: How to deal with weapon action function in scripting
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.
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.