Patch Values to Script Fails

Dear Creators. First of all, I’m a beginner and I do really enjoy all the tutorials. But in the effort to start on the scripting, I always struggle. I’m currently following Maru Studios tutorial on 2D Game .

Based on the tutorial, I’ve made one change that is to link the score count into my face tracker (world space) instead of leaving it in the camera space.

However when I implement the script, though on VS it didn’t show any error, in the console however it shows this:


What does this mean? and how can I overcome this? I’ve tried following many scripting tutorials on YT but failed miserably. I appreciate any help that I can follow as I love how scripting works.

This is my current Scene:

This is the Counter value that I needed to be shown in the game. As you can see, the Value successfully shown in the patch when everytime my character jumps over a collider. But I couldn’t translate this into the script:

This is the script that I used:

const Scene = require('Scene');

export const Diagnostics = require('Diagnostics');

const Patches = require("Patches");




function onReady(assets) {

      var counterNumber = assets[0];

        var scoreNumber = Patches.outputs.getScalar("score");







I don’t see anything that jumps out as incorrect. It might help you narrow down the offending line by adding some debug statements like this:

const {log} = require('Diagnostics')

It’s possible that it’s a bug in Spark, so you could try deleting the text object and recreating it. Maybe call it something other than “number” since that’s a reserved word in JS. Sometimes it can make strange things happen.

Another thing to try would be to break out the segments of code and test each one individually. Will the text object allow you to set text manually?

counterNumber.text = 'test'

It didn’t work at first… So, after a day’s clearing my head and sat down with a clear conscience, suddenly I stumbled on this patch Oh my goodness it worked!.. I mean not with script but with another patch!

It worked perfectly. Now, I just need to insert sound and I’ll be laughing all the way.

I thank you for your suggestion, Josh. And since this road block makes me understand more on the scripting part! I’m excited to experiment scripting more now that I know how it actually works (not in my case) but I truly gain something from learning scripting mistakes and how to make sense of how patches and script connects! (^_^) So happy!

1 Like