Random every x seconds and division not working

Get help using Construct 2

Post » Sat Nov 26, 2016 12:02 am

Hi all. This seems simple enough:

Every choose(2,3)/[number of enemy instances] seconds I want to pick a random instance of an enemy and run a function on it.

It works perfectly when I don't divide by anything, but the second I add a "/" the function never fires. What's the dealio here? (The variable "Crab_Count" is the number of instances, by the by. Let's just say it's 3).

Image

Any help much appreciated. :)

Jimzip :D
B
6
S
1
Posts: 28
Reputation: 465

Post » Sat Nov 26, 2016 12:01 pm

Hmm. On closer look it appears there's a problem with the variable "Crab_Count". Though I don't know what it could be.

On start of layout (or on creation of a dark crab enemy) a value of 1 is added to "Crab_Count", but when I try to use that in the "every x seconds" action it breaks. I just tested again with normal division (every choose(2,3)/2 seconds) and it worked.

But that's a problem as I need the function to fire evenly no matter how many instances there are on screen - as in, the wait to trigger the function should scale with the number of crabs.

Image

Anyone got any ideas what might be wrong with the variable? Are you unable to use variables in this way?

Jimzip :D
B
6
S
1
Posts: 28
Reputation: 465

Post » Sat Nov 26, 2016 12:31 pm

@jimzip

Hey Jimzip ;-), can you put in words what you want to do with this? The more enemies on screen the faster they attack? Do you need your own counting variable? You have system exprsssions for this:

Image

To me it looks like a division by 0 issue.
B
33
S
9
G
3
Posts: 206
Reputation: 7,821

Post » Mon Nov 28, 2016 1:45 pm

Oh! I never thought to check for an expression for this. ;) I learn something new about Construct every day. Thanks @MACPK! That gets rid of a lot of unnecessary code.

I actually finally figured out what the problem was however: The variable can't be 0 on start of layout. I had to make it 1, and now it seems to work. -.-

Oddly, when I checked the variable through the debug mode, I could see it was bigger than 0, but the action still wouldn't work. Changing the variable to 1 in the event sheet and testing again, and voila. No problemo.

I realised that I was calculating this wrong anyway though. X)

Jimzip :D
B
6
S
1
Posts: 28
Reputation: 465


Return to How do I....?

Who is online

Users browsing this forum: newt and 12 guests