- Home /
open door to next level, after 10000 points were added to your score (solved)
ha ha, I will ask in this way, to keep it simple.
How do you write this in code (javascript)?
"open door to next level, after 10000 points were ADDED to you current score."
I don't know, how to check the score, if 10000 points were added.
Think of a pinball-game with several levels. For example, you make 15692 points in the 1st level. Now you enter the 2nd level. The score of the 1st level is retained. Now, you must score another 10000 points for the 3rd level. So here, the minimum score has to be 25692 points for the 3rd level.
Any clever suggestions? :)
this is my (simplified) code so far. It works for the 1st level, but NOT in the 2nd level, the door opens immediately. (I get the current score from another script).
private var levelscore : float;
private var nextlevelscore : float;
function Start(){
nextlevelscore = GameObject.Find("GAME").GetComponent(SCORE).scorePoints;
}
function Update () {
levelscore = GameObject.Find("GAME").GetComponent(SCORE).scorePoints;
if(levelscore >= nextlevelscore + 10000) {
animation.Play("Take 001");
}
}
I save the current score points constantly in another script (SCORE).
PlayerPrefs.SetFloat("Player Score", scorePoints);
Only when the 1st level starts, the score ist set to 00000.
I found my solution. One problem was, that the score was set to 0 in another script, when loading the next level.
Another problem is, that the score is set to 0, when you declare a variable. Even, if you give that variable a certain number afterwards. (so the levelscore is higher than the nextlevelscore (0) for a millisecond, therefore the 'door' opens immediately in the 2nd level.)
private var nextlevelscore : float;
function Start(){ nextlevelscore = GameObject.Find("GAME").GetComponent(SCORE).scorePoints; }
.
.
.
Finally, this works:
private var levelscore : float;
private var nextlevelscore : float = PlayerPrefs.GetFloat("Player Score");
function Update () {
levelscore = GameObject.Find("GAME").GetComponent(SCORE).scorePoints;
if(levelscore >= nextlevelscore + 10000) {
animation.Play("Take 001");
}
}
(An extra script for the 1st level resets everything back to 0.)
Answer by e-bonneville · Aug 22, 2010 at 04:11 PM
Yup. When you enter a level, create a variable that contains the current score. (var originalScore = score
) When your current score equals the original score + 10000 (if score = originalScore + 10000
), open the door to the next level.
Does that work for you?
thx for the answer, but it doesn't work in the 2nd level. The 'door' opens immediately, and not after another 10000 points. I don't understand, why?!
You have to reset originalScore
on entering every level to equal the current score.
Answer by StephenLTGAMES · May 12, 2011 at 02:42 PM
Save the old score (then call it after the level has loaded) Note would help with scripting if i could get own save /load to work.
Your answer
Follow this Question
Related Questions
how to make a level load after hitting a score 1 Answer
Score system Level Load 1 Answer
Score and Level Loading 1 Answer
Cannot retrieve score from previous scene/level 1 Answer
Collision and score 1 Answer