Random every x seconds and division not working

0 favourites
  • 4 posts
From the Asset Store
2D fighting template based in the game that defined the fighting games genre.
  • 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).

    Any help much appreciated.

    Jimzip

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 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.

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

    Jimzip

  • 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:

    To me it looks like a division by 0 issue.

  • Oh! I never thought to check for an expression for this. I learn something new about Construct every day. Thanks ! 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

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