Deprecated Script Functions

#1

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

#2

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
#3

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?

#4

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:

1 Like