SOLVED Need help with destroy sprites on start of layout

Get help using Construct 2

Post » Tue Apr 04, 2017 12:58 pm

Hello

I have global variable 'Oponents'
On layout i have 100 sprites called 'Enemies'

now

When on start of layout global variable 'oponents' is 10
game at start should leave only 10 sprites other 90 should be destroyed randomly


when i start layout with 60 oponents
at start 40 sprites should be destroyed and 60 should stay etc.
Last edited by IGDev on Wed Apr 05, 2017 12:46 pm, edited 2 times in total.
B
25
S
8
Posts: 215
Reputation: 2,173

Post » Tue Apr 04, 2017 1:02 pm

mmm, u can do:

Start of layout -> Repeat Enemies.count - oponents
Pick random(0, enemies.count)nth instance -> enemies.destroy
B
6
S
2
Posts: 61
Reputation: 1,099

Post » Tue Apr 04, 2017 1:32 pm

ezrubiera wrote:mmm, u can do:

Start of layout -> Repeat Enemies.count - oponents
Pick random(0, enemies.count)nth instance -> enemies.destroy


lets see

when i have 100 sprites on layout and on global variable 'oponents' i have 40

you suggest from counted enemies (100) substract oponents (40)
in that way on layout will be 60 enemies
should be 40
B
25
S
8
Posts: 215
Reputation: 2,173

Post » Tue Apr 04, 2017 1:35 pm

no, u destroy (100 - oponents(40)) = 60
B
6
S
2
Posts: 61
Reputation: 1,099

Post » Tue Apr 04, 2017 1:42 pm

ezrubiera wrote:no, u destroy (100 - oponents(40)) = 60

thats incorreect

60 should be destroyed
because global variable tells 'oponents' is 40
so 40 should stay in game
B
25
S
8
Posts: 215
Reputation: 2,173

Post » Tue Apr 04, 2017 2:06 pm

that is what im saying :)

You destroy 100 - 40 = 60
So u destroy 60, then 40 will stay
B
6
S
2
Posts: 61
Reputation: 1,099

Post » Tue Apr 04, 2017 2:17 pm

ezrubiera wrote:that is what im saying :)

You destroy 100 - 40 = 60
So u destroy 60, then 40 will stay



ok lets try

this is correct? because dont works
https://www.dropbox.com/s/ivinc2sy9k3j6 ... 0.png?dl=0
B
25
S
8
Posts: 215
Reputation: 2,173

Post » Tue Apr 04, 2017 2:23 pm

yes, i think that should work, try to get the int of the random number:

int(random(enemy.count))
B
6
S
2
Posts: 61
Reputation: 1,099

Post » Tue Apr 04, 2017 2:26 pm

changed
https://www.dropbox.com/s/haatfg1c6byox ... 2.png?dl=0

enemies on start of layout is more than 3
B
25
S
8
Posts: 215
Reputation: 2,173

Post » Tue Apr 04, 2017 2:29 pm

give me one moment, I create a new project and I try it
B
6
S
2
Posts: 61
Reputation: 1,099

Next

Return to How do I....?

Who is online

Users browsing this forum: bclikesyou, kalibark2, Lancifer and 28 guests