• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Random position, timer and delay

H

happylives

Guest
Hi there,

I have a question, i'm having a 'monster' that shoots three bombs, between the shooting i want it to delay and generate a random position. I did this with a while loop and later with a recurring function. The first and second shot are random, but the third shot always has the same position as the second shot. I know this is caused by the clock used as a seed for the random generator. However i tried to created a pause in between the shooting, point being the (delay/pause) seems to be ignored. I don't know how to solve this. The feature 'delay between shooting' isn't really revolutionary. So i hope that one of you guys could help out.

GML:
amountOfShots = argument0;
pauseTimer = argument1;
paused = argument2;



if(paused) {
    if(pauseTimer <= 0){
        paused = false;
        pauseTimer = 300;
        Shoot(amountOfShots, pauseTimer, paused)
    } else {
        pauseTimer -= 1;
        Shoot(amountOfShots, pauseTimer, paused)
    }
}
   
if(paused == false and amountOfShots > 0){
    instance_create_layer( 500, 500, "Bombs", pointerB);
    amountOfShots -= 1;
    paused = true;
    Shoot(amountOfShots, pauseTimer, paused)
}
Thank you in advanced and for your time!
Happylives
 
H

happylives

Guest
when it is paused it counts down... and calling it self with the new updated values,

what i want is to shoot 3 times, with a delay inbetween, and every shot a random position, in short.

i reverted it back to how it was before:

GML:
while(amountOfShots > 0) {
    if(paused) {
        if(pauseTimer <= 0){
            paused = false;
            pauseTimer = 300;
        } else {
            pauseTimer -= 1;
            show_debug_message(pauseTimer)
        }
    }
    
    if(paused == false){
        instance_create_layer( 500, 500, "Bombs", pointerB);
        amountOfShots -= 1;
        paused = true;
    }
}
 
Last edited by a moderator:

Nidoking

Member
That's an infinite loop. There should be no loops at all in a correct implementation of what you're trying to do. You need to give the game time to do the thing and come back to shooting in a later step. The first thing you posted was a lot closer to correct, but I don't think you've properly thought out what the function should do when paused, and what it should do when unpaused. Think, plan, THEN write.
 
Top