How do I manage events on objects not created yet ?

0 favourites
  • 13 posts
From the Asset Store
2D fighting template based in the game that defined the fighting games genre.
  • Hi guys, here's a hard one :

    I'm trying to create a Tower Defense game.

    Currently, I have only one type of turret possible, the basic gun turret with a turret behavior, which shoots bullets with a bullet behavior. So far so good.

    As in 99% of Tower defense games, you may place more than one of the same turret type, right ? Right.

    But I also would like to be able to upgrade my turrets individually, and not all the same turrets of the same type at once.

    So I have to create a container with all upgrade buttons I have, and associate them with my tower, to make each same upgrade buttons associated with their own tower, and all distinct from each others, right ?

    This way, every single tower (of the same type) will have its own upgrade options, and their variables will be independent too (range, speed, power, etc...)

    ______________________________________________

    Now comes the hard part : The only way I can think of to upgrade bullet power is to set a variable somewhere (supposedly inside the bullet) that reduces the enemies life by the value of that variable, which represent the damage the bullet does. Which mean I need the bullets to be in the same containers as the turrets, because if not, every single bullet is gonna share a single power variable, and upgrading towers individually will work, but not for bullet power, because turret firepower is not relative to the tower, but to its bullet. (stop me if i'm wrong so far)

    BUT ! If I include bullets in the same container as the turret, then the turret is gonna be destroyed as soon as the bullet gets destroyed/another turret may spawn when a turret shoots (spawns) a bullet...

    So I am cornered. No way to make bullets separate from each other in properties without including the tower they originate from in the same container, which creates various problems.

    So here is the question : How do I make my bullets make a certain amount of damage to enemies , depending of which tower they have been fired from ?

    Good luck.... And thank you very much to anyone who will try to help

  • You can potentially do this by making different bullet objects for different levels of turret. So something like,

    On Turret shoot

    [sub-event] Turret lvl=1 --> Shoot Bullet1

    [sub-event] Turret lvl=2 --> Shoot Bullet2

    etc.

  • Hi SupWithThat?

    Thank you for you answer. This is a solution indeed, however this would mean having as many bullets objects as I have of levels of power, times the numbers of turret I will have in the future, which could be maybe 10 (no idea yet), resulting in hundreds of bullets and hundreds of events...

    Not suitable i'm afraid. But thanks for your reply !

  • You don't need the bullets in a container. Spawn the bullet and store the turret's UID, so you can pick it again in the future when you need to reference the master object (turret).

  • For my main game, which is quite large, I have a layout called "Layout of Things" here I place all the things that spawn at some point in the game so that I can reference them. In smaller games I just place them in the layout but outside, on the grey area so that it's there but can't be seen.

  • You don't need the bullets in a container. Spawn the bullet and store the turret's UID, so you can pick it again in the future when you need to reference the master object (turret).

    Hmmm Im afraid I dont quite understand that. Im very new to this software... Could you explain a little bit for me please ?

    Thank you

  • Hi blackhornet

    Thank you so much for your reply ! I had a look on the finished product without looking a lot at the events yet, because I am trying to figure out things myself (as I wait for the answer), and Im actually pretty close !

    I managed to select any turret I want (whether it has been created before or after start of layout), I managed to upgrade the "strength" of any turret I want independently, and now I'm just starting trying to apply "instance turret strength value" to "spawned bullet from same instance tower damage value".

    However, I still have some trouble understanding the difference between "=" and "<>", but I do understand there is a difference between them, since "=" doesnt work and "<>" does work when I am clicking on a tower to select it, using a global variable "SelectedUID" set to the selected tower UID, and a boolean for towers to make the difference between a selected tower and the rest.

    Another thing I have trouble with is the difference between "pick instance BY COMPARAISON" and "pick instance BY EVALUATE"... Any light on that matter would be absolutely delighful.

    I did notice the "ParentUID" value in your event sheet, this might be the key to my upcoming challenge.

    I will try to manage this myself for now, and if I really cannot do it, I will explore your event sheet. Copying things does not mean understanding it, and if I really want to be good at using this software, I need to understand it thoroughly.

    But thank you so much for your answer, you demonstrated exactly what I wanted to do !

  • Why so difficult ?

    Upgrade the towers. Including an instance variable for damage done by a bullet. Bullet has instance variable damage.

    Right after spawning the bullet set its instance variable to the (up-gradable one) from the tower.

    Compare on impact.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Why so difficult ?

    Upgrade the towers. Including an instance variable for damage done by a bullet. Bullet has instance variable damage.

    Right after spawning the bullet set its instance variable to the (up-gradable one) from the tower.

    Compare on impact.

    This would make sense if I only had a single tower, no ?

    If I create additionnal similar towers once the game is launched, I need to associate bullets to their parents tower in order to make a difference between bullet powers, fired by different towers with different power values. Im working on this right now.

  • Hey guys, bump.

    Tried several things, and could not get the game to pick the right bullets.

    Here is my capx file : dropbox.com/s/yd6i2sm4u2mh8 ... .capx?dl=0

    click the tower to select it, then you can upgrade it clicking "upgrade" button. You can also create new instances of the same tower by clicking "create".

    I need the bullets coming from each different instances of the same turret to have different damage values.

    ANy help would be greatly appreciated. Thank you <img src="{SMILIES_PATH}/icon_e_smile.gif" alt=":)" title="Smile" />

    EDIT : cannot post urls... heres printscreen instead :

  • Uh no, instance variables are always personal for that instance.

    Are the towers turrets and do you use 'on shoot' ?

  • Last bump : I DID IT !!

    I followed blackhornet 's capx, but at first I chose the base event to be "on bullet spawned" instead of "on turret shoot" But now its all good, now I have to redo everything on the actual game -_- but im very happy, thank you very much guys !

    99Instances2Go => figured that out litterally 2 minutes ago

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