We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy with it.

How to execute self defined functions at any frame?

Home Forums Programming How to execute self defined functions at any frame?

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #34536
    Avatarderekwang0605
    Licensee

    Suppose I define a function
    function changeColor(){
    assignMat([‘GROUP’, mygroupName], myMat);
    setMaterialColor(myMat, ’emissive’, math.random(), 0.5, 0.5, ”);
    }
    How to execute this funtion at frame 10/20/30?

    #34539
    GlifTekGlifTek
    Licensee

    Do you mean frames of an animation or frames of your project’s fps? (24/30/60fps etc)?

    For the latter, you could use the delta puzzle in the time category of the puzzles menu.

    For animation frames there’s the “get animation frame” puzzle
    (Accompanied by a play animation puzzle preceeding it of course)

    You’d want that wrapped in an if logic puzzle, where a variable representing the the current gotten frame equaling the desired frame is met.

    I’m pretty sure that’s how it would work. On mobile now, haven’t tested it.

    • This reply was modified 1 month, 1 week ago by GlifTekGlifTek.
    #34542
    Avatarderekwang0605
    Licensee

    Thank you for the help! It helps a lot! I mean the frames of myproject’s fps. I did not import any animation on the objects. For the latter, I used ‘after 1 seconds do’ puzzle like below as a nested loop:
    registerSetTimeout(1, function() {
    changeVis(‘Cube.001’, true);
    registerSetTimeout(1, function() {
    changeVis(‘Cube’, true);
    });
    });

    But I have a parent group list including 30 subgroups name and I want to settimeout 1 second for each subgroup to show. How to write a loop to implement these nested loops? Otherwise, there will be too many repetitive code lines.

    #34558
    GlifTekGlifTek
    Licensee

    I don’t know if you’re using any puzzles, but You can also use the “time” puzzle do after

    And put “0” frames in the field.
    0 will mean the “next” immediate frame.

    Or put after puzzle 10/20/30 in a loop inside an if statement if needed.
    Or see if the code that is created from all that is able to be used in your code (found in visual_logic.js)

    • This reply was modified 1 month, 1 week ago by GlifTekGlifTek.
    #34560
    Avatarderekwang0605
    Licensee

    Thanks a lot! It worked very well by using the puzzle do after. I followed your way by putting 0, everything worked ok. :good: :good: :good:

    #34562
    GlifTekGlifTek
    Licensee

    Awesome.
    Yeah Yuri mentioned that lil technique awhile back.
    Very good secret
    :good:

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.