LOCK / UNLOCK - user interaction while CPU is busy ?

0 favourites
From the Asset Store
Unlock Levels, Worlds & skin plus add coins by watching ads
  • Hi All,

    Since I don't want to have extra issues when I'll test my project on other machines, I've decided to try make some kind of Lock/Unlock some buttons whenever the CPU is busy for Saving/Loading Project file and Exporting/Importing Image file.

    I just got started with a very simplistic logic by creating a Global Boolean called: "is_CPU_Busy"

    Before I'll add the actual buttons/menus I want to lock, I made a simple 9-patch PANEL with TEXT (Pinned to the Panel) so it will be a visual way to check beside the Console (F12).

    The Panel TEXT is out of the Layout by default, and when "is_CPU_Busy" = True it changes position to a specific place:

    I actually made the LOADING part works in a way, it's not perfect yet (need to add "on cancel" etc..)

    But I'm having issues with the SAVE part... it won't show the PANEL with the Text, I tried to follow what I did in the LOADING but I can't get it to work correct.

    I tried some different approaches, I get to show it but then the panel stay on the screen (on save complete) instead of go back to it's position based on the "is_CPU_Busy" Bool, just like it works when I click "LOAD" that's where I got confused.

    Console (F12) didn't show anything strange so I'm on a trial and errors now, and I make things more complicated than they should instead of making it clean and efficient.

    .

    Note: the screenshots are NOT my current latest version, I'm still playing with the code as you read this post BUT! you can see the rough idea of what I got started (a total mess) but it's just so you can have a look and give me a hint how to make it work more efficient if possible, Any help is appreciated, thanks ahead! :)

  • Add browser-log messages to all events where you reset CPU_is_busy flag to false. Maybe one of them is fired after you hit the save button.

    Also, why don't you use functions? Events like 224 and 225 running on every tick are not only bad for performance, but also making it difficult to troubleshoot. Create two functions "LockUI" and "UnlockUI" and call them when needed.

  • Thanks for the help sensei dop2000!

    Before I'll do the Console Log check as you suggested I want to convert the current code to Functions as you suggested first, it's still a mess.

    I'm still confused what kind of events runs on "Every Frame" if I didn't use "EVERY FRAME" that's why I thought it's "Only Trigger Once" by default and didn't even think about functions BTW.

    I didn't understand something, I hope that you can help me get the idea right:

    The reason I used Boolean: "CPU_is_Busy" is because like in Line 235 (WIP) for example, I don't know how to do the same "IDEA" with functions?

    Which I want to check if the UI can even be used or not.. I was thinking about checking Activate/Deactivate Groups instead but maybe there are better, cleaner options?

    Do I even NEED "CPU_is_Busy" anymore if the functions basically do the same check but as you explained, not every frame and more efficient = GREAT!

    As you can see... I'm confused about the all thing, but I'm still messing with it...

  • Here is my first basic attempt with the functions instead of the Boolean:

    If disable the Call Func_UnlockUI on Line 229:

    I get a signal on the Console (F12) By pressing the SAVE button but not when I CANCEL from the Save Dialog:

    If Enable the Call Func_UnlockUI on Line 229:

    I get automatic signal for SAVE button and immediately for the CANCEL (while the Save Dialog is open, I didn't press Cancel yet) even if I press Cancel it won't give me a signal on the console.

    I'm missing something related to the SAVE / CANCEL but I can't see what...

    How do I even make something simple such as "CANCEL" the Save Dialog to work for sake of testing?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Any top-level events which are not triggered (don't have a small green arrow on the left) are running on every tick.

    Even with functions you still need to use that CPU_is_busy boolean flag. Set it to true inside the "LockUI" function. Set it to false inside the "UnlockUI" function. Check for this flag in different events. Add browser-log messages to events where you call "UnlockUI", to see which event has unlocked the UI.

    I can't answer your questions about event 236 because it's not on your screenshots.

    .

    Deactivating event groups when UI is locked is a good idea. For example, you can have a group with all keyboard shortcuts. Instead of adding boolean check to each event, simply deactivate the entire group.

    To easily block all mouse activity I used this trick - place a huge TextBox with transparent background covering everything on the screen. It will intercept and block all mouse clicks, wheel events etc. In "UnlockUI" function destroy this TextBox.

  • Thanks for the explanation and guides, I will try to follow your instructions.

    Sorry about the wrong line number, my bad... I meant Line 229 the part I marked on the screenshot which supposed to show print it to me on the Console(F12) once SAVE Dialog Canceled (same code WORKS for Load Dialog Cancel) but NOT for SAVE Dialog Cancel. Please have a look on the post with that screenshot maybe you'll get my mistake why it's NOT working on SAVE Dialog Cancel?

    .

    Now that the Boolean CPU_is_Busy are inside both functions (true / false)

    What about the CPU_is_Busy events themselves? the position that was in there moved to the Function, so what do I need to put in there? I'm not sure I understood why I need them, because checking CPU_is_Busy = Same as Call Function at the moment? (unless I'll put there something of course)

    it's a huge loop in my head that I don't understand exactly, please explain or give an example with Func_LockUI + CPU_is_Buys why I need both if you can?

    I guess ONLY for checking flags as you said but to PUT NOTHING inside lines 227 and 228 I can actually remove these two?

    I'm asking because I'm not sure.

    .

    Blocking the keyboard may be tricky for me since I will need to reorganize some groups but, yes it will be much easier to Activate / Deactivate instead of messing around. :)

    About the Mouse lock, I was thinking about making a dedicated Layer (or just a huge QuickBackground Stretched all over the place) as you suggested but I never done that before so I didn't know if I can use such thing to actually BLOCK anything with the mouse, it seems the most simple and effective solution. I should give that a try... As soon as I get the CONSOLE (F12) show me that most basic actions actually works.

    Thanks ahead for any help! :)

  • "On saved dialog cancelled" may be triggered after "NWJS Show Save dialog" action. You are using "Browser invoke download" to save files, that's why it's not triggered.

    Boolean flag is needed for checks in your various events.

    If you add any opaque layer or background above everything in your project, it will not block mouse clicks, they will still go through to objects underneath. You need to use TextBox (or another Form Control object), only they block mouse events.

  • "On saved dialog cancelled" may be triggered after "NWJS Show Save dialog" action. You are using "Browser invoke download" to save files, that's why it's not triggered.

    That's why I got confused... broswer/NWJS, can I use ONLY NWJS instead of browser so I'll have the same "way" talking with these events.

    I didn't touch these because of all the binary or Json data and rest of the code that you helped me with earlier since it works... I was afraid to ruin it by "guessing" things, is it possible at all to NOT use Browser for save/download the files? but only NWJS? If so... how exactly? or if not what is the solution?

    Boolean flag is needed for checks in your various events.

    OK, I wasn't sure I understood thanks!

    If you add any opaque layer or background above everything in your project, it will not block mouse clicks, they will still go through to objects underneath. You need to use TextBox (or another Form Control object), only they block mouse events.

    OH... I didn't know that! it should be easier than using Sprite or QuickBackground and put "While Mouse cursor is NOT over X" for all the events one by one... I must give it a try once I'll fix the current issue.

  • You don't really need to continue blocking UI when saving files. There will be a modal "Save as" dialog open, which will prevent users from doing anything else. So I think you can remove event 229, and in event 234 remove "wait for previous event to complete"

    .

    You can use NWJS actions and events to save files, if you want more control. You can find answers to your questions in the official documentation :)

    .

    Also, by TextBox I meant Text Input object.

  • You don't really need to continue blocking UI when saving files. There will be a modal "Save as" dialog open, which will prevent users from doing anything else.

    Even before I get to the all Blocking code, I want to solve the original issue the PANEL with the text that shows "LOADING PROJECT FILE" while the Load Dialog Box is working, while the "SAVING PROJECT FILE" is not working, because it works with the Invoke download if I understood you, but how do I still make the panel to work like it does with the LOAD?

    This is to CHECK if it works, also the Save/Load Dialog is not always covering all the screen like in the screenshot, it's up to what the user size and position used last so I want it to be on the background with all other messages that I will use on this panel later on.

    The question is: how can I make the "SAVING PROJECT FILE" Panel with Text to appear while the Save Dialog Open?

    So I think you can remove event 229, and in event 234 remove "wait for previous event to complete"

    .

    Also, by TextBox I meant Text Input object.

    Thanks I can't wait to try it after I'll solve the Save issue! :)

    Here is the current code version if it helps you follow my mess:

    What I'm trying to do first is to solve this PANEL + TEXT to appear on it's position (using the Functions) and SET it's text to the current states that I need because I will have more.

    That's why I don't want to proceed to the actual Blocking yet.

  • If you want to continue showing "SAVING PROJECT FILE" message while the "Save as" dialog is on the screen, you have no other option but to switch from using "Browser invoke download" to "NWJS Show Save Dialog", and then "NWJS Write text file".

    You can find how to use it in the official documentation, or search the forum for tutorials, examples. It's not difficult.

    But I would just forget about it, and leave it as it is - invoke download and immediately unlock the UI in the same event.

    .

    By the way, you should send the message to be shown in Text_Panel_CPU_Is_Busy in function parameter, and set text inside the function.

  • If you want to continue showing "SAVING PROJECT FILE" message while the "Save as" dialog is on the screen, you have no other option but to switch from using "Browser invoke download" to "NWJS Show Save Dialog", and then "NWJS Write text file".

    You can find how to use it in the official documentation, or search the forum for tutorials, examples. It's not difficult.

    I'll dig into that because I think it will be better that most of my code will work around NWJS when possible anyway, I hope I can get it to work. :)

    But I would just forget about it, and leave it as it is - invoke download and immediately unlock the UI in the same event.

    It will look weird to have some messages appears, but when saving... nothing, also it helps me do early checks more visually, but if I won't be able to code that... I may have to skip the all panel idea which is a shame.

    By the way, you should send the message to be shown in Text_Panel_CPU_Is_Busy in function parameter, and set text inside the function.

    OH! I never used Functions Parameters before, it sounds like an efficient way using parameters for every SET TEXT! I gotta give it a try, Thanks! :)

  • Sensei dop2000 I got some progress:

    If press SAVE button, the PANEL + TEXT "SAVING PROJECT FILE" appears and if I Cancel from the SAVE Dialog, I get the panel to get back to it's hidden position, so the functions are working! :)

    But the problem is that now the ACTUAL saving file to .alon as it was with the Browser using Invoke Download not saving the data, I tried to understand using the manuals unfortunately I still can't understand many things about how to use it right it's not simple as I thought based on what I saw on the Loading group which I tried somehow to follow.

    .

    As for the UNFINISHED current code, I can save a file, but it will be an empty file, obviously it's not actually saving the data since I don't know how to complete the code in this area.

    I'm trying to convert the saving via Browser object to NWJS, just like it's already loading from NWJS fine including the Panel + Text.

    Can you have a look on the SAVE group, and tell me how can I make the save work?

    Thanks ahead for any help!

  • Did you really read the documentation? Because it explains everything.

    The result of Save dialog is the file name only, which will be in ChosenPath expression. Then you need to write to this file.

  • Yes I did, where is that explanation or examples of how it's done exactly?

    All I see is just a brief information, there is nothing there that can explain to ME (non-programmer) how do I save my unique file extension as file?

    This is why I'm using the forums MUCH more informative and helpful than the documents which are using lots of terms for programmers with lack of examples for non-programmers.

    The Dialog windows are working fine as you saw on my example, it's not the issue because it works great with the functions you helped me with:

    For example: How do I SAVE my specific file .ALON using the NWJS?

    there is no example or tutorial about such thing using C3 there is only something about TEXT which isn't helping me in any way since I need to save data using my unique file extension.

    I wish the documents had more tutorials or at least base examples for non-programmers... so I could learn and actually understand from there as well.

    The result of Save dialog is the file name only, which will be in ChosenPath expression. Then you need to write to this file.

    I must say that I always appreciate your help, I learn a lot from you and other good people at the forums but I wish I knew how to do half of what you just explained...

    Since I don't know where to begin or how it's done exactly I can only guess that "something.ChosenPath" after something in one of the actions I need to do but I have no idea what or how

    I'm looking on the older save code and keep guessing but not sure if I'll "HIT" right how it's done... these things are not so simple to learn, trying to connect the pieces together, not so simple but I'm trying as I go. :)

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