[SOLVED THANK YOU :)] Collision question

miralina

  • *
  • Posts: 14
Hi all!  I am new to Stencyl so please forgive my newbie question...

I am (in the very early stages of) creating a farm sim game and I have several pieces of dirt that when clicked create a seedling. I don't want any more seedlings to be created on that particular piece of dirt until the seedling dies.  I am having trouble getting the dirt to recognize that the seedling is gone!  I have tried triggering events, setting the dirt behavior attributes from the seedling events, and testing to see if the dirt is colliding with a seedling. 

Am I having trouble because the seedling is created on top of the dirt?  Am I going about this the completely wrong way?

Thank you so much in advance :)



« Last Edit: November 18, 2012, 12:24:30 pm by miralina »

chrizt

  • Posts: 345
in my opinion you dont need to use colliding for that. if seedling die>> set (boolean attributes) seedling is gone for the dirt to recognize its gone.then do whatever you want after that. hope this can help :)
need help with behavior? game design? graphic design? just contact me
skype : christian.atin
email : christianatin27@gmail.com

miralina

  • *
  • Posts: 14
Thank you for your reply!  This is what I tried originally... but I can't get it to work either!  Am I doing something wrong?

Thanks!


miralina

  • *
  • Posts: 14
Actually this latest solution sort of worked... when the last seedling on the last patch of dirt (there are three) died, all the isplanted? attributes for all three patches of dirt turned to false, and the game got incredibly laggy.  Is this because I am "always" to set planted to false for Last Created Actor?  I don't know how else to refer to the seedling on the current patch of dirt...  Any insight appreciated :)

dtrungle

  • Posts: 1938
For the seedling behavior,

Change '-0' to '0' for your timer. (it just doesn't look right to me lol)
Delete your 'when self is killed' event. Place your amIdead? setter above 'kill self' in the click event. (you know what, you don't have to change this at all, I'm just not use to this style)

For the dirt behavior,

In 'always', use a 'For each actor of type' loop. Inside this loop place your 'If' in it. Instead of 'last created actor' use 'actor of type' from the loop.

You will need to use more 'For each' loop if you plan on adding more dirt squares.

miralina

  • *
  • Posts: 14
Thank you so much for your reply!  I didn't know about for each loops, they seem really useful.

Is this correct?  The planted? attribute still is remaining "true" after the plant is dead...I'm so frustrated with this attribute, haha!

dtrungle

  • Posts: 1938
In seedling behavior,

move 'set amIdead' from 'when self is killed' to below 'switch animation to dead'

That 'when self is killed' event works/activates when the actor is killed or recycled. In your case, this actor is still alive, it only gets an animation change and its 'state' is dead.

chrizt

  • Posts: 345
the last always block is very bad i think. you not even compare something in the if condition. if (get attribute value amIdead) = true
set planted to false.

also when the mouse in released on self
if alive = false
set amIdead? to true >> set attribute am i dead to true then kill your self :)
then kill self

you dont need to use when self is killed for that.
i have zero knowledge in programming. but what i believe if you can make code line shorter the better the performance will be.

if you still cant fix it, feel free to add me on skype christian.atin
i can help you a bit

« Last Edit: November 14, 2012, 08:03:36 pm by chrizt »
need help with behavior? game design? graphic design? just contact me
skype : christian.atin
email : christianatin27@gmail.com

miralina

  • *
  • Posts: 14
Thank you chrizt and dtrungle!

I don't know why my planted? attribute still won't change to false!

Would scene behaviors work better here than actor behaviors? I will have a set number of dirt actors on the screen, I just want them to be able to be replanted when something dies. 

Thank you for the coding tips, I agree clean coding is the best!  I would settle for working code at this point LOL :)  will hop on skype tonight if I still can't figure it out :)

miralina

  • *
  • Posts: 14
oops forgot to attach code!

dtrungle

  • Posts: 1938
For seedling behavior,

in 'always', use this:

If ([wateredAmount > 0] AND [wateredAmount < 50] AND [animation of self =/= withered])
=>(you need to check up on what [animation of self] block returns to make sure it's comparing correctly)
  -switch animation to withered
End

If ([wateredAmount <= 0] AND [alive == true])
  -set alive to false
  -switch animation to dead
  Do after 4 seconds
    -set amIdead? to true
End

In 'when created', set wateredAmount to 100.
You don't need the 'mouse released on self' event.

~

For dirt behavior,

under 'create seedling',
-add 'set cachePlant to last created actor' (cachePlant is a Actor attribute)

in 'always',
-remove the 'for each loop'
-add 'If cachePlant has value' as a condition check before going to the next 'If'
-in the second 'If' use cachePlant as the actor to get from
-under 'set planted? to false', add kill(cachePlant)
-add 'clear value of cachePlant' under the above

~
This should work. I didn't build the code, it's the logic/steps for it.

miralina

  • *
  • Posts: 14
Ok I tried that code and it still DIDN'T WORK!  I noticed an error in the debug referencing an attribute that didn't exist in my game... so I started wondering if something was corrupted in my game somehow.  I started a completely fresh game, and simplified my code for testing purposes.  And it WORKED!  Finally I can stop banging my head on the desk in frustration :)

Thank you for all of the help :)  I learned so much from your comments!

Attached is the code that performs the function I want (being able to plant and replant the dirt again with seedlings after they die) , in case anyone else is having a similar issue.   Obviously I need to go back and add in my animations etc :)

dtrungle

  • Posts: 1938
Your seedling behavior has two 'kill self' blocks, that may cause you grief.
Your dirt behavior refers to 'last created actor', that will likely cause you grief because you will have multiple dirts and seeds in the scene.

miralina

  • *
  • Posts: 14
thanks for the catch!  The kill self after 10 seconds was just for a quick test, forgot to remove for screenshot.

Well I have 9 dirts in the scene and the last created actor seems to be working fine...but I will definitely make a plantCache attribute now that I know how!

 So does lastCreatedActor refer to the actor that was created by self, or the last created actor in the game?

miralina

  • *
  • Posts: 14
I did notice some strange things with lastCreatedActor!  The plantCache is working splendidly this time around :)