Help a begginer to create a special behavior

trakeure

  • Posts: 18
Hello everybody ! :)
 
I introduce myself, I'm French (sorry for my english ..  :-[ ) and mobile game developer (I started one month ago , so I'm beginner).
I began to develop my game, advancing rather quickly, knowing that I learned all while on the job so I'm pretty proud of me but I am having some difficulties >:( .
In fact, I'd tried to create a behavior which consist of when the actor appears in the scene has a definite time life (9 seconds for example, that I can do) but if I take and moves the actor and puts it in an area that I set before this,  the definite time is cancelled and also cannot die.  I can not find a solution :'( ..

So can you help me please ?
Thank you !
Trakeure.

« Last Edit: February 26, 2014, 08:32:46 am by trakeure »

iNK

  • Posts: 68
Hi, can you post your code for the time-delayed actor death?

I hope I understood your problem correctly - if so I have a solution.

I've attached a screenshot of all events but let me explain it in a little more detail:
a) I created two new boolean attributes, New and Invincible.
b) In the create function I set New to true and Invincible to false. I also created a region (Scene -> Regions; for this example I used the whole right half of the screen).
c) In the update function I checked for the state of New. If true, it was set to false and a timer started (here I followed your example of 9 seconds). Inside the time loop I also checked for Invincible. If false, the actor was subsequently killed.
d) Now, here is where the region comes to use: I created two additional events that checked for how the actor interacted with the region (Add Event -> Actors -> Enters or Leaves a Region). When he entered, Invincible was set to true. That means, he couldn't die while in the region. Afterwards, when he left the region, Invincible was set to false (so he could die again) and New was set to true (so the timer could start anew).

When I tested the behavior inside of the Crash Course Kit, it worked exactly like expected.
This solution only checks for the last created region though, so you can only use one safe-haven at a time. I suppose you could also "define" several regions by checking whether the actor's x/y values are inside the x/y areas you want them to be - though that might lead to clumsier code.

Let me know if that solved your mishap - or whether you wanted to know something completely different ;)

Cheers,
IITH

trakeure

  • Posts: 18
I created the first behavior (die after time) attached to my actor (a bomb) which includes the creation of an "actor" but acts as an explosion.

And my second behavior which is attached to the actor "explosion"  that disappear after its creation thanks to "fade out".

My goal now is when actors are in a defined region, time and preset death are canceled and remains living in the area.

trakeure

  • Posts: 18
Hello IsleInTheHeavens,

I think that your help would be the begin of my solution.
The problem is that I have 2 defined region who actors can remains living and can't move outside of it.  So I don't know if it is adapt for me but I would test to see  ;D

So I test it, but it doesn't work. The actor continue to die even if he is on the defined region. In your codage I don't understand what means New and Invincible ?

« Last Edit: February 26, 2014, 01:46:30 pm by trakeure »

trakeure

  • Posts: 18
I tried to ensure that the player doesn't die and continues to live in a region defined but it doesn't work .. I'll put the code.
Am I on the good way ? Have you other ideas ?

Hey trakeure,
basically what the two new attributes "New" and "Invincible" do is determine whether the actor can/should be destroyed.

["New" = true] is assigned to the actor every time he is created and whenever he leaves the safe region. It makes him behave like a fresh, "new" actor. The "if new -> set new to false" routine in my "always" event behaves similar to your "if not fading -> set fading to true" routine. Only when an actor is "new", i.e. his state for "New" is true, the 9 second countdown starts to play. And since "New" is set to false in the same routine, the countdown only plays once (until the player's state is altered).
["Invincible" = true] however is assigned when the actor reaches the safe region. Since the actor is killed only if "Invincible" is false, he shouldn't die while inside of the region.

When I tested the behavior with the Crash Course Kit, I simply tried waiting inside and outside of the region to see what happened. Inside the actor survived unlimited. Outside the actor vanished after exactly 9 seconds. That's what I expected when I wrote the "kill self" function.

In your case however, you have to be careful to whom and where you assign the attribute "Invincible". From your code bits I don't see which actor you want to keep alive. The bomb or the explosion?
On a related note, I have to say, I don't really understand why you would need two separate actors. Seeing as how you make your first actor create the second one upon being killed off, wouldn't one actor with different animations be enough (one bomb-animation and one explosion-animation)?

My suggestion would be to assign the "Invincible" attribute (or however you want to call it) to your bomb actor and only kill it and create the explosion if "Invincible" is checked as false, i.e. he's not in the safe region.
I'd say the important part here is to make sure that you can create a condition where your actor can't be killed. When that is done you can still go on and change the areas where that is the case.

I hope this helps to clarify what I wanted to use these two attributes for.


P.S.: Concerning your newest code bits:
In the last part, when you disable "Die After Time", what code is in that behavior "Die After Time"? Is it the "always" loop containing the 4 second countdown? If so, that is where the problem might lie:
Once you start that loop, it is guaranteed that the actor is killed - there is no "if" condition. Even if you enter the region during the 4 second interval, the "disable" function only prevents the "Die After Time" behavior in further updates. The ones that were already started will be executed to the end. That's why I used "Invincible" as an attribute. This way, I could tell the game inside of the time loop that I didn't want to kill the actor if he was inside of the region.

Good luck with your game!


EDIT: I just had a lovely little moment of "eureka": To allow for multiple safe-havens, you simply have to create multiple regions in the "create" function. After every single one of them you then have to declare them as individual attributes (type: region). This way, you can later on check for the actor entering/exiting multiple regions, instead of just the "Last Created Region".
I modified my screenshot accordingly.

« Last Edit: February 26, 2014, 05:17:09 pm by IsleInTheHeavens »

trakeure

  • Posts: 18
Hi ,

Okay I thank you for these explanations I understand :)

Oh ok , I think it works for you in the Crash Course Kit because it's a platform game while mine is rather style RPG games, no ?

The "Invincible" should be attributed to the bomb as the actor "explosion" ,in the end, is only a animation. So yes I could make my job easier by putting the actor "explosion" as animation bomb . This is what I do at the beginning but later the animation don't working at all .. so I decided to built it as actor .

Also you know that I have two types of bomb in my game and appear in large numbers throughout the game

Oh yeeees ! : o yes, I did not thought about it at all on the loop. This is actually the reason why it does not work I think.

Oh , I didn't  know it was possible to do this, it would make my job easier! I will immediately test your solution ! : D

Again thank you for your help! :)

Edit : It ruuuuuun ! Amazing, I'm so happy aha :p after 3 days of research, you found the solution so thanks a lot ! :D
Now that it works I could test it, but after a while the game start lag and slow. What can it come? The purpose of my game is to put bombs in their camps so they appearing a lot  from one place. This is perhaps the reason it lag ?  that there is so many actors?

« Last Edit: February 27, 2014, 03:16:30 am by trakeure »

Glad the fix worked.

About the lag: I probably won't be able to help you with that (I'm also still learning with Stencyl - nowhere near performance optimization yet).
But if all you want to do is put bombs into their respective camps, what do you do with them once they're inside their camps? Do you keep the actors alive? If so, I could see lag happening there. I'd suggest to kill/recycle every actor that is put inside the right camp and then raising the pertaining score. For looks, you can simply show a picture (or an animation) of a bunch of bombs inside of the camp. If you already do that, I have no idea what else to do to save resources.

trakeure

  • Posts: 18
Once the respective camps of bombs is "full" (20 bombs) it will count in the score and send it to another screen and will not work again in the game . You understand?

Sorry. As I said earlier, I don't know what else you could do to avoid lag.
All I can suggest is this article about actor performance: http://www.stencyl.com/help/viewArticle/51

Good luck and go on having fun with Stencyl,
IITH