Can't use Custom Property in script & actor is not interactable

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)

Can't use Custom Property in script & actor is not interactable

Post by TheSartremaster »

Hi,

I am trying to create a bush that the player can pick berries from. Sadly I run into several problems.

This is my code:

Code: Select all

class Bush : Actor
{
	//$Category "DecoNature"
	//$Arg0 Has Berries
	//$Arg0Type 11
	//$Arg0Enum falsetrue
	int HealingPower;
	property HealingAmount: HealingPower;
	
	Default
	{
		Bush.HealingAmount 10;
	}

	
	override bool Used (Actor user)
	{
		if (user && args[0])
		{
			if (user.health < 100)
			{
				HealThing(Bush.HealingAmount,200);
				//HealThing(HealingAmount,200);
				//HealThing(10,200);
				args[0] = false;
				return true;
			}
		}
		return false;
	}
}

class BushSmall : Bush
{
	Default
	{
		Radius 8;
		Height 16;
		Bush.HealingAmount 10;	
	}
	
		
	States
	{
	Spawn:
		BUS1 A -1 NoDelay
		{
			if(args[0]) {return ResolveState("HasBerries");}
			else {return ResolveState("NoBerries");}
		}
	HasBerries:
		Bus1 A -1;
		Loop;
	NoBerries:
		Bus1 B -1;
		Loop;
	
	}
}
Issue 1:
The custom property "HealingAmount" I define in the class Bush does not work when trying to address it in the "Used" function.
If I use "HealingAmount", I get the error "Unknown Identifier "Healing Amount"". If I use "Bush.HealingAmount", I get "HealingAmount is not a member of BUSH"
If I use an int (i.e., 10), the script compiles. However, I would like to have bushes of different sizes and being able to just change the HealingAmount would be great. Also not getting custom properties to run, might be an issue I will run into again, so I thought to better ask now^^

Issue 2: If I get the script to compile, I do not seem to be able to interact with the bushes. Do I have to give them some special flag or set a specific option in the map editor? I got the Used function from here: https://zdoom.org/wiki/Used. None of the "actor specials" seem to do what I want them to either.

Thanks in Advance!
Jarewill
 
 
Posts: 1855
Joined: Sun Jul 21, 2019 8:54 am

Re: Can't use Custom Property in script & actor is not interactable

Post by Jarewill »

You need to use the variable name instead of the property name, so instead of using HealingAmount, you have to use HealingPower.
Now I copied your code and I was able to interact with the bush, so I assume something else is the issue.
If you want the bush to heal the player, you should use GiveBody with the user pointer instead: user.GiveBody(HealingPower,200);
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: Can't use Custom Property in script & actor is not interactable

Post by TheSartremaster »

Thanks so much for your answer.
I adjusted my code as you said and everything works... at least once I figured out I had forgotten to adjust the Health < 100 check :oops:

Just for my understanding: What is the difference between property and variable?
I use the variable (HealingPower) for actual scripting, while I change the property in Default blocks when I want to give different values to the children? Could I just use the variable for everything?
Jarewill
 
 
Posts: 1855
Joined: Sun Jul 21, 2019 8:54 am

Re: Can't use Custom Property in script & actor is not interactable

Post by Jarewill »

Variables are what is actually in the code and what you should check and use, while properties are just aliases for those variables that are there for children classes to modify.
For example if you make a variable called BerryTaste, then you can already use it anywhere in your class' code, but children classes won't be able to specify the default value because it lacks an assigned property.
But if you create a property BerryTaste which is an alias for the variable BerryTaste, each children class will be able to specify it in their Default block as Bush.BerryTaste.

You can still modify those variables in the children classes if you don't assign a property to them, but that will require using an override such as PostBeginPlay, you won't be able to do it in their Default block.
User avatar
ramon.dexter
Posts: 1562
Joined: Tue Oct 20, 2015 12:50 pm
Graphics Processor: nVidia with Vulkan support
Location: Kozolupy, Bohemia

Re: Can't use Custom Property in script & actor is not interactable

Post by ramon.dexter »

For better undestanding, your "physical height" is a property and it has value of your physical height. So the actual value is the variable.
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: Can't use Custom Property in script & actor is not interactable

Post by TheSartremaster »

Ah I see.
Thanks so much, both of you. That made it much clearer for me
Post Reply

Return to “Scripting”