Get current scene name and if it's main, prevent trigger?

Hello again. I’m trying out the key bindings that I posted about yesterday and found a solution by using the keybindings on a scene that only loads the first time the page loads. For some reason the keybindings where doubling the value and adding 1 after each click.
If it started at 1 click the next click would be used 3 times, then 7 times etc… this made the page load really slow and after a while of using it I got javascript crash.

Anyway, I’m trying to get the currentSceneName id and if the id = main it should prevent the click from happening.

Any idea on how to turn this code to what I am looking for?

$(document).on('keydown', function (e){ 
	console.log(e.keyCode);
    if (e.keyCode == 40) { //down arrow
    hypeDocument.showSceneNamed('main');
    }
});

maby this is something you´re looking for?

keypress.hype.zip (47.9 KB)

the active scene will be a div with attr ‘aria-hidden=“false”’

do a forumsearch for more info on this …
(though this behaviour may be broken on further releases of hype)

i have to get faster … :stuck_out_tongue:

1 Like

The problem is that it will still trigger the scenes even if you’re on it.
Look at this and you will see what I mean, this is why I need it to be disabled if you are on the main scene, in this case scene “1”.

keypress2.hype.zip (54.5 KB)

create a new function and load “onLoadScene”.
then let the action-line empty.

 document.onkeydown = checkKey;

 function checkKey(e) {

 e = e || window.event;

if (e.keyCode == '39') {
// right arrow
//no action
 }
  else if (e.keyCode == '37') {
 // left arrow
    //no action
 }
 }

I’m not at my Mac at the mo. But another approach is to have a global variable the is a BOOL.

in the scene loaded function

I.e. window.mainLoad = true;

Use this in an if clause .

If (!window.mainLoad) {

// do stuff

}

You can then reset it from any other function

window.mainLoad = false;

Example. ( And I know I may be missing what you are trying to do)

simpleBlocker.hype.zip (16.3 KB)

Thank you @MarkHunte & @strmiska for taking your time! I did what @strmiska told me to do and it worked. It might not be the best thing to do since you have a javascript on all the scenes but it works as intended. Thanks!

1 Like

No worries. I’ll post this updated one since I just wrote it any way…

simpleBlocker.hype.zip (17.8 KB)

1 Like