In select level tutorial when we set array x to

max(2+stars,levelsat(currentlevel)

then if i want to sum all X values then how do i do it

13 posts
• Page **1** of **2** • **1**, 2

luckyrawatlucky wrote:actually i want to count amount of stars in above linked tutorial

i m new in construct 2 and not getting this point

If it's just a tutorial you are following then you would be best posting the .capx so users can quickly see the problem and offer help.

If your vision so exceeds your ability, then look to something closer.

**Posts:**5,638**Reputation:**61,207

Moderator

B

138
S

31
G

88
here is the link

i want to count total stars here

https://www.dropbox.com/s/n9qq0r1s2rmlb ... .capx?dl=0

i want to count total stars here

https://www.dropbox.com/s/n9qq0r1s2rmlb ... .capx?dl=0

**Posts:**701**Reputation:**34,754

B

74
S

44
G

48
Amount of stars...

Okay found tutorial.

So he stores data as follows

finish level = 1

win = +1

star1 = +1

star2 = +1

star3 = +1

So if a player finishes level and wins and gets 3 stars x = 5

So you want to for each x element

you want to add a condition curent value > 2 [Don't want to count levels without stars]

System add 1 to TotalStars (variable)

Sytem add 1 to NumberStarLevels(variable)

outside loop

System Subtract Totalstars numberstarlevels*2 [because we want to remove the 2 in each]

The above isn't pretty. But I am trying to show you the logic.

Foreach x.

Condition that x > 2 (2 being player has won, but no stars)

We want to add all those up.

Now we want to subtract the finish 1 plus the winning 1 to get total stars

You can see this all clearly using the debugger

Okay found tutorial.

So he stores data as follows

finish level = 1

win = +1

star1 = +1

star2 = +1

star3 = +1

So if a player finishes level and wins and gets 3 stars x = 5

So you want to for each x element

you want to add a condition curent value > 2 [Don't want to count levels without stars]

System add 1 to TotalStars (variable)

Sytem add 1 to NumberStarLevels(variable)

outside loop

System Subtract Totalstars numberstarlevels*2 [because we want to remove the 2 in each]

The above isn't pretty. But I am trying to show you the logic.

Foreach x.

Condition that x > 2 (2 being player has won, but no stars)

We want to add all those up.

Now we want to subtract the finish 1 plus the winning 1 to get total stars

You can see this all clearly using the debugger

**Posts:**1,429**Reputation:**12,738

B

65
S

16
G

9
**Posts:**701**Reputation:**34,754

B

74
S

44
G

48
Foreach creates a loop that goes round and round for each x element it cycles through each line in the array.

Condition allows us to restrict amount of lines/loops to a specific rule

Our rule is x must be greater than 2

Why 2?

Because tutorial says if player attempts level he gets a 1, if he wins the level he gets a 2, if he wins and gets 1 star, he gets 3, wins and 2 stars, he gets 4 and if he wins and gets max stars he gets 5

Its just a number.

We know that 2 of the 5 is not stars so we want to subtract the 2 to get the remainder.

Examples

x = 3 player has 1 star 3-2=1

x = 4 player has 2 stars 4-2=1

x = 5 player has 3 stars 5-2=3

So we loop through each x element that is greater than 2

We add total x number to a total variable

we also add 1 to count number of times it cycles (this is number of x entries that have stars.

No we do the same. Total -2 = stars but I did it a litle different

Total - (numberlevelswithstars*2)

Condition allows us to restrict amount of lines/loops to a specific rule

Our rule is x must be greater than 2

Why 2?

Because tutorial says if player attempts level he gets a 1, if he wins the level he gets a 2, if he wins and gets 1 star, he gets 3, wins and 2 stars, he gets 4 and if he wins and gets max stars he gets 5

Its just a number.

We know that 2 of the 5 is not stars so we want to subtract the 2 to get the remainder.

Examples

x = 3 player has 1 star 3-2=1

x = 4 player has 2 stars 4-2=1

x = 5 player has 3 stars 5-2=3

So we loop through each x element that is greater than 2

We add total x number to a total variable

we also add 1 to count number of times it cycles (this is number of x entries that have stars.

No we do the same. Total -2 = stars but I did it a litle different

Total - (numberlevelswithstars*2)

**Posts:**1,429**Reputation:**12,738

B

65
S

16
G

9
DUTOIT wrote:Foreach creates a loop that goes round and round for each x element it cycles through each line in the array.

Condition allows us to restrict amount of lines/loops to a specific rule

Our rule is x must be greater than 2

Why 2?

Because tutorial says if player attempts level he gets a 1, if he wins the level he gets a 2, if he wins and gets 1 star, he gets 3, wins and 2 stars, he gets 4 and if he wins and gets max stars he gets 5

Its just a number.

We know that 2 of the 5 is not stars so we want to subtract the 2 to get the remainder.

Examples

x = 3 player has 1 star 3-2=1

x = 4 player has 2 stars 4-2=1

x = 5 player has 3 stars 5-2=3

So we loop through each x element that is greater than 2

We add total x number to a total variable

we also add 1 to count number of times it cycles (this is number of x entries that have stars.

No we do the same. Total -2 = stars but I did it a litle different

Total - (numberlevelswithstars*2)

i have try this

but result is below

https://www.dropbox.com/s/ajsvwt1gxmhcd ... m.jpg?dl=0

**Posts:**701**Reputation:**34,754

B

74
S

44
G

48
13 posts
• Page **1** of **2** • **1**, 2

## Who is online |

Users browsing this forum: Computerized God and 9 guests |