Page 4 of 5
Re: How to deal with weapon action function in scripting
Posted: Tue Oct 18, 2016 3:23 pm
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.
Re: How to deal with weapon action function in scripting
Posted: Tue Oct 18, 2016 4:07 pm
by Major Cooke
Yes, I did. I meant crash prevention itself.
Re: How to deal with weapon action function in scripting
Posted: Tue Oct 18, 2016 4:28 pm
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.
Re: How to deal with weapon action function in scripting
Posted: Tue Oct 18, 2016 5:19 pm
by Major Cooke
Ah, so we would do
Code: Select all
if (target != null && target.num != null)
to ensure they have the variable?
Re: How to deal with weapon action function in scripting
Posted: Wed Oct 19, 2016 12:56 am
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.
Re: How to deal with weapon action function in scripting
Posted: Wed Oct 19, 2016 6:08 am
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
}
}
Re: How to deal with weapon action function in scripting
Posted: Wed Oct 19, 2016 6:32 am
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
}
}
Re: How to deal with weapon action function in scripting
Posted: Wed Oct 19, 2016 6:48 am
by Fishytza
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
}
Re: How to deal with weapon action function in scripting
Posted: Wed Oct 19, 2016 7:04 am
by Major Cooke
Re: How to deal with weapon action function in scripting
Posted: Wed Oct 19, 2016 7:24 am
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.
Re: How to deal with weapon action function in scripting
Posted: Wed Oct 19, 2016 8:04 am
by Fishytza
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?
Re: How to deal with weapon action function in scripting
Posted: Wed Oct 19, 2016 8:17 am
by Graf Zahl
That's not defined yet.
I guess something like 'typeof(object)', but don't nail me on it.
Re: How to deal with weapon action function in scripting
Posted: Wed Oct 19, 2016 11:26 am
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.
Re: How to deal with weapon action function in scripting
Posted: Wed Oct 19, 2016 11:29 am
by Fishytza
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
}
Re: How to deal with weapon action function in scripting
Posted: Wed Oct 19, 2016 11:29 am
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.