[SOLVED]Creating objects at random position and delete later

For questions about using Classic.

Post » Sun Apr 17, 2011 11:14 pm

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):
[code:3878vfr1]
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. http://dl.dropbox.com/u/12049513/Construct/GE/alpha.cap
B
3
G
2
Posts: 35
Reputation: 770

Post » Mon Apr 18, 2011 3:09 pm

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
B
3
G
2
Posts: 35
Reputation: 770

Post » Mon Apr 18, 2011 5:10 pm

Error with the link. says the cap doesn't exist?
B
19
S
6
G
7
Posts: 1,206
Reputation: 7,300

Post » Mon Apr 18, 2011 5:53 pm

Here is an example for that first aspect that may be helpful:
[url:iyz7kjc4]http://dl.dropbox.com/u/5426011/examples4/createOnObj.cap[/url:iyz7kjc4] 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.[/quote:iyz7kjc4]
Try the system condition "for each".
B
79
S
24
G
54
Posts: 4,750
Reputation: 40,763

Post » Mon Apr 18, 2011 7:40 pm

[quote="chrisbrobs":d82p7jd2]Error with the link. says the cap doesn't exist?[/quote:d82p7jd2]
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

[quote="R0J0hound":d82p7jd2]Here is an example for that first aspect that may be helpful:
[url:d82p7jd2]http://dl.dropbox.com/u/5426011/examples4/createOnObj.cap[/url:d82p7jd2] made in 0.99.97[/quote:d82p7jd2]
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.

[quote="R0J0hound":d82p7jd2]Try the system condition "for each".[/quote:d82p7jd2]
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
B
3
G
2
Posts: 35
Reputation: 770

Post » Mon Apr 18, 2011 9:38 pm

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 :

[url:3u4gos7v]http://dl.dropbox.com/u/22173473/StarSytems.cap[/url:3u4gos7v]

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.
B
19
S
6
G
7
Posts: 1,206
Reputation: 7,300

Post » Wed Apr 20, 2011 7:28 am

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! :D

Best regards,
Noel
B
3
G
2
Posts: 35
Reputation: 770

Post » Wed Apr 20, 2011 11:28 am

.uid

unique id in the expression list

is a unique number for each instance of anything on the layout
Spriter Dev
B
88
S
21
G
12
Posts: 3,240
Reputation: 16,486

Post » Wed Apr 20, 2011 12:52 pm

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? :mrgreen: I will mark this one as solved.


Best regards,
Noel
B
3
G
2
Posts: 35
Reputation: 770


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 5 guests