Deprecated Script Functions

Hi!

I have have written some JavaScript code in a script tab, and noticed some of the functions are crossed out and say ‘deprecated’ when I hover over them. For example, these functions are deprecated, among others:
Scene.loadSound()
item.setOpacity()

These are listed in the API linked to from the Script tab (by pressing the i in a circle). Is there a more updated API I should be using?

Current space: https://cospac.es/IKtp

Hi @lpancoast!

The API on the site is indeed a little outdated. Here some changes relevant for your space.

We moved all sound related methods to Sound namespace:

Sound.load(id, callback)

Also, schedule and other time related methods are under Time namespace now.

Time.scheduleRepeating(callback)

Some get* / set* methods were replaced with properties. For example items now have an opacity and color properties:

// This is how you can set an opacity 
item.opacity = 0.5
// This is how you can get an opacity
let opacity = item.opacity

For color we also introduced a dedicated class Color:

cube.color = new Color(255, 0, 0);
let color = cube.color

Hope this helps!

2 Likes

This is great!

What is the new way to do Space.showSceneNavigation(false); ?

Is there an updated API somewhere, or is it still a WIP?

Hi @lpancoast,

To hide the space navigation you can use the following code snippet

GUI.HUD.sceneNavigationVisible = false;

Hope that helps! The API linked in the API website is quite old, we’re looking into updating it in the future :slight_smile:

2 Likes

Is there an updated API somewhere? I am running into a ton of issues with deprecated JS functions and can’t seem to find documentation on all of them.

1 Like

totally agree…I am trying to learn the scripting but most of the examples are depreciated and there is insufficient information to guess the new syntaxes

Please either write an updater program or provide a style guide for converting old to new
this already exists for other languages like python 2->3 convertors

?also a list of internals?

In the CoSpaces code editor click the i icon, that is located on the right. It will bring you to the API documentation.

Have you tried checking it already? Is there anything particular that you can’t find there?

thanks this helped! - I was able to fix the drag cube-dog example…i will post on the relevent forum posting

@Pavel it is good to see an updated API. Thank you!

Is it possible to add examples throughout the API. As it currently reads it is hard for students (or teachers) to understand how to use the syntax. I had high school students in their third or fourth year of CS, who are used to learning from documentation, try it today and many were lost. For example, it took me a lot of playing around with the moveTo function before I realized that I have to pass in a Vector3 created using the constructor and not just the x,y,z parameters. An example would make this clearer.

Something along the lines of Mozilla’s JavaScript documentation would be useful.

Hi @ianostrom,

Thanks for your feedback! We’ll look into providing more elaborative examples to functions like .moveTo in the future :slight_smile: