Behavior just affecting the selected actor

Photon

  • Posts: 2697
The problem is simple. Game attributes are universal attributes, and if one actor accesses it, it changes it for everyone. They are not unique to a specific actor. So if I understand the problem correctly, make it a behavior-based attribute to make it local to each specific actor.
Do NOT PM me your questions, because I likely will not respond. If I have replied to your question on the forum, keep using that topic. Thanks!

bergapappa

  • Posts: 48
dtrungle - yes I have tried with a GA, and I think Photon just told us why this don't work.

This GA will be true for all actors.

I will try to make it a Behavior Attribute.
Feels like it will be the same though, all my players need this "makeActive" behavior.
But only one at a time should be the "activeplayer", so only this one is up for a move, turn or shot.

Will try it though.

bergapappa

  • Posts: 48
You'll need a scene behavior that has a purpose of holding the current active actor, because an actor can not be stored in a GA. This behavior only needs an attribute of type-actor, (actorCurrent).

You'll need a generic actor behavior that has a purpose of:
If [click on self],
   [For this scene, set (actorCurrent) to [self] for behavior]
I tried but Im not sure I did it correct.
Cannot find a block for "self"
When the mouse 'is pressed on' 'Actor'
       Set actorCurrent to 'Actor'

Then i did a When Drawing like this
      Draw text 'actorCurrent' at ( x: 50 y: 50)

This only draws the name of the actortype I choose as default for my attribute actorCurrent.

Ideas?

This cannot be that hard, going bananas :-)

dtrungle

  • *
  • Posts: 1938
You'll need a scene behavior that has a purpose of holding the current active actor, because an actor can not be stored in a GA. This behavior only needs an attribute of type-actor, (actorCurrent).

--

You'll need a generic actor behavior that has a purpose of:

If [click on self] >(needs to be 'self', it refers to itself, the actor)
   [For this scene, set (actorCurrent) to [self] for behavior] >([self] block is in scene->actor, or search 'self'?)

--

For scene or actor behavior, depending on how you're setting up your game.
Whenever you want to give an action to the current active actor, such as set x-speed:

Set [x-speed] to 10 for [For this scene, get (actorCurrent) from behavior]

--

Again, this all depends on how you're coding it. From what I read recently, you don't seem to need the actor at all. You just want a boolean to indicate if it is active.

Let me know how it goes for you.

EDIT: Yes, if your draw text or print actorCurrent, you get the ActorType. But if you use actorCurrent as an actor, it will refer to the actor that gave the value(actor/self).

Photon

  • Posts: 2697
I will try to make it a Behavior Attribute.
Feels like it will be the same though, all my players need this "makeActive" behavior.
But only one at a time should be the "activeplayer", so only this one is up for a move, turn or shot.

Will try it though.

The difference with the behavior attribute is that each actor has its own copy of the attribute. If you change it in one, it will not change for the other.

Here is my suggestion. For each clickable actor, have a behavior with two booleans. Use one for registering the click (let's call it "Clicked?") and one for registering when the mouse has left the actor (let's call it "Off Actor?"). With both of these set to a default of False, use the following three events:

--When mouse is pressed on self: Set Clicked? to True
--When mouse enters self: Set Off Actor? to False
--When mouse exits self: Set Off Actor? to True
(Note: I don't know how you want to handle unselecting (Set Clicked? to False). Right now, I leave that to you).

Now, attach a scene behavior to the scene with the following event:

When mouse is pressed:
    For every actor of specified type:
        If Clicked? and Off Actor?:
            Rotate (or whatever action you are looking for)

That sound good?
Do NOT PM me your questions, because I likely will not respond. If I have replied to your question on the forum, keep using that topic. Thanks!

bergapappa

  • Posts: 48
This sounds very good Photon.

Made this Actor Behavoir - got an error though.
Pls read it further down if you know what this could be.

1 related questions:

Will I be able to check these two attributes from another behavior as you suggest from the scene behavior, I thought this only could be done with GAs?

THX so much man!

The Error:
"
TypeError: Error #1034: Type Coercion failed: cannot convert stencyl.api.engine::GameState@5a920b1 to stencyl.api.engine.actor.Actor.
   at stencyl.api.engine.behavior::Behavior/initScript()[/home/stencyl/stencyl.net/jenkins/jobs/StencylWorks-Dist/workspace/plaf/flash/root/stencyl/api/engine/behavior/Behavior.as:109]
   at stencyl.api.engine.behavior::BehaviorManager/initScripts()[/home/stencyl/stencyl.net/jenkins/jobs/StencylWorks-Dist/workspace/plaf/flash/root/stencyl/api/engine/behavior/BehaviorManager.as:109]
   at stencyl.api.engine::GameState$/initBehaviors()[/home/stencyl/stencyl.net/jenkins/jobs/StencylWorks-Dist/workspace/plaf/flash/root/stencyl/api/engine/GameState.as:708]
   at stencyl.api.engine::GameState/loadScene()[/home/stencyl/stencyl.net/jenkins/jobs/StencylWorks-Dist/workspace/plaf/flash/root/stencyl/api/engine/GameState.as:556]
   at stencyl.api.engine::GameState/begin()[/home/stencyl/stencyl.net/jenkins/jobs/StencylWorks-Dist/workspace/plaf/flash/root/stencyl/api/engine/GameState.as:300]
   at Function/<anonymous>()[C:\Users\patrikb\AppData\Roaming\Stencyl\stencylworks\preview\scripts\MyAssets.as:193]
"


Photon

  • Posts: 2697
Not overly familiar with these error messages, but based on what I noticed, "Type Coercion" sounds like you are trying to use the wrong type of data somewhere. For instance, you might be supplying text where it needs a number. Looking at it again, it looks like maybe something is looking for an actor and you are giving it something different ("cannot convert stencyl.api.engine::GameState@5a920b1 to stencyl.api.engine.actor.Actor."). Not entirely sure though.

As for your related question, my suggestion would be that if any other behaviors want to get to those attributes, have them call the scene behavior to do the legwork (like what it would do for what was mentioned before), and then have the scene behavior send the data needed to those specified behaviors.
Do NOT PM me your questions, because I likely will not respond. If I have replied to your question on the forum, keep using that topic. Thanks!

bergapappa

  • Posts: 48
Hi again Photon

Looked over the very few behaviors I have and cannot find any fault.
Removed the one I made after your suggestions.
Then I dont get the error.
Made a new one with different names just in case. (From my little programming experience I know some names can be reserved)
Then I get the error again.

Did you try making the behavior?


Photon

  • Posts: 2697
Can you post the behavior you made?
Do NOT PM me your questions, because I likely will not respond. If I have replied to your question on the forum, keep using that topic. Thanks!

bergapappa

  • Posts: 48
Hi again

It's silly, but I don't seem to be able to paste an image on the forum.
How do everybody do this?

Photon

  • Posts: 2697
When you go to post, look below the text box for something like "More Options" (I can't remember at the moment exactly what it is called). Attachments should be one of those options.
Do NOT PM me your questions, because I likely will not respond. If I have replied to your question on the forum, keep using that topic. Thanks!

bergapappa

  • Posts: 48
OK, Attached 3 pics

gplar

  • Posts: 1118
Jumping in a bit late in this, but it seems to be getting unnecessarily complicated. If I got your original problem right, it is to make an actor "Active" so that group/type actions only affect that actor.

I have used Actor values to achieve this. In this way you let the actor know it is active and react accordingly. In this way you leave it to the actor to only react when active.

on creating an actor:
set actor value MeActive for last created actor to 0

on mousedown on actor:
set actor value MeActive for self to 1

When actions are taken on actor group:
For each actor of metype
If get actor value MeActive for actor of type as number = 1
Actions

Thn only the active actor is affected.

Remeber to reset value to 0 when actor is no longer active.



« Last Edit: December 15, 2012, 10:50:31 am by gplar »

bergapappa

  • Posts: 48
Perfect, as easy as I thought from the beginning :-)
Let's see if I get why my other approach did not work.
This way, with actor values, the value correspond to the specific actor instance, and when I used the attribute all actors of that type was effected.

Is this right?

Lets say I don't want more than one actor instance should not be able to be active.
Any suggestions for this?
I'm thinking about an attribute that tell if there are any active actors or not?

TNX a lot man, have been going crazy over this!