How do I access attributes of other behaviors/actors?

weirdAbacist

  • Posts: 5
From my limited programming experience, I've gleaned that "attributes" are like local variables and "game attributes" are like global variables. A vital part of my Stencyl game requires one actor to access certain attributes from other actors, and due to the local nature of attributes I've had some difficulty accomplishing this. I've tried the getter/setter from Behavior>Attributes, but that didn't work.

I dislike revealing information on my actual game, but I'll propose a test scenario that deals with the problem in question:

Assume that I have two enemy actors that follow enemy behaviors. One of the attributes of this behavior is a boolean WeakToFire. One enemy has this set to true, and the other has it set to false. When the player hits an enemy with a fire attack, the player needs to check the enemy's WeakToFire attribute to determine the damage done.

This seems like such a basic feature of most video games that I'm mortified to ask for help, but I am completely stumped. Any feedback is appreciated.

hansbe

  • Posts: 262
I think the behaviour getter/setters should work as long as you got the actor right, and behavior and attribute name right.

But it might be much simpler to trigger an event in a enemy behavior. To create such an event use 'create custom event' under 'advanced'. Then the player can do something like "trigger Take Damage in Enemy One".

Also if you use collision to determine if enemies are hit, it might not be necessary for the player actor to have any direct communication to the enemy.

weirdAbacist

  • Posts: 5
I think the behaviour getter/setters should work as long as you got the actor right, and behavior and attribute name right.

But it might be much simpler to trigger an event in a enemy behavior. To create such an event use 'create custom event' under 'advanced'. Then the player can do something like "trigger Take Damage in Enemy One".

Also if you use collision to determine if enemies are hit, it might not be necessary for the player actor to have any direct communication to the enemy.

I get the impression that collisions are one of the prime tools of Stencyl; the player attacking the enemies would do so via a menu-based input akin to RPG battles, although I suppose I could create invisible actors for the sole purpose of dealing damage. Doable, but not very elegant.

Hmm... on second thought... new proposition. If the player had an actor attribute Target, and I set Target to be Enemy1, would I have access to all attributes of Enemy1 through the Target attribute? Something along the lines of "Player.getTarget().getWeakToFire()."

I just gotta convert my limited Java knowledge to Stencyl terms. Heh. ;D

Ryusui

  • Posts: 827
For an RPG, keep track of enemies using Scene Behavior attributes or Game Attributes.

For the record, BTW, I'd put the combat logic in a Scene Behavior as well.
In the event of a firestorm, the salad bar will remain open.

hansbe

  • Posts: 262
@weirdAbacist: For the stencyl blocks that export to multiple platforms you should probably get the getters/setters to work. Game attributes can also be used to pass information as Ryusui says.
If you'd rather do native programming you can use the code blocks or code mode. Flash AS3 is not so dissimilar from Java, but a fair amount easier IMO. You could create a package with your own Player class, and create attributes and methods. If you mark these attributes and methods as static they will be accessible from anywhere, like in your example. You will not have to instantiate a Player object even, all you need to do is to import the package where you use it.

froz

  • Posts: 250
Quote
Hmm... on second thought... new proposition. If the player had an actor attribute Target, and I set Target to be Enemy1, would I have access to all attributes of Enemy1 through the Target attribute? Something along the lines of "Player.getTarget().getWeakToFire()."

Creating attribute Target and set it to enemy actor should do the work, I'm doing something similar in my project.

Then just use "for Target get _WeakToFire from behaviour whateveritis". Stencyl is so polite that you don't have to remember internal name, just choose from the dropdown list (attribute names).

You need Target attribute anyway to apply damage to the enemy, don't you?

I would not do it via Game Attributes, I believe it could get very messy very quickly, especially if you have more attributes you would need to check.