Store Matrix event.type into a variable object

Hi guys, happy new year and best wishes for 2023!

I am trying to store event.type into a variable object, because I am trying to know if a child object is touched to block an incoming OSC input, to get the touch state I am using this:

image

I've tried then @{myVariable} = p.onTouch but that doesn't seem to work, any idea?
Thanks in advance!

Hi,

I'm a little confused on what you want, could be my lack of coffee :coffee: haha. However, would just using set(id) on the variable work for your case?

let p = {}
p.onTouch = event.type
set("IdForVariable", p.onTouch)
// or you could save the whole object
// set("IdForVariable", p)

Then calling the @{myVariable} from another widget would show the updated value of the onTouch state.

If you needed to update the variable instead of overriding it, you could use get(id) to get the current object from the variable, than update it manually with Javascript.

Does this help, or am I misunderstanding how you're using this?

Cheers,
DMDComposer

1 Like

Hi mate, thanks for replying!

No problem, maybe I've not explained this well enough!

I've tried also with set() but then I have an error in console, and the script stops working. Also I may be wrong, but I've read Emmanuel's post not recommending using set() on properties, could be?

Basically I need a variable widget (lets say touchState) what let me know if I am touching the matrix object or not. So I can use this on another script and do something like this.

let state = get(touchState)
if (touchState == start) {
 // do something
}

Hopefully this is clear now, thanks in advance!

I think figured this out, not sure if the more elegant way, but in the matrix properties, just doing this seems to work

I was not using the ``quotes, doing that allows you to use the script commands like set(), get(), inside of the JS block. Basically like using a script field if I got this correctly.

JS{{
  
let p = {}
  p.onTouch = `if (event.type == "start") { set("touchState", 1) } else { set("touchState", 0) }`
return p
}}

Cheers

1 Like