Switching Character Behavior

Murad

  • Posts: 151
So I'm working on a switching character behavior for my game. In it, you have the basic player, but he can switch between 3 others. I attached this behavior to the main player and, after hitting the switching character button, he successfully switches to the next character in the order, but when the button is hit again to switch to the next character, the current player on screen jumps to a different spot in the scene and doesn't switch at all. For this behavior to work, it needs to be able to switch between all 4 characters using the switching character button. But I can only switch once. I've attached a picture of the behavior, any help would be much appreciated! Thanks!

Alexin

  • *
  • Posts: 3130
First thing first, you should create actors before killing the current one.

Are you sure the behavior is attached to all characters and not the first one only?
"Find the fun"
alexin@stencyl.com

herby

  • Posts: 124
There's probably a lot of complications here.

First, this behaviour should be attached to all players that can switch. You said you attached it to the main player, and there it worked, but then it did not work on subsequent player. It could not if it wasn't attached to the next type as well.

Second, you said that after second hit the player jumped somewhere else. That is _very_ strange. You are probably using the "switch button" for something else, as well. Nothing should have happened.

Third, what is "Actor Type" in create actor block? It looks like you haven't selected the actor type to create.

Fourth, even if you attached switching behaviour to other actor types as well, it would always switch to the same thing (the one that is specified in create actor block).

To solve the third and fourth complication at once, you should have "Next State" attribute in the switching behaviour, of type "Actor Type", _not_ hidden, so it can be parametrized for each use of behaviour. Then you should attach it to any actor type that can switch to something else. Then, on the actor's page, in the behavior tab, you should fill this attribute with the type of the next stage.
And, last but not least, you should put the "Next State" attribute inside the (Actor Type ) part of the create actor block in the switching behaviour.

Murad

  • Posts: 151

@herby: Yes, I had this behavior attached to all the actors that can switch, it works perfectly fine the first time it is pressed, but messes up each subsequent time. No the switch character button is used only for switching characters. The actor type is the next character in line for switching, and its an attribute the creator fills in when attaching the behavior, which I did.

I'm really not seeing what could go wrong but it just doesn't work.

« Last Edit: June 23, 2011, 08:27:11 am by mozzy »

herby

  • Posts: 124

@herby: Yes, I had this behavior attached to all the actors that can switch, it works perfectly fine the first time it is pressed, but messes up each subsequent time. No the switch character button is used only for switching characters. The actor type is the next character in line for switching, and its an attribute the creator fills in when attaching the behavior, which I did.

I'm really not seeing what could go wrong but it just doesn't work.

That's strange, then... put there some debugging output... either print block or, to be visible in the game itself, appending to Text type game attribute and drawing it in when drawing ... phase in some scene bahviour (so it is not affected by actor changes). It can show you where the code got run, in what order, and some other things like values of the attributes, if you append them as well.

asherryan

  • Posts: 13
I have the same thing in my game you can switch into 4 characters on the fly. ;(Are you coping me):JK
PLAY IT HERE still a demo, tons of bugs have been fixed in the final version.
http://www.stencyl.com/game/play/3539

I had to make that same rule in four different behaviors, then place each one onto each actor.

So "change to actor 2" goes on actor 1, "change to actor 3" goes on actor 2, and so on.

Hope that helps

Asher
B-Side Games

« Last Edit: June 23, 2011, 08:51:40 am by asherryan »

Murad

  • Posts: 151
@Herby: I'm sorry, but i have no clue what you're trying to say.

@asherryan: I would prefer to keep it at one behavior, I created this behavior before and it worked just fine, until Stencyl destroyed it. I have no idea why its not working now.

herby

  • Posts: 124
I made some experiments, there was a hideous trap involving timing and "control was pressed" value.
As far as I was tried in a tryout game, it works. Find it as "Switching Type" behaviour in forge.

Murad

  • Posts: 151
Works great! Thank you! Now, how can I have it so that the behavior only works in the game after winning an object/achievement/reaching a goal?

herby

  • Posts: 124
disable it by default, enable it by enable behaviour block.