0

If it's okay, I'm kind of in need of assistance,

This is an AR filter mini game.

I would like to replace an object's material when the loop count reaches a certain value. I found it extremely challenging to do it with the Patch Editor so I went and explore options with scripting but I really hit a wall with Reactive Javascript. (I'm only an amateur with the conventional javascript and have no idea how to use If-Else statements in Reactive JS).

So I was wondering if there's a way to change an object's material dynamically, controlled by a loop counter? Any help would be greatly appreciated.

Let me know if there are any additional screenshots you need (Or project file, for the matter).

The object does not have a material attached to it.

(The software uses reactive javascript)

*I also shared a similar post in the Facebook group dedicated to Spark AR but I don't seem to get any responses so I figured I'll try my luck here.

If-Else statement Declaration Patch Editor loopCount screenshot

Script Patch types

Levin
  • 65
  • 1
  • 2
  • 10

1 Answers1

1

Someone from the Facebook group responded and told me that a loop is sequential and a callback is reactive and provided the callback function sample code and I slotted my conditional statement in and it worked! Just thought I'll post this answer here.

const Time = require('Time');
const interval = Time.setInterval(function changeMat(){

    if (loopCountNum.pinLastValue() >= 0 && loopCountNum.pinLastValue() <=10)
    {
        car.material = carMaterial;
    }

else if (loopCountNum.pinLastValue() >= 11)
    {

        car.material = carMaterial2;
    }



}, 500);
Levin
  • 65
  • 1
  • 2
  • 10