Can I set repeat to 0 times?

Discussion and feedback on Construct 2

Post » Sat Oct 03, 2015 4:45 pm

Hi,

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

thx
My professional Royalty Free Music at Scirra Assets Store
--------------------------------
Specs: i5 2500, 16gb of ram, gtx 770, win 7, Focusrite Scarlett 8i6, Mackie mr8mk2, Alesis 320, browsing the net on chrome.
B
89
S
30
G
22
Posts: 1,985
Reputation: 20,099

Post » Sat Oct 03, 2015 4:56 pm

nope. won't happen. you repeat each subevent 0 times - therefore nothing happens.
Sea Monsters template - Isometric
Also includes 40 pages PDF of optimizations and "how-to" for your games, and how the "sea monsters" template was built. Follow link for details :)

sea-monsters-templates-and-assets_t162705
B
43
S
14
G
12
Posts: 626
Reputation: 9,450

Post » Sat Oct 03, 2015 5:45 pm

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
Image
Game Producer & Independent Developer - http://raphaelgervaise.com
B
24
S
9
Posts: 237
Reputation: 2,232

Post » Sat Oct 03, 2015 5:50 pm

Refeuh wrote: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?
My professional Royalty Free Music at Scirra Assets Store
--------------------------------
Specs: i5 2500, 16gb of ram, gtx 770, win 7, Focusrite Scarlett 8i6, Mackie mr8mk2, Alesis 320, browsing the net on chrome.
B
89
S
30
G
22
Posts: 1,985
Reputation: 20,099

Post » Sat Oct 03, 2015 6:32 pm

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.
ImageImageImageImage
B
157
S
66
G
42
Posts: 2,603
Reputation: 35,343

Post » Sat Oct 03, 2015 6:49 pm

shinkan wrote: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 :)
My professional Royalty Free Music at Scirra Assets Store
--------------------------------
Specs: i5 2500, 16gb of ram, gtx 770, win 7, Focusrite Scarlett 8i6, Mackie mr8mk2, Alesis 320, browsing the net on chrome.
B
89
S
30
G
22
Posts: 1,985
Reputation: 20,099

Post » Sat Oct 03, 2015 7:43 pm

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
Sea Monsters template - Isometric
Also includes 40 pages PDF of optimizations and "how-to" for your games, and how the "sea monsters" template was built. Follow link for details :)

sea-monsters-templates-and-assets_t162705
B
43
S
14
G
12
Posts: 626
Reputation: 9,450

Post » Sun Oct 04, 2015 4:05 am

i use repeat -> choose(0,1) to make an event happen with 50% probability, and it works. You can also use different ratios.
B
65
S
22
G
4
Posts: 358
Reputation: 6,555

Post » Sun Oct 04, 2015 10:12 am

Danwood wrote: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! :D

Thanks everyone for you help!
My professional Royalty Free Music at Scirra Assets Store
--------------------------------
Specs: i5 2500, 16gb of ram, gtx 770, win 7, Focusrite Scarlett 8i6, Mackie mr8mk2, Alesis 320, browsing the net on chrome.
B
89
S
30
G
22
Posts: 1,985
Reputation: 20,099


Return to Construct 2 General

Who is online

Users browsing this forum: AnD4D and 16 guests