[Question]What does that command means?
-migrated-
[Question]What does that command means? Posted on: 10/03/2010 4:39pm
Quote Post
Hi,

In the source code of the flash game I saw:
Code: [Select]
this.score = this.score - Math.random() * 5;
this.score = this.score < 0 ? (0) : (this.score);
The first line substracts old value of score and Random number from 0 to 4 (am I right?). But what second line does?
Re: [Question]What does that command means? Posted on: 10/03/2010 5:44pm
Quote Post
That's a stupid way to write an if-statement. It means something like this:
If(this.score < 0) this.score = 0;
else this.score = this.score;

It's just making sure you don't get a negative score
Re: [Question]What does that command means? Posted on: 10/03/2010 6:01pm
Quote Post
Ok, thx for your reply. Now I understand this, but what about the first line... Math.random()*5 means a random number from 0 to 4, or from 1 to 5?
Re: [Question]What does that command means? Posted on: 10/03/2010 7:51pm
Quote Post
I don't know the differences between flash and C/C++, but in C/C++ that would generate a random number and multiply it by five. If that actually means mod, it would generate a random number from 0~4
Re: [Question]What does that command means? Posted on: 10/03/2010 8:10pm
Quote Post
Math.random()
Pseudo-random number between 0 and 1 (0 <= n < 1).

Math.random() * i
Pseudo-random number between 0 and i (0 <= n < i).

Math.random() * 5
Pseudo-random number between 0 and 5 (0 <= n < 5).

I assume score is an integer, so it automatically rounds it.
Re: [Question]What does that command means? Posted on: 10/04/2010 7:14pm
Quote Post
Thx now I know what exacly this game does with score. Close the thread (broken image removed).