I am sure this is blindingly obvious but… How does one call a function from a second function?
If ‘nested’ within the current function it is fine - e.g.
functionmain() {
//do something;
functionsub() // call secondary function;
function functionsub() {
//do something else to call above;
}
}
How though does to run functionsub() when it is within a main function run on scene load?
The answer must be similar to the difference in scope between var myvariable (local) and window.myvariable (global), but I can’t find it in the documentation.
In an external script file this would be fine - if using Hype javascript one can only select and type within the containing function… Unless I am missing something absolutely fundamental?
I think you need to be a bit more clear in what you are trying to do.
I do not understand " if using Hype javascript one can only select and type within the containing function "
Post an example project of what you are trying to do, My and @strmiska’s answers are correct ways of calling functions.
Also my assumption was you had your functions inside a Hype Function.
Which in Hype would look like:
// element - DOMHTMLElement that triggered this function being called
// event - event that triggered this function being called
functions untitledFunction(hypeDocument, element, event){
function main() {
//do something;
sub() ;// call secondary function;
};
function sub() {
//do something else to call above;
};
}
// element - DOMHTMLElement that triggered this function being called
// event - event that triggered this function being called
function scenefunction(hypeDocument, element, event){
function functionsub() {
//do something to be called from different clicks on different objects
};
}
2] - triggered on a click on an object so in a separate attached function
// element - DOMHTMLElement that triggered this function being called
// event - event that triggered this function being called
function interactionfunction(hypeDocument, element, event){
//do something and then;
functionsub() ;// call secondary function initialised above;
Thanks for your help and patience guys! [quote=“DBear, post:10, topic:6565”]
window.myFunction = function () { // do something }
[/quote]
was what I needed to know!
I attach a test project demonstrating changing the value of a variable from functions declared on scene load in case it helps anyone else to learn this. testfunction.hype.zip (74.7 KB)