(SOLVED) How do I give each object a diferent instance

0 favourites
  • 6 posts
From the Asset Store
Hand-painted tiles, objects, animated objects, and background to build a colorful Mayan civilization environment.
  • I want to give my all-ready created enemys (objects) a "name" (instance variable) that is different from the others (enemy1, enemy2, enemy3 etc...) as it solves tons of problems for me later on.

    I use for that a global number (EnemyName) that should increase every time the "for each" works.

    The problem thats driving me mad is that it works on tests but not in the actual project!

    It sets all the TileEnemys (objects) to the exactly same name (the global "enemyname"+1)

    Actual Project Code:

    https://ibb.co/kqBLO7

    Test Code:

    https://ibb.co/m4RyAn

  • It's pretty obvious if you compare the two, look at the order of the events in actual compared to test. The test code is correct picking, every time you pick an enemy you set the name to the glob var then add 1 to glob var. In actual you are adding 1 to glob var for every enemy, so the total number of enemies, then setting the enemy name for all enemies to the glob var number. Be careful with the order of events and sub-events, you've done it correctly in test code though so I can see you know what you're doing.

  • I want to give my all-ready created enemys (objects) a "name" (instance variable) that is different from the others (enemy1, enemy2, enemy3 etc...) as it solves tons of problems for me later on.

    I use for that a global number (EnemyName) that should increase every time the "for each" works.

    The problem thats driving me mad is that it works on tests but not in the actual project!

    It sets all the TileEnemys (objects) to the exactly same name (the global "enemyname"+1)

    Actual Project Code:

    https://ibb.co/kqBLO7

    Test Code:

    https://ibb.co/m4RyAn

    I would check two things

    1-if the Global (EnemyName) from the Actual Project Code: is by mistake Type = Txt instead of Number

    or

    2-if the (Txt box) where you show the debug names are calling the Right TileEnemy.TagName

    example

    Every Thick >> Set Txt Box >>To TileEnemy.TagName

    Because this sounds weird [quote:1sb986o4]to the exactly same name (the global "enemyname"+1)

    specifically this part >> "enemyname"+1

    at last if it was wrong it should be "enemyname"+the total Number of Enemies >>not +1 only, all the enmies should have added 1 to the Global, still is wrong but it shows like you had only one enemy calling when is not that's why I will look on those places first

  • It's pretty obvious if you compare the two, look at the order of the events in actual compared to test. The test code is correct picking, every time you pick an enemy you set the name to the glob var then add 1 to glob var. In actual you are adding 1 to glob var for every enemy, so the total number of enemies, then setting the enemy name for all enemies to the glob var number. Be careful with the order of events and sub-events, you've done it correctly in test code though so I can see you know what you're doing.

    I tried using that exact order but when I do that (the image below) some strage things happens too: The global variable that started in 1 gets to 4 as expected (because there are only 3 enemys that increase 1), but all the Tagnames are called the same "Enemy1" as if the data from the global variable was extracted only once for the 3 objects before it changed to 2,3 and 4.

    https://ibb.co/dkPGfn

    PS: I checked all those things tarek2 and many more, but thanks for the suggestions!

  • Naurgalen

    [quote:22fek3zx]PS: I checked all those things tarek2 and many more, but thanks for the suggestions!

    sure no problem, I just mentioned because I saw that the txt box from the Test Project was calling the "EnemyName" & EnemyName but maybe that was your intention

    can you share your events to display the text boxes? and how you link them to the Enemies on the Actual Project

    or if you like you can remove any extras and send me capx just enough showing the problem by pm or share it here will be easier to resolve the Problem

    For me both Methods worked fine it must be something else that conflicts with your events instead of the other, I do agree with Pinkie though that is the correct way of ordering the events

    Capx: https://www.dropbox.com/s/gb1ldgu4zq3cd ... .capx?dl=0

    Capx2: https://www.dropbox.com/s/lsobfebnnmi52 ... .capx?dl=0

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I solved it! 2 days of MADNESS and finally!

    The problem was in a part of the code AFTER the event. (I searched the code for the error allways BEFORE it, not even thinking about other possibility)

    Im sure its a rookie mistake that every programmer will have fun off, but how I suffered for it.... lol =P.

    It really helped a TON, having lots of folders/groups to disable/enable and sectorize the problem. I highly recommend it.

    Thnx all for the help!

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