Calling function instance from another function

In short this is an example of what I am trying to do:

function a() 
	this.b = function()

var c = new a( ) ; 

I am trying to store the instance of function in “hypedocument” like this:

hypeDocument.gameLogic = new hypeDocument.functions().gameLogic(hypeDocument, element, event);;

But when I try to get the value of hypeDocument.gameLogic from another function, I get this error:

Error in undefined: TypeError: hypeDocument.gameLogic is undefined

Here is the hype doc (9.4 KB)

Why are you putting gameLogic into a Hype function as constructor? You don’t have no control over the function signature and possible interferences.

How should I create an instance of that function “gameLogic” and use it in another function? I know, I can call it directly, but I just wanted to avoid making it a global function.

If you want to structure your game like that then this might help… (13,6 KB)

1 Like

Hmm. Ok got it.

So, is their any other better way to do the same in hype. Something sort of hype-specific way via it’s UI ? What I am looking for is a separate helper class, whose instance can be used to calculate the result on button click.

As we don’t have a classic build pipeline in Hype. Meaning that modern code is compiled to a lower technology stack. You therefor have to look for your technological lowest denominator and choose how todo make it manually. From, or are possibilities.

I personally use the the structure defined here with an Immediately Invoked Function Expression

It’s how the runtime itself is structured and there are some examples of mine. Look at the recent (and still in progress) HypeAnimationFrame.js for example.

But your approach might not have “truly” protected data structures by should do fine.
Whatever works and gets you there!