Problem when picking family member for deletion

0 favourites
  • 13 posts
From the Asset Store
A collection of various zombie characters sprites for creating a 2D platformer or sidescroller game
  • Hi! I have two groups. One to create baubles, one to despawn them after a while. When they despawn the "Missed" counter increases by 1 and it seems to work fine except for the very first spawned family member. When the first one appears the variable for "Missed" is instantly incremented by 1 but the first spawned bauble does not disappear.

    I tried to add a global variable as workaround which allows the deletion only after the first one was created but this did not fix or change anything. Does anyone know how to fix this?

    Here is the code:

    <img src="http://img5.fotos-hochladen.net/uploads/spawnbaubleinst9eqdzpkjna.jpg" border="0" />

  • You've taken an interesting approach at having timers on multiple objects. I can't offer any help, but I can offer how I would do it myself.

    ONLY have the instance variable "LifeTime", which gets set to a random number still when it is created, (int(random(1,6))

    And then have an event, that constantly DECREASES the LifeTime variable of the baubles by "dt" (which will make it go down by 1 every second). You may or may not need a "ForEach Baubles" event here, probably not though!

    And then have another separate event, that "Compares instance variable" of the baubles, checking if it's =<0, then "play Sheep sound", destroy, ect.

    I hope this helps somehow!

  • Thanks! I will try this tomorrow. <img src="smileys/smiley1.gif" border="0" align="middle" />

  • Hi. I changed it how you suggested but the same happens.

    When the first bauble is spawned the "Missed" counter is increased by 1 and the bauble is not deleted. <img src="smileys/smiley19.gif" border="0" align="middle" />

    After a few seconds it is deleted and the counter shows 2, but it should be 1.

    <img src="http://img5.fotos-hochladen.net/uploads/spawnbaublealteibe9rtlwdg.jpg" border="0" />

  • Place the "trigger once" conditions in their respective subs and add the actions there.

    else the condition checks get done only once ;)

  • <img src="http://img5.fotos-hochladen.net/uploads/spawnbaublesubenyl3qv1zi.jpg" border="0" />

    Like this, or did you mean something else?

    (Still having the same problem)

  • Sorry, I had overlooked some differences between the first spawn and despawn

    condition 1: pick all baubbles

    condition 2: compare variable

    This made some difference for me when wanting to select actions from multi picks

  • "Compare variable" does only have global vars listed, I tried "compare two values" but now it counts upwards very fast (with and without trigger once) and no baubles appear. :/

    <img src="http://img5.fotos-hochladen.net/uploads/spawnbauble1azj67rgpdc.jpg" border="0" />

  • Hi! I'm still trying to fix this and hope I can try a few other things this weekend.

    Or does anyone else have an idea how to fix this? Any help would be very much appreciated.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • wouldn't on bubble destroyed add one to counter work?

    Or you could use

    for each bubble

    system compare two values: bubbles.lifetime < 0

    • bubble destroy
    • add 1 to missedbaubles
  • I am just taking a wild guess at this. Do you have an off screen Baubles that you are spawning from? If so, then you have 2 Baubles after you spawn the new one. If there is an original Bauble off screen, then that may be the one that is being destroyed which leaves the new Baubles onscreen. Normally I have seen people use a On start of layout > destroy object to account for this type of problem.

    When you change the code to Pick Baubles where Baubles.Lifttime < 0 you stated,

    "When the first bauble is spawned the "Missed" counter is increased by 1 and the bauble is not deleted.   

    After a few seconds it is deleted and the counter shows 2, but it should be 1."

    That increased "Missed" to 1 might be the original and then the second spawned instance onscreen Baubles is destroyed "and the counter shows 2, but should be 1."

    Try deactivating the "Spawning Baubles" and the "Despawning Baubles" groups, and then use the Debugger to track if any Baubles exist at the start of the layout. If there is one that exist, then your first Spawned Bauble is not the first Bauble picked and messing with your Vars and Conditions. Put a Keyboard when key X press then activate "Spawning Baubles" and check debugger again for all Var values # of Baubles and see if they are what you would expect. Then use another key press y to deactivate "Spawning Baubles" and activate "Despawning Baubles." Recheck Vars and # of Baubles to see if it is what your expected.

    I have learned that all to often what I think is happening is not the true "State" or "Status" of my vars or objects and the Debugger quickly reveals where my logic is bad. You can step through each event/action process using the debugger to watch every element taking place when, why, and what happened as a result of each ACE of your Events Sheet. Learning how to use the debugger was the best thing I did to help me to fix and stop writing bad code and how to rethink my logic before writing the code. Yann stated in one of his video tutorials that when the problem is complex, we should write out our logic in English, in my case, what we are trying to accomplish before we start coding. That was the best advice ever. As a result, I bought high quality whiteboard paint and made my sliding closet doors into a 7'x7' brainstorming wall. My ability to get it right the first time or fined problems quicker made all the difference in how I code. Instead digging a deep and complex coding hole that I cannot find my way out of, I just pickup a dry erase pen and eraser and make changes to my logic in a matter of seconds. He suggested getting a small whiteboard which would work to help in developing your logic process first then code and test it. I just when big on the whiteboard because, as you can see my mind runs 100 miles and hour and I need lots of space to get my ideas out.

    If you do not get the problem solve. Could you post your capx. I would love to see if I could help solve the problem, and also learn form your great ideas on how to create processes that I could study then modify to possibly use in my project development also.   Hope all works out for this problem and that maybe you could post the solution for the rest of us to learn from. Thanks.

  • Thank you very much to both of you.

    It's too late to test it now but I think you might be right about the additional objects. I have a few baubles placed on the outside (need to have them there to spawn them?) and forgot to add a "Destroy on Startup" command (which I learned a few weeks ago but totally forgot about). I will take a closer look at the debugger and try to incorporate your suggestions. Writing down the logic of what you want to do is a very good idea. I will try it again tomorrow.

    Thanks for the detailed advices! <img src="smileys/smiley1.gif" border="0" align="middle" />

  • Hi. Seems you were right. I hade multiple baubles on the layout and one of them was counted as missed right at the beginning. I added a Destroy command on Startup and it seems to have fixed it. No 1/10 missed at the beginning. <img src="smileys/smiley1.gif" border="0" align="middle" />

    <img src="http://img5.fotos-hochladen.net/uploads/missedbaublecouixdfenbhpw.jpg" border="0" />

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)