Behavior just affecting the selected actor

bergapappa

  • Posts: 48
Hi

I'm having trouble with a behavior affecting all actors of the same Type.
Have an Actor Type called redPlayer.
There are 2 redPlayer on the board.
Made a behavior that gives a game attribute (activeplayer) "True" if you click on one of these two.
Then I made another bahavior that are supposed to turn the previosly selected player 90 degrees when you click on any other place on the board than on this player.
My problem is that this affect both redPlayers.

How would one go about when you only want a behavior affecting one Actor within the same Actor Type?

I have read the chapter about customizing Actors, but seems the other way around.

Please help a very new user.

Regards

bergapappa

Tuo

  • *
  • Posts: 2469
You can use a scene actor loop to find which actor specifically was clicked on by comparing the locations to the x and y of the mouse. I have a few demos on how to do it. If you search StencylForge for "Demo-" you can find all of them. The best is probably the jigsaw one for you to manipulate to what you need.
Don't look to me but rather to the One who is the reason for what I do. :)

If you need help, send me a PM. Even if I haven't been on in the forums in ages, I still receive those messages via email notifications. You can also reply to any of my forum posts, regardless of the age (especially if I created it), and I will likely reply.

If you want to see the programming behind certain types of games, feel free to check out my "Demo-" games on StencylForge (http://community.stencyl.com/index.php/topic,16160.0.html)

bergapappa

  • Posts: 48
TNX, had a quick look, will look further later.

But it looks hard :-)

When you use "set clickedActor to - Actor of type" does this mean that the attribute ClickedActor is filled with id for a specific Actor och a Actor Type?
I think this is my big problem.
Cannot separate Actor from Actor Type in my code, cannot se the difference in Stencyl.

dtrungle

  • *
  • Posts: 1938
The way I see it, Actor refers to a specific Actor(the ID). Actor Type refers to the base of the Actor for example, you have a Red Ball actor. You can have a dozen of Red Ball actors in the scene. The Actor Type is Red Ball and each actor is their own Actor(have their own ID).

For most? of the blocks, it will not allow you to stick an Actor Type block inside a slot that takes Actor blocks.

bergapappa

  • Posts: 48
That is exactly the way I want to see it.
But what block do i use that Will refer to the actorid?

Can you please give me an example like this.
When mouse click on an actor - store actor id in an attribute.
Then for example, call an event that turns just this actor 90 degrees
And not all of that actor type in the scene.

Pretty please with sugar on top!

dtrungle

  • *
  • Posts: 1938
For scene behavior,

In 'when created'

set id_List to (create new list)
For each ActorOfType - ActorType
   add ActorOfType to id_List


In 'always'

If (mouse was pressed on [get item#0 from id_List])
   rotate [get item#0 from id_List]
Otherwise if (mouse was pressed on [get item#1 from id_List])
   rotate [get item#1 from id_List]


Note: If you print ActorOfType or the (Item), you get Actor Type(the name of the actor). So, this is not storing the ID of the actor. I'm not sure how this would work if you store these "actors" in a game attribute and use them in different scenes.

Note: I looked around and getting an actor's ID is easy but I'm not sure how you would refer to a specific Actor given an actor ID. I'm guessing that you would have to compare each actor on screen to the stored actor ID. Even still, I'm not sure how it would work if the scenes gets changed or the game restarts.

bergapappa

  • Posts: 48
Sorry, but I donĀ“t get it.
Total newbe and haven't used lists.

Could you please make a screen shot for me?


Another thing.
I cannot belive it should be this difficult identifying an actor.
Would have liked to have a game attribute as what actor is the selected one. The "Active" one.
So I could have my Behaviors start with a check if the actor is "Active", so the only affect this actor.
Everything seems to be about ActorType.
I will have one red Actor Type and one Blue. Withing these there will be several actors. Think a game of checkers, and I want to Identify which red Actor the user selected and are about to ex. move.

Please help, going crazy here.
Think this one will increse my understanding of Stencyl, I obviously missed something during the introduction  >:(

dtrungle

  • *
  • Posts: 1938
What I wrote is the code itself in text. The blocks are there, search for the keywords. You will need to work with lists for what you're doing.

Try to setup my code and see if it works for you. The code works by storing the actor. I think this is all you'll need.

If you really want the ID, it will be more coding for you. What do you plan to do with the ID? There are no blocks that use it.

bergapappa

  • Posts: 48
OK, I'll try again tonight, maybe I'll get it right.

But are you sure Lists is needed for this.
I would think this should be fairly simple.

I have to ask it this way again:

Would have liked to have a game attribute as what actor is the selected one. The "Active" one.
So I could have my Behaviors start with a check if the actor is "Active", so they only affect this actor.
Everything seems to be about ActorType and not Actor.
I will have one red Actor Type and one Blue. Withing these there will be several actors.
Think a game of checkers, and I want to Identify which red Actor the user selected and are about to ex. move.

dtrungle

  • *
  • Posts: 1938
What you want is,

-To store the selected actor in an attribute.
If (actor) is selected.
Store (actor) as actorCache (attribute, actor).

-To move only the stored actor.
'Set x of actorCache' would change the x value for that actor.

This is what you want right?
You may have difficulties if you reload the scene and try to use the same stored actor.

bergapappa

  • Posts: 48
Yes, something like that.
I will only use one scene in play.
It's will be a board game, like chess och checkers but ofcourse with a twist :-)
The perfekt solution would be something like a game attribute that I can use in every behavior.
Lets call the attribute "activepiece".

Then when the player clicks on piece, this one is the "activepiece".
Then when I make ex. a move behavior I can check so only the "activepiece" is affected by the behavior. Could be a button I click to turn the "activepiece" 90 degrees or similar.

This is why I think it seems overkill using lists.
I only want to identify one piece.

I thought this would be a piece of cake, and it was till I added a second piece of the same Actor Type. Then they both got affected by my behaviors.

BTW, TNX for your patience!

Regards

bergapapp

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],
   [For this scene, set (actorCurrent) to [self] for behavior]

Now, whenever you want to refer to it, for example change the x-speed.
Set [x-speed] to 10 for [For this scene, get (actorCurrent) from behavior]

That should work out. Let me know how it goes for you.

Last resort is to try it with actor id. I believe it would lower your game performance depending on the usage.

« Last Edit: November 19, 2012, 12:31:52 pm by dtrungle »

Photon

  • Posts: 2697
Excuse me, but if I may...
Made a behavior that gives a game attribute (activeplayer) "True" if you click on one of these two.
Are you using behavior attributes or game attributes? Because that would make a huge difference.
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
Game attribute, Boolean

dtrungle

  • *
  • Posts: 1938
Have you tried what I wrote above? You can use a GA as a boolean flag for if there is an active actor, but that alone can not give you the actor itself to manipulate.