How to insert a function inside a .tick() handler on the fly in aframe?












0















I want to remove a piece of code inside a .tick handler in AFRAME using js.



This is what I have:



AFRAME.registerComponent('foo', {
schema: {},
init: function () {},
update: function () {},
tick: function() {
myObject.position.y += 0.009;//this is what I want to remove on the fly
},
remove: function () {},
pause: function () {},
play: function () {}
});


I expect to trigger the add or removal of that piece of code on the fly using js.










share|improve this question



























    0















    I want to remove a piece of code inside a .tick handler in AFRAME using js.



    This is what I have:



    AFRAME.registerComponent('foo', {
    schema: {},
    init: function () {},
    update: function () {},
    tick: function() {
    myObject.position.y += 0.009;//this is what I want to remove on the fly
    },
    remove: function () {},
    pause: function () {},
    play: function () {}
    });


    I expect to trigger the add or removal of that piece of code on the fly using js.










    share|improve this question

























      0












      0








      0








      I want to remove a piece of code inside a .tick handler in AFRAME using js.



      This is what I have:



      AFRAME.registerComponent('foo', {
      schema: {},
      init: function () {},
      update: function () {},
      tick: function() {
      myObject.position.y += 0.009;//this is what I want to remove on the fly
      },
      remove: function () {},
      pause: function () {},
      play: function () {}
      });


      I expect to trigger the add or removal of that piece of code on the fly using js.










      share|improve this question














      I want to remove a piece of code inside a .tick handler in AFRAME using js.



      This is what I have:



      AFRAME.registerComponent('foo', {
      schema: {},
      init: function () {},
      update: function () {},
      tick: function() {
      myObject.position.y += 0.009;//this is what I want to remove on the fly
      },
      remove: function () {},
      pause: function () {},
      play: function () {}
      });


      I expect to trigger the add or removal of that piece of code on the fly using js.







      aframe






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Dec 29 '18 at 5:41









      XunorusXunorus

      12




      12
























          3 Answers
          3






          active

          oldest

          votes


















          1














          Sorround your logic with an if statement that checks for the appropriate conditions:



          tick: function() {
          if (conditions) {
          myObject.position.y += 0.009;
          }
          }


          You can set those conditions anywhere in your code: component local or global variable, component property...






          share|improve this answer

































            0














            Thanks! I used the conditional like this:



             AFRAME.registerComponent('foo', {
            schema: {},
            init: function () {
            condition = false;
            },
            update: function () {},
            tick: function() {
            if (condition == true) {
            myObject.position.y += 0.009;//this is what I want to remove on the fly
            }
            },
            remove: function () {},
            pause: function () {},
            play: function () {}
            });


            Now I can trigger the state with:



                condition = false;





            share|improve this answer



















            • 2





              Good job! Another idea is adding the condition as part of the schema to avoid the global variable: schema: {enabled: { default: false }} and you can do el.setAttribute(‘foo’, {enabled: false})

              – Diego Marcos
              Dec 29 '18 at 19:04



















            0














            I think you misunderstood the point of schema and updates, but you are really really close with your logic.



            I would add the condition into the schema so that you can use it anywhere within your component as well as use AFrame sugar to update it using setAttribute.



            AFRAME.registerComponent('foo', {
            schema: {
            condition: {type: boolean, default:false}
            },
            init: function () {
            //possible once off initialization logic
            },
            update: function () {},
            tick: function() {
            if (this.data.codition) {
            myObject.position.y += 0.009;//this is what I want to remove on the fly
            }
            },
            remove: function () {},
            pause: function () {},
            play: function () {}
            });


            Then on the fly you simply do



            yourElementWithFooComponent.setAttribute("condition":"true"/"false");






            share|improve this answer























              Your Answer






              StackExchange.ifUsing("editor", function () {
              StackExchange.using("externalEditor", function () {
              StackExchange.using("snippets", function () {
              StackExchange.snippets.init();
              });
              });
              }, "code-snippets");

              StackExchange.ready(function() {
              var channelOptions = {
              tags: "".split(" "),
              id: "1"
              };
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function() {
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled) {
              StackExchange.using("snippets", function() {
              createEditor();
              });
              }
              else {
              createEditor();
              }
              });

              function createEditor() {
              StackExchange.prepareEditor({
              heartbeatType: 'answer',
              autoActivateHeartbeat: false,
              convertImagesToLinks: true,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              bindNavPrevention: true,
              postfix: "",
              imageUploader: {
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              },
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              });


              }
              });














              draft saved

              draft discarded


















              StackExchange.ready(
              function () {
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53967012%2fhow-to-insert-a-function-inside-a-tick-handler-on-the-fly-in-aframe%23new-answer', 'question_page');
              }
              );

              Post as a guest















              Required, but never shown

























              3 Answers
              3






              active

              oldest

              votes








              3 Answers
              3






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              1














              Sorround your logic with an if statement that checks for the appropriate conditions:



              tick: function() {
              if (conditions) {
              myObject.position.y += 0.009;
              }
              }


              You can set those conditions anywhere in your code: component local or global variable, component property...






              share|improve this answer






























                1














                Sorround your logic with an if statement that checks for the appropriate conditions:



                tick: function() {
                if (conditions) {
                myObject.position.y += 0.009;
                }
                }


                You can set those conditions anywhere in your code: component local or global variable, component property...






                share|improve this answer




























                  1












                  1








                  1







                  Sorround your logic with an if statement that checks for the appropriate conditions:



                  tick: function() {
                  if (conditions) {
                  myObject.position.y += 0.009;
                  }
                  }


                  You can set those conditions anywhere in your code: component local or global variable, component property...






                  share|improve this answer















                  Sorround your logic with an if statement that checks for the appropriate conditions:



                  tick: function() {
                  if (conditions) {
                  myObject.position.y += 0.009;
                  }
                  }


                  You can set those conditions anywhere in your code: component local or global variable, component property...







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Dec 29 '18 at 18:01

























                  answered Dec 29 '18 at 11:49









                  Diego MarcosDiego Marcos

                  1,97531013




                  1,97531013

























                      0














                      Thanks! I used the conditional like this:



                       AFRAME.registerComponent('foo', {
                      schema: {},
                      init: function () {
                      condition = false;
                      },
                      update: function () {},
                      tick: function() {
                      if (condition == true) {
                      myObject.position.y += 0.009;//this is what I want to remove on the fly
                      }
                      },
                      remove: function () {},
                      pause: function () {},
                      play: function () {}
                      });


                      Now I can trigger the state with:



                          condition = false;





                      share|improve this answer



















                      • 2





                        Good job! Another idea is adding the condition as part of the schema to avoid the global variable: schema: {enabled: { default: false }} and you can do el.setAttribute(‘foo’, {enabled: false})

                        – Diego Marcos
                        Dec 29 '18 at 19:04
















                      0














                      Thanks! I used the conditional like this:



                       AFRAME.registerComponent('foo', {
                      schema: {},
                      init: function () {
                      condition = false;
                      },
                      update: function () {},
                      tick: function() {
                      if (condition == true) {
                      myObject.position.y += 0.009;//this is what I want to remove on the fly
                      }
                      },
                      remove: function () {},
                      pause: function () {},
                      play: function () {}
                      });


                      Now I can trigger the state with:



                          condition = false;





                      share|improve this answer



















                      • 2





                        Good job! Another idea is adding the condition as part of the schema to avoid the global variable: schema: {enabled: { default: false }} and you can do el.setAttribute(‘foo’, {enabled: false})

                        – Diego Marcos
                        Dec 29 '18 at 19:04














                      0












                      0








                      0







                      Thanks! I used the conditional like this:



                       AFRAME.registerComponent('foo', {
                      schema: {},
                      init: function () {
                      condition = false;
                      },
                      update: function () {},
                      tick: function() {
                      if (condition == true) {
                      myObject.position.y += 0.009;//this is what I want to remove on the fly
                      }
                      },
                      remove: function () {},
                      pause: function () {},
                      play: function () {}
                      });


                      Now I can trigger the state with:



                          condition = false;





                      share|improve this answer













                      Thanks! I used the conditional like this:



                       AFRAME.registerComponent('foo', {
                      schema: {},
                      init: function () {
                      condition = false;
                      },
                      update: function () {},
                      tick: function() {
                      if (condition == true) {
                      myObject.position.y += 0.009;//this is what I want to remove on the fly
                      }
                      },
                      remove: function () {},
                      pause: function () {},
                      play: function () {}
                      });


                      Now I can trigger the state with:



                          condition = false;






                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      answered Dec 29 '18 at 18:28









                      XunorusXunorus

                      12




                      12








                      • 2





                        Good job! Another idea is adding the condition as part of the schema to avoid the global variable: schema: {enabled: { default: false }} and you can do el.setAttribute(‘foo’, {enabled: false})

                        – Diego Marcos
                        Dec 29 '18 at 19:04














                      • 2





                        Good job! Another idea is adding the condition as part of the schema to avoid the global variable: schema: {enabled: { default: false }} and you can do el.setAttribute(‘foo’, {enabled: false})

                        – Diego Marcos
                        Dec 29 '18 at 19:04








                      2




                      2





                      Good job! Another idea is adding the condition as part of the schema to avoid the global variable: schema: {enabled: { default: false }} and you can do el.setAttribute(‘foo’, {enabled: false})

                      – Diego Marcos
                      Dec 29 '18 at 19:04





                      Good job! Another idea is adding the condition as part of the schema to avoid the global variable: schema: {enabled: { default: false }} and you can do el.setAttribute(‘foo’, {enabled: false})

                      – Diego Marcos
                      Dec 29 '18 at 19:04











                      0














                      I think you misunderstood the point of schema and updates, but you are really really close with your logic.



                      I would add the condition into the schema so that you can use it anywhere within your component as well as use AFrame sugar to update it using setAttribute.



                      AFRAME.registerComponent('foo', {
                      schema: {
                      condition: {type: boolean, default:false}
                      },
                      init: function () {
                      //possible once off initialization logic
                      },
                      update: function () {},
                      tick: function() {
                      if (this.data.codition) {
                      myObject.position.y += 0.009;//this is what I want to remove on the fly
                      }
                      },
                      remove: function () {},
                      pause: function () {},
                      play: function () {}
                      });


                      Then on the fly you simply do



                      yourElementWithFooComponent.setAttribute("condition":"true"/"false");






                      share|improve this answer




























                        0














                        I think you misunderstood the point of schema and updates, but you are really really close with your logic.



                        I would add the condition into the schema so that you can use it anywhere within your component as well as use AFrame sugar to update it using setAttribute.



                        AFRAME.registerComponent('foo', {
                        schema: {
                        condition: {type: boolean, default:false}
                        },
                        init: function () {
                        //possible once off initialization logic
                        },
                        update: function () {},
                        tick: function() {
                        if (this.data.codition) {
                        myObject.position.y += 0.009;//this is what I want to remove on the fly
                        }
                        },
                        remove: function () {},
                        pause: function () {},
                        play: function () {}
                        });


                        Then on the fly you simply do



                        yourElementWithFooComponent.setAttribute("condition":"true"/"false");






                        share|improve this answer


























                          0












                          0








                          0







                          I think you misunderstood the point of schema and updates, but you are really really close with your logic.



                          I would add the condition into the schema so that you can use it anywhere within your component as well as use AFrame sugar to update it using setAttribute.



                          AFRAME.registerComponent('foo', {
                          schema: {
                          condition: {type: boolean, default:false}
                          },
                          init: function () {
                          //possible once off initialization logic
                          },
                          update: function () {},
                          tick: function() {
                          if (this.data.codition) {
                          myObject.position.y += 0.009;//this is what I want to remove on the fly
                          }
                          },
                          remove: function () {},
                          pause: function () {},
                          play: function () {}
                          });


                          Then on the fly you simply do



                          yourElementWithFooComponent.setAttribute("condition":"true"/"false");






                          share|improve this answer













                          I think you misunderstood the point of schema and updates, but you are really really close with your logic.



                          I would add the condition into the schema so that you can use it anywhere within your component as well as use AFrame sugar to update it using setAttribute.



                          AFRAME.registerComponent('foo', {
                          schema: {
                          condition: {type: boolean, default:false}
                          },
                          init: function () {
                          //possible once off initialization logic
                          },
                          update: function () {},
                          tick: function() {
                          if (this.data.codition) {
                          myObject.position.y += 0.009;//this is what I want to remove on the fly
                          }
                          },
                          remove: function () {},
                          pause: function () {},
                          play: function () {}
                          });


                          Then on the fly you simply do



                          yourElementWithFooComponent.setAttribute("condition":"true"/"false");







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Dec 30 '18 at 16:33









                          BeyerzBeyerz

                          4881718




                          4881718






























                              draft saved

                              draft discarded




















































                              Thanks for contributing an answer to Stack Overflow!


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid



                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.


                              To learn more, see our tips on writing great answers.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function () {
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53967012%2fhow-to-insert-a-function-inside-a-tick-handler-on-the-fly-in-aframe%23new-answer', 'question_page');
                              }
                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              Popular posts from this blog

                              Mossoró

                              Error while reading .h5 file using the rhdf5 package in R

                              Pushsharp Apns notification error: 'InvalidToken'