Patch to Script values

Any idea how can I get a value in the patch editor to display as text in the scene? In my case I want a countdown timer.

I’m really struggling with this since V85 updates. I’ve followed many tutorials but nothing seems to work. No matter what I do, I get ‘possible unhandled promise rejection’. The only possible work around is to remove the 2D text and add 3D text. But cannot see any reason why it only works with 3D text.

Here’s my current code (only works with 3D text).



  const scoretext = results[0];

  Patches.outputs.getScalar('scoreCount').then(e=> {
    e.monitor().subscribe(value=> {
      scoretext.text = value.newValue.toString();

Looking a bit into it it appears there’s a bug on windows machines regarding 2d text atm. Are you on a Windows? Might be worth checking this same setup on a mac (if you send me the project file I can quickly see if I get the same error log in my console)

1 Like

Promises have another function called catch. You can use that to log out the error message/s on your Promises.

Promise.all([...]).then(...).catch(error => console.log(error))

Then you will know what the actual problem is


Thanks. @Boris Yes I am on Windows 10. I did see a few mentions that there might be a bug with 2D Text. @josh_beckwith I did have a quick go with catch, but had a few issues with it. But I didn’t persevere with it.

However, after a LOT of experimentation and many techniques I got it working. This is on v99, but that doesn’t seem to have made and difference.

The issue appears to be the ability to find 2D Text. So to get around that, I added From Script and patched that into the 2DText.

Here’s the set up:

On the Script:
From Script called textIn, set as text. Drag the script into the patch editor and plug it into your 2D Text.

To Script called valueOut set as number. Send this to the patch editor and add whatever you need to it.

Here’s’ the code:

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

(async function getvalue(){
    const value = await Patches.outputs.getScalar('valueOut');   
    Patches.inputs.setString('textIn', value.toString());

haha nice! at least one good thing about spark despite the plethora of bugs, it allows to do the same thing in many different ways ^^

1 Like

cool you have your answer, for quick reference on patches to code I always have this web in mind:

(all kudos to them)

@MartinBerisso yeah that was one of the many sites and YT channels I looked at and tried. Unfortunately their techniques still did not work for me. A bit of code bashing, logic and trial and error got me there in the end!