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