Can I set repeat to 0 times?

  • Hi,

    Simple question: Can I repeat 0 times, and will it make sub-events being triggered once pert tick?

    thx

  • nope. won't happen. you repeat each subevent 0 times - therefore nothing happens.

  • Though you could "repeat" 1 time ; everything happens only once. That defeats a bit the point of "repeating", but from a logic point of view that should just work

  • Though you could "repeat" 1 time ; everything happens only once. That defeats a bit the point of "repeating", but from a logic point of view that should just work

    I haave set of sub event's and wanted to trigger them once or more depending on random number. So repeat 1 will trigger those events once or will it repeat once and trigger them twice?

  • Repeat 1 - will run just once

    Repeat 2 - will run twice

    etc

    I have something like this in my game, and works just fine.

    EDIT: In "repeat 2" you will get loopindex = 0 and loopindex = 1. In "repeat 1" you will just get loopindex = 0.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Repeat 1 - will run just once

    Repeat 2 - will run twice

    etc

    I have something like this in my game, and works just fine.

    EDIT: In "repeat 2" you will get loopindex = 0 and loopindex = 1. In "repeat 1" you will just get loopindex = 0.

    Cool, thanks

  • set N= random(some number, some number)

    repeat N times.

    also if you have that set just in event - it will repeat infinitely. (each tick N times) - you have to add some condition that will evaluate when that happens. you can call a function on that random number generation. example

    set N = random(x,y)

    call function repeat (n)

    on function 'repeat'

    repeat func.param(0) times

    - something to do..

    what i'm tryin' to say is that if you don't have that green arrow -> on your event, and no conditions that will stop that event, it will run each tick. the point of making game is that you reduce as much as you can events without green arrow "->". why? because they run each tick and you don't want that. if you want to reduce their time of execution design your game to worth with triggers (events that HAVE "->" green arrow), or use Functions that are called when something happens (usually on triggers).

    here's a good example:

    let's imagine you have a BALL, a guiLife (some life bar that represents objects health), and object. they have variables damage (ball), and health (guiLife and object).

    bad way to do things:

    • object.health < guiLife.health

    - set guiLife.health = object.Health

    - set guiLife.Width = guiLife.health

    and now if you repeat something like this - your object takes some damage and you do this:

    • on ball collision with object

    - repeat (ball.damage) times

    -object.health = object. health - 1

    that's just horrible and performance crippling way to do things. why? when some ball hits your object it repeats the calculation, so that health from object is reduced by that damage but 1 by 1 damage.

    what's the point? the first part is executing the check if objects health is lower then guiLife variable is. it happens each tick. and then executes the code behind if it is true. and what happens if let's say a ball hits your object? let's say it does 10 damage. the upper code repeats 10 times, and ball collision happens only 1.

    so how can you fix that to be better performing? use a function.

    -on ball collision with object - call bla with parameter ball.damage

    on funcion bla

    - repeat (func.param(0) ) times

    - object.health = object. health - 1

    subevent -object.health < guiLife.health

    - set guiLife.health = object.Health

    - set guiLife.Width = guiLife.health

    so what's the difference? well - this only happens ONCE. no checking for difference each tick, nothing. when your ball hits object it will call function that will do the rest. you can throw a wait in there and other stuff to give it different change time, but still way better then when set on each tick. also - when repeat finishes - with function - it's done. when not done with function it will keep checking.

    shit my posts are too long and unfriendly xD

  • i use repeat -> choose(0,1) to make an event happen with 50% probability, and it works. You can also use different ratios.

  • i use repeat -> choose(0,1) to make an event happen with 50% probability, and it works. You can also use different ratios.

    That's a cool way of using it!

    Thanks everyone for you help!

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