[SOLVED]Creating objects at random position and delete later

This forum is currently in read-only mode.
From the Asset Store
Easily generate many levels from a set of pre-built scenes (Construct 3 template)
  • Hello!

    I want to create x instances of a sprite at random locations on the screen in a certain area, whereas x is a global variable. I also need to give each created instance different values for their private variables.

    What I figured out so far (but doesn't work):

    10 IF: button clicked
    20   THEN: delete starsystem
    30      IF: global('starsystem_creation_counter') is lower than global('number_of_starsystems')
    40         THEN: starsystem set position x: random(1024) y: random(768)
    50            IF: starsystem overlaps creation_area_sprite
    60               THEN: starsystem: spawn starsystem
    70               THEN: add 1 to global('starsystem_creation_counter')[/code:3878vfr1]
    
    Instead of creating the number of starsystems/sprites it only creates one, and if I click another time, nothing happens at all and the one generated starsystem/sprite vanishes. I have no clue what is going on.
    
    I also have no clue on how to make them 'unique' after their creation, so I can deal with them each for their own. Any help would greatly be appreciated.
    
    Best regards,
    Noel
    
    PS: *.cap of what I've done so far. Ignore the other layout. [url=http://dl.dropbox.com/u/12049513/Construct/GE/alpha.cap]http://dl.dropbox.com/u/12049513/Construct/GE/alpha.cap[/url]
  • BUMP.

    The .cap is updated with my latest version... I changed the complete script, and it behaves a bit better now. Still not doing what I intended. Please have a look at it... I know some of you can help me, please...

    Best regards,

    Noel

  • Error with the link. says the cap doesn't exist?

  • Here is an example for that first aspect that may be helpful:

    http://dl.dropbox.com/u/5426011/examples4/createOnObj.cap made in 0.99.97

    [quote:iyz7kjc4]I also have no clue on how to make them 'unique' after their creation, so I can deal with them each for their own. Any help would greatly be appreciated.

    Try the system condition "for each".

  • Error with the link. says the cap doesn't exist?

    I updated the *.cap, wrong path - sorry. It includes the most actual changes because I work directly with the dropbox-copy. Link again: http://dl.dropbox.com/u/12049513/Construct/GE/alpha.cap

    Here is an example for that first aspect that may be helpful:

    http://dl.dropbox.com/u/5426011/examples4/createOnObj.cap made in 0.99.97

    This pretty much is what I wanted to do, it's mostly like I did it. I will try to clean up my code and see what the problem is.

    Try the system condition "for each".

    Maybe I wasn't too clear about what I wanted to do... I need to give each of the created sprites unique values for their private variables and need to know when the player clicks on a specific sprite (they're some kind of "levels" and you need to get to the apropriate layout when clicking on them)... But I think I managed that by giving them a numerical ID as private variable right after the creation of every single one. It just don't work. They all have ID 0 except for the last one, that has a value = number of created sprites...

    Maybe some ideas (looking at the cap will help you more than reading my explanations I think) why this happens? Thanks for you help so far!

    Best regards,

    Noel

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • If you create the Star system objects using a loop (indexed to the number typed in the edit box) Each one will have its own unique private variable.

    Here's a cap :

    http://dl.dropbox.com/u/22173473/StarSytems.cap

    1, Click the 'generate' button.

    2, Click on each Star system to display its unique number.

    Hope this helps.

    P.S The Sprites Objects you are using are way too big(1027 x 768)(the download is over 5 meg), Why dont you cut then up into smaller tiles, if you dont the game will always run slow.

  • Hello,

    I did try a for-loop, but somewhat different and it didn't work. Your solution is the clever one because of the LoopIndex. Thanks for the lesson!

    Best regards,

    Noel

  • .uid

    unique id in the expression list

    is a unique number for each instance of anything on the layout

  • Hey lucid, thanks for your tip! I knew that internal uids exist before, but the problem is that they are not given in - what humans would call - logical order. Rather theyre given rather randomly and mixed together with other elements on the layout. So it's hard to keep track of them.

    At the moment I numerate them while creating them, ensuring I got uids for 25 stars ranging from 1-25.

    But maybe there is any chance you can help me with my next problem? I will mark this one as solved.

    Best regards,

    Noel

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