Calculations over several scenes


#1

Hello, I want to do a score which goes over several scenes i tried it with these java scripts but it did not work these numbers should also be variables. For example i tried that one:
Javascript: Space.setProperty(‘Time’,‘10’)
Javascript: Time = Space.getProperty(‘Time’)

If you want to take a closer look here is the share link:
https://cospac.es/edu/4IyH


#2

Hi @DanielH

your script works! However, in your “PlayerLives” Blockly tab in Scene 1 you run a while loop without pausing in-between the steps. This means that when you start Scene1 you switch to Scene 2 very quickly and before the property could be saved in the space.

Try adding a pause block as shown below in your “PlayerLives” coding tab in Scene 1.
image

Hope this helps!


#3

If I want to set the variable to a random number what do I have to do, so a number which we know when the scene is changing first? Do I have to call the number “X” then ?


#4

Hello,
I have not received an answer yet. I would like a score in which the variable, for example, “Time” itself varies a value depending on the playful power, so it can be e.g. between 1-120 or something like that. How do I get to this if I want to use the javascripts via this comment? Because I have the value in the javascript as “var” so variable used but in the next scene I get the value “NaN” So Not a Number.How do I get this error anymore.


#5

Hi @DanielH,

can you share a link to your space with us? You can do so by pressing the “Share” button in the toolbar, then copy-pasting it here.


#6

Hi @Stefan ,
Here is the link https://cospac.es/iIud
remember the value of the variable should be depending on the playful power this is just a version where I am trying to make the score


#7

Hi @DanielH,

in your Space.setProperty method you set the property “Time” to the string “Final Time”. Remember that the first parameter of the method is the property-name, while the second is the value you are assigning to it. In your code, you’re doing it the other way around.

To make sure that you’re not mistaking variable names for strings, you can also write your “Time” and “Lives” variables in lowercase as “time” and “lives”.

Below is the correct version of your script. Notice how I re-named the variable names to be lowercase, and don’t use the ’ ’ - symbols around the variable.

Click to see solution

Scene1:
30

Scene 2:
In this scene, make sure you assign a value to “lives” and “time” before giving it another value by script.
42