Skip to content

Instantly share code, notes, and snippets.

@lassemt
Last active April 20, 2022 22:06
Show Gist options
  • Save lassemt/7b6833cfa2dc0bb0e643c52cb7d6b5a2 to your computer and use it in GitHub Desktop.
Save lassemt/7b6833cfa2dc0bb0e643c52cb7d6b5a2 to your computer and use it in GitHub Desktop.
const Scene = require('Scene');
//
// Old way
//
const obj = Scene.root.find('2dText0');
// Do stuff to the object in global scope
//
// New way
//
Scene.root.findFirst('2dText0').then(obj => {
// Object is ready
// you can update the object signals etc here.
});
const D = require('Diagnostics');
const Patches = require('Patches');
//
// RECVIEVING SIGNALS FROM PATCHES
//
//
// Old way
//
const onTap = Patches.getPulseValue('tap');
onTap.subscribe(evt => {
D.log('tap')
});
//
// New way
//
Patches.outputs.getPulse('tap').then(signal => {
signal.subscribe(evt => {
D.log('tap');
});
});
//
// SENDING SIGNALS TO PATCHES
//
//
// Old way
//
Patches.setStringValue('timeNow', new Date().toString());
//
// New way
//
// Note how the new method returns a promise. Not sure what
// it can be used for though,
Patches.inputs.setString('timeNow', new Date().toString()).then(() => {
D.log('Signal is set?');
});
// So this could be enough for this
Patches.inputs.setString('timeNow', new Date().toString());
@Miuzard
Copy link

Miuzard commented Apr 6, 2020

please help me .. i have problem with my score script ..

score dont wanna show up ???? : (

( This API is deprecated, please upgrade to the newest SDK version. Message: Please use findFirst or findAll instead
@ )
i use this script

const number = Scene.root.find("number");
var score = Patches.getScalarValue("score");
number.text = score.toString();

how to cange to new SDK ..

thank u sir

@farrkhat
Copy link

farrkhat commented Apr 7, 2020

please help me .. i have problem with my score script ..

score dont wanna show up ???? : (

( This API is deprecated, please upgrade to the newest SDK version. Message: Please use findFirst or findAll instead
@ )
i use this script

const number = Scene.root.find("number");
var score = Patches.getScalarValue("score");
number.text = score.toString();

how to cange to new SDK ..

thank u sir

// Put everything that needs to be loaded
// into 1 promise.
Promise.all([
Scene.root.findFirst('directionalLight01'),
Scene.root.findFirst('number'),
Patches.outputs.getScalar('score'),
]).then( (loadedItems) => {
// When everything is loaded
// this function will trigger

// Note how the loacded items are stored in the
// loadedItems and in the orderd the was added
// to the array above. Arrays always starts on 0;
const directionalLight = loadedItems[0];

// Get the loaded items from Scene.root.findFirst('number');
const counterNumber = loadedItems[1];

// And the last added to the list
const scoreNumber = loadedItems[2];

// Do your thing as normal
counterNumber.text = scoreNumber.toString();

});

@Miuzard
Copy link

Miuzard commented Apr 7, 2020

thank u so much bro

@Miuzard
Copy link

Miuzard commented Apr 8, 2020

i wanna ask more about increase speed with script when score more than 10 .. help me bro

@newcolor-studio
Copy link

please help me .. i have problem with my score script ..

score dont wanna show up ???? : (

( This API is deprecated, please upgrade to the newest SDK version. Message: Please use findFirst or findAll instead
@ )
i use this script

const number = Scene.root.find("number");
var score = Patches.getScalarValue("score");
number.text = score.toString();

how to cange to new SDK ..

thank u sir

This worked for me!

const Scene = require('Scene');
const Patches = require('Patches');

Scene.root.findFirst('BlinkCountText').then(BlinkCountText => {
Patches.outputs.getScalar('BlinkCountValue').then(BlinkCountValue => {
BlinkCountText.text = BlinkCountValue.toString();
});
});

Scene.root.findFirst('TimerCountText').then(TimerCountText => {
Patches.outputs.getScalar('TimerCountValue').then(TimerCountValue => {
TimerCountText.text = "10";
TimerCountText.text = TimerCountValue.toString();
});
});

@Demien2020
Copy link

Hi,How can I update the new code of my filter?
Now I've solved it with a tap but I'd like to change the text for each picker again.
I had linked a different dynamic text for each picker of the native ui with code old.
I have problems with canvas and rectangles.
Do you have any feedback?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment