How to deal with weapon action function in scripting
- Graf Zahl
- Lead GZDoom+Raze Developer
- Posts: 49225
- 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.
- Major Cooke
- Posts: 8208
- 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: How to deal with weapon action function in scripting
Yes, I did. I meant crash prevention itself.
- Graf Zahl
- Lead GZDoom+Raze Developer
- Posts: 49225
- 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.
- Major Cooke
- Posts: 8208
- 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: 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)
- Graf Zahl
- Lead GZDoom+Raze Developer
- Posts: 49225
- 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.
- Major Cooke
- Posts: 8208
- 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: 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
}
}
- Graf Zahl
- Lead GZDoom+Raze Developer
- Posts: 49225
- 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
}
}
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
}
- Major Cooke
- Posts: 8208
- 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:
- Graf Zahl
- Lead GZDoom+Raze Developer
- Posts: 49225
- 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
}
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?
- Graf Zahl
- Lead GZDoom+Raze Developer
- Posts: 49225
- 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.
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.
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.
- Major Cooke
- Posts: 8208
- 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: 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.