onTouch Get onValue of Current Touch Position

I have an XY-Pad in which I'm using some functions on the start in the onTouch property. Currently, if you try the following, just logging the value in the onTouch property will only register the last known previous value.

For example, using the following script in the onTouch property on a new XY-Pad, snap property set to true, touch a random position on the XY Pad, and it will console.log [0,0]. Touch a different random position and it will console.log the previous random touched position.

if (event.type === "start") {
  console.log(value)
}

I imagine that the value isn't being calculated until after the start touch event has been executed. Is it possible to get the updated value during the start touch event? I want to apply some custom functions to the touch events that require the updated value.

Cheers,
DMDComposer

If you don't mind your functions to be called after the value has been updated and sent (if snap is enabled) you can use setTimeout to deffer them:

if (event.type === "start") {

  setTimeout(()=>{
    // executed on next processing cycle
    // use get(this) instead of "value" to retrieve the updated value 
    console.log(get(this))
  })

}
1 Like

Brilliant! That worked perfectly for my needs, thanks, Jean!

Cheers,
DMDComposer