Extra Life per So Many Points?

For questions about using Classic.

Post » Fri Jan 22, 2010 5:38 am

I'm having some difficulty coming up with a way to create an extra life every 20,000 points.

I'm a little weak in the math department, but I shouldn't have much trouble figuring out how to turn a good algorithm into an expression if somebody would be kind enough to offer one.

Anyway, if anybody knows of a great way to accomplish this, I would greatly appreciate any assistance. Thank you! :)
B
2
G
5
Posts: 14
Reputation: 1,278

Post » Fri Jan 22, 2010 7:00 am

You could use mod function "%" and trigger once while true event.

made an example
[url:29raja1c]http://dl.dropbox.com/u/888303/Caps/score_life.cap[/url:29raja1c]
B
4
S
2
G
4
Posts: 719
Reputation: 2,938

Post » Fri Jan 22, 2010 7:04 am

Hope this helps.
I mis-read your post and gave a life at 2000 exp not 20,000. Just change my 2000 to 20000 in the code

http://www.box.net/shared/5r3090p9yl
B
28
S
8
G
8
Posts: 530
Reputation: 7,154

Post » Fri Jan 22, 2010 10:32 am

+ Points greater or equal to 20000
-> Add 1 to lives
-> Subtract 20000 from points
Scirra Founder
B
359
S
214
G
72
Posts: 22,949
Reputation: 178,544

Post » Fri Jan 22, 2010 11:28 am

[quote="Ashley":34h8367s]+ Points greater or equal to 20000
-> Add 1 to lives
-> Subtract 20000 from points[/quote:34h8367s]
Problem is if he wants to keep his Score then he would need to make two counters.
B
4
S
2
G
4
Posts: 719
Reputation: 2,938

Post » Fri Jan 22, 2010 5:13 pm

No... Just look at my example, it is all in the math

EarnedLives:

int(global('EarnedExp') / 20000)+1
B
28
S
8
G
8
Posts: 530
Reputation: 7,154

Post » Fri Jan 22, 2010 10:01 pm

[quote="Guyon":v7nsbf93]No... Just look at my example, it is all in the math

EarnedLives:

int(global('EarnedExp') / 20000)+1[/quote:v7nsbf93]
That method won't work properly. Since the amount of lives you have is directly tied to the amount of experience(or points) you have, losing lives won't work properly. You'll just gain back any lives you lost the instant that expression is used again. :P

Doppel's method is the best. However, the more conventional way of using modulus in this case would be:

If Score % 20000 = 0
Moderator
B
98
S
37
G
19
Posts: 1,584
Reputation: 17,817

Post » Sat Jan 23, 2010 9:06 am

[quote="linkman2004":398lu01w]
If Score % 20000 = 0[/quote:398lu01w]

What if you are at 19999 points and gain 10 points? It skips over 20000, which means the above condition is only run if you hit exactly 20000, 40000 or 60000 score.

If the score doesn't decrease, I'd suggest something like this:

+ if Score/20000 > var
> Lives = Lives +1
> Var = Var +1

What does this do? Well, it tracks how many times you gained life by scores! When you hit 20000 score for the first time, the above condition is true since var = 0 at the start and Score/20000 = 1 > 0. Once the event is processed, it also increases var by 1, so that it won't run again until you pass the next milestone.

Meanwhile, you can abuse lives all you want!
B
62
S
21
G
12
Posts: 1,910
Reputation: 13,155

Post » Sat Jan 23, 2010 1:55 pm

[quote="linkman2004":96nmtnqn]Doppel's method is the best. However, the more conventional way of using modulus in this case would be:

If Score % 20000 = 0[/quote:96nmtnqn]
Free Bonus life at start of the game? Sweet.
B
4
S
2
G
4
Posts: 719
Reputation: 2,938

Post » Sat Jan 23, 2010 5:34 pm

[quote="Mipey":24w40yj9]What if you are at 19999 points and gain 10 points? It skips over 20000, which means the above condition is only run if you hit exactly 20000, 40000 or 60000 score.[/quote:24w40yj9]
Heh, I had never even considered that. :P
Moderator
B
98
S
37
G
19
Posts: 1,584
Reputation: 17,817

Next

Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 1 guest