Plugin-wide oncreate function

0 favourites
  • 4 posts
From the Asset Store
Dungeon generation
$4 USD
60% off
Template for dungeon/maze generation, using wave function collapse
  • What is the best way to implement a function just once when the plugin loads, regardless of the number of classes and instances?

    For example,

    I want to load the facebook api just once. However multiple instances will be used to place 'like' boxes..........., so I can't place the init code under the classes or instance oncreate(would load it multiple times)

  • You could just create a function and a var. And when an instance is created check of the var is true. If not then execute the function and set the var to true so the next time an instance is created the function wont be called again. Still requires at least one instance to be created but it will only be triggered once.

    var runonce = false;
    
    function Myfunction(){
     //do something
    }
    
    instanceProto.onCreate = function(){
        if(runonce==false){
             runonce = true;
             Myfunction();
        }
    }
    [/code:8d69cljx]
  • Roflmbo, ohhh my god. Face-palm lol thank you. I was too close to the issue, I was way overthinking it.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • and here i was thinking i completely miss read the question because it seemed to easy.. haha... we all have those moments

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)