In short this is an example of what I am trying to do:
function a()
{
this.b = function()
{
alert("hello");
}
}
var c = new a( ) ;
c.b();
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
function-calling.hype.zip (9.4 KB)
MaxZieb
(Loves Hype)
August 24, 2019, 2:15pm
2
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.
MaxZieb
(Loves Hype)
August 24, 2019, 4:30pm
4
If you want to structure your game like that then this might help…
function-calling.hype.zip (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.
MaxZieb
(Loves Hype)
August 24, 2019, 5:15pm
6
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 https://www.phpied.com/3-ways-to-define-a-javascript-class/ , https://www.accelebrate.com/blog/javascript-es6-classes-and-prototype-inheritance-part-1-of-2 or https://www.w3schools.com/js/js_classes.asp are possibilities.
I personally use the the structure defined here with an Immediately Invoked Function Expression https://medium.com/@vvkchandra/essential-javascript-mastering-immediately-invoked-function-expressions-67791338ddc6
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.
MaxZieb
(Loves Hype)
August 24, 2019, 5:21pm
7
But your approach might not have “truly” protected data structures by should do fine.
Whatever works and gets you there!