How to access custom actor functions - Probably scope issue

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!

Moderator: GZDoom Developers

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!)
Post Reply
TheSartremaster
Posts: 20
Joined: Thu Jun 15, 2023 1:29 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): Windows10 / Ubuntu 22.04.3
Graphics Processor: ATI/AMD (Modern GZDoom)

How to access custom actor functions - Probably scope issue

Post by TheSartremaster »

Hi,

I want an actor to access a custom function of another actor.
I.e., when one of my enemies dies, I want it to instill panic in the other enemies around them. The issue is, in my code below the "CausePanic" function tells me that it does not know the "IncreasePanic" function ("Unknown function IncreasePanic").

Code: Select all

class WalpurgisNightEnemy : Actor
{
	
	int currentPanicInt;
	property CurrentPanic : currentPanicInt;
	
	int PanicThresholdInt;
	property PanicThreshold : PanicThresholdInt;
	
	double panicRangeDouble;
	property PanicRange : panicRangeDouble;

	
	void IncreasePanic(int increaseAmount)
	{
		currentPanicInt = currentPanicInt + increaseAmount;
	}
	
	bool DecreasePanic(int decreaseAmount)
	{
		//Don't go below 0
		if(decreaseAmount > currentPanicInt)
		{
			currentPanicInt = currentPanicInt - decreaseAmount;
		}
		else
		{
			currentPanicInt = 0;
		}
		
		//return true if no longer panicked.
		if(currentPanicInt > 0)
		{ return true; }
		else
		{ return false; }
	}
	
	void CausePanic(int amount, double rad)
	{
		//Create Iterator
		BlockThingsIterator PanicTargets = BlockThingsIterator.Create(self, rad);
		
		while(PanicTargets.Next())
		{
			let obj = PanicTargets.thing;
			
			if(obj.bISMONSTER && obj.health > 0 && Distance3d(obj)<=rad)
			{
				obj.IncreasePanic(amount);
			}
		}
	}
	
	Default
	{
		//$Category "WN_Monsters"
		+ISMONSTER;
		WalpurgisNightEnemy.CurrentPanic 0;
		WalpurgisNightEnemy.PanicThreshold 5;
		WalpurgisNightEnemy.PanicRange 256;
	}
}
I suspect my issue is that the BlockThingsIterator is not being allowed to access the functions of other actors. My instinct would be, to give the functions the equivalent of a "public" keyword, but those do not seem to exist here?
I tried to figure out object scropes (https://zdoom.org/wiki/Object_scopes_and_versions), but those do not seem to work. Giving IncreasePanic the "clearscope" or "virtualscope" flag does not work (I just get the additional error that the expression inside "must be a modifiable value", while the Cause Panic function still does not know the IncreasePanic function). Omitting the function and trying to access "obj.CurrentPanic" or "obj.CurrentPanicInt" also does not work.

Does anyone know where to set what flag or if I need a completely different approach?

Thanks in advance!
Jarewill
 
 
Posts: 1853
Joined: Sun Jul 21, 2019 8:54 am

Re: How to access custom actor functions - Probably scope issue

Post by Jarewill »

You will have to cast the actor as your specific class.
Like this:

Code: Select all

let obj = WalpurgisNightEnemy(PanicTargets.thing);
If(obj && /* rest of the checks */ )
TheSartremaster
Posts: 20
Joined: Thu Jun 15, 2023 1:29 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): Windows10 / Ubuntu 22.04.3
Graphics Processor: ATI/AMD (Modern GZDoom)

Re: How to access custom actor functions - Probably scope issue

Post by TheSartremaster »

Yes! Thanks so much.
That seems to have worked!
Post Reply

Return to “Scripting”