1. Hey! Guest! The 34th GMC Jam will take place between August 22nd, 12:00 UTC (Thursday noon) and August 26th, 12:00 UTC (Monday noon). Why not join in! Click here to find out more!
    Dismiss Notice

Discussion will gamemaker 2 support yield and wait for the new functions and possibly events?

Discussion in 'GameMaker Studio 2 Community Tech Support' started by Shadowblitz16, Jul 5, 2019.

  1. Shadowblitz16

    Shadowblitz16 Member

    Joined:
    Jun 23, 2016
    Posts:
    594
    will gamemaker 2 support yield an wait keywords this year?
    I think it would make a good addition to functions and might also be useful if you could use them in events as well

    Code:
    var x = 0
    yield (x++ >= 4);
    wait(4);
    //Do something
    
    this is just example code so I'm not sure if its correct but you should get the idea
    basically this would be a alternative to alarms but for functions and events
     
    Last edited: Jul 5, 2019
  2. EvanSki

    EvanSki King of Raccoons

    Joined:
    Apr 17, 2018
    Posts:
    537
    A wait function would be very useful seeing you cant call alarm events in scripts
     
  3. Shadowblitz16

    Shadowblitz16 Member

    Joined:
    Jun 23, 2016
    Posts:
    594
    I would prefer it to be a keyword that works similar to yield but accepts time in frames
    I don't think yield works outside it's scope in other languages so trying to create a wait function wouldn't work
     
  4. Nocturne

    Nocturne Friendly Tyrant Forum Staff Admin

    Joined:
    Apr 13, 2016
    Posts:
    6,777
    There are no plans for this in the future, but that doesn't mean you can't file it with the helpdesk as a feature request. :)
     
  5. TsukaYuriko

    TsukaYuriko Q&A Spawn Camper Forum Staff Moderator

    Joined:
    Apr 21, 2016
    Posts:
    1,538
    You totally can, as long as you call them from an instance scope (e.g. with <instance> script();).
     
  6. EvanSki

    EvanSki King of Raccoons

    Joined:
    Apr 17, 2018
    Posts:
    537
    Unless its JSdoc that requires a pause
     
  7. Shadowblitz16

    Shadowblitz16 Member

    Joined:
    Jun 23, 2016
    Posts:
    594
    @Nocturne
    help desk?
    never heard of it.
    is this the same as the file bug report in the ide?
     
  8. TsukaYuriko

    TsukaYuriko Q&A Spawn Camper Forum Staff Moderator

    Joined:
    Apr 21, 2016
    Posts:
    1,538
    You can find the feature request form on the contact page - it's one of the dropdown options - so yes, same link as the bug report form.
     
  9. Shadowblitz16

    Shadowblitz16 Member

    Joined:
    Jun 23, 2016
    Posts:
    594
    @TsukaYuriko thankyou so much.
    EDIT: sent it :D
    hopefully the yoyo games devs see it and like it.
     
    Last edited: Jul 6, 2019
  10. rIKmAN

    rIKmAN Member

    Joined:
    Sep 6, 2016
    Posts:
    4,336
    I don't understand what you mean?
    Why would you need a pause in the JSDoc declaration?
     
  11. EvanSki

    EvanSki King of Raccoons

    Joined:
    Apr 17, 2018
    Posts:
    537
    for timings and other things that require a pause
     
  12. FrostyCat

    FrostyCat Member

    Joined:
    Jun 26, 2016
    Posts:
    4,327
    YoYo should not bow to suggestions that arise from ignorance of basic techniques, in this case asynchronous handling of sequential actions.

    This suggestion is only ever meaningful for people who over-complicate their code by never delegating between events and components. It's an emotional outburst from novice users when they run into walls with poor code architecture, in particular the kind dictated by the cult of "everything-in-one-place". Anyone who is past that stage and does delegate can see a variety of existing alternatives in GM, some even designed explicitly for the purpose:
    • Timelines
    • Worker objects
    • Asynchronous events
    • Manual/built-in alarms
    • Scripted solutions such as TMC Script Batch
    And with the upcoming introduction of chained accessors and lambdas, promise-like mechanisms such as the kind in modern Javascript will also become a viable alternative, with generality surpassing all of the above options yet also permitting the delayed actions to be specified in the same piece of code.

    The suggestion also fails to think of contradictions with existing syntax and functionality. Consider the following:
    Code:
    ///@func foo()
    wait(4);
    return "FOO";
    
    Code:
    ///@desc Draw event
    for (var i = 0; i < 10, i++) {
      draw_text(x, y, foo());
    }
    
    If it returns "FOO" right away, then the wait didn't happen, thus violating the suggestion's premise. If the wait does happen, a run of the Draw event code will be delayed past schedule, likely to a point where it becomes inconsistent with the engine's internal state. There's no way for conflicts like this to be resolved in a way that is consistent with clear-cut, reliable execution.

    Compared to learning how to do asynchronous sequential actions properly with existing and well-defined techniques, introducing loosey-goosey, self-contradictory syntax to GM is a far worse alternative.
     
    Hyomoto, chamaeleon and IndianaBones like this.
  13. rIKmAN

    rIKmAN Member

    Joined:
    Sep 6, 2016
    Posts:
    4,336
    What have JSDoc declarations got to do with timing and pauses in code execution?

    Also, "loosey-goosey" - not heard that for years haha!
     
  14. Hyomoto

    Hyomoto Member

    Joined:
    Jul 7, 2016
    Posts:
    1,060
    I can't say anything Frosty Cat hasn't already said better, but I support his conclusion. However, it's already possible to do this. The wait as described is nothing more a program execution pause, a purposeful code hang. You essentially "lag" execution. If you wanted to wait in this way, you could write a function that is nothing more than a loop that continues until some time passes.
    Code:
    @func wait( time );
    var _wait = delta_time + argument0;
    while ( delta_time < _wait ) { continue }
    
    We simply get our current time, add the amount we want to wait to it, and then freeze execution with a while loop until that time passes. At that point the loop ends, and the program execution continues. The reason I assume GML doesn't include this as a built-in function, as opposed to trigonometry for is example, is because hanging program execution is not a good habit to get into.
     
    Last edited: Jul 8, 2019
  15. Tthecreator

    Tthecreator Your Creator!

    Joined:
    Jun 20, 2016
    Posts:
    741
    Just as a clarification, this is like a proof of concept function. Please don't actually use this. A decent sleep function tells the OS not to execute the program's/thread's instructions for X amount of time. This one just lags the CPU sucking up resources.

    If you need a timeout in your code, it's probably not very good code. (Except perhaps if it is something async)
     
  16. Samuel Venable

    Samuel Venable Time Killer

    Joined:
    Sep 13, 2016
    Posts:
    1,222
    Well, a similar thing is done as a common practice in VBScript, so it can't be all bad. Sometimes, like when using Microsoft Script Control, or the IActiveScript Interface, you don't have access to the normal WScript.Sleep method, so you have no choice but to use a delta time while loop. Have you actually tested this and verified it eats up resources? Or did you just read that somewhere?
     
  17. chamaeleon

    chamaeleon Member

    Joined:
    Jun 21, 2016
    Posts:
    931
    I'm anxiously awaiting a good example of a use case for a wait/pause function that halts the execution of everything, every step, every draw event, until the required time has elapsed. Right now that would be equivalent to having disabled every object except a controller object that only checks for elapsed time in a step event or until an alarm goes off, at which point all objects are enabled again. What is the use case for this? Given no other side functionality.
     
  18. Tthecreator

    Tthecreator Your Creator!

    Joined:
    Jun 20, 2016
    Posts:
    741
    @Samuel Venable I know from C/C++/C# experience.
    If I run the following C program on my computer:
    Code:
    int main(int argc, char** args){
    [INDENT] while(true){
    [INDENT]//do nothing[/INDENT]
    }[/INDENT]
    }
    
    I can see that the program uses about 4,0% CPU. If I look at per core utilization I can see one of my cores being 100%.
    upload_2019-7-8_23-27-46.png (I couldn't get a better screenshot since the program keeps jumping from core to core)
    It actually kind of differs per programming language. Lower level languages have more problems with this than higher end ones. This is why I can't say for certain how GameMaker will deal with this. I'd have to test that. I'll do that in a moment.


    EDIT:
    Jup, a while(true){} loop in gm does indeed result into high resource usage
    upload_2019-7-8_23-41-26.png
     
    Last edited: Jul 8, 2019
    Samuel Venable likes this.
  19. Samuel Venable

    Samuel Venable Time Killer

    Joined:
    Sep 13, 2016
    Posts:
    1,222
    Yeah, VBScript is scripting language as the name suggests, therefore it's not exactly the same category of thing as raw C++, and that's why I was curious how GM would react to it, in which direction would it lean to...

    However, I've seen while (true) used many times in software, most notably game engines. That's what a main game loop is. It executes every step without fail, at least until it either crashes or a break is called, like in most cases it would on the close button and/or escape key for the latter.
     
  20. GMWolf

    GMWolf aka fel666

    Joined:
    Jun 21, 2016
    Posts:
    3,363
    And anyone who has written a script (not like a GML a script, but like, a script script, where you have instructions, timings, and under interactions, like in a dialogue system for example) knows the value of coroutines!
    They are invaluable.
    Sure you can have an array of instructions etc, but even that is limiting.
    Coroutines allow you to describe these scripts very naturally, and with a lot less fuss and boilerplate.

    I would love to see coroutines.
    It's one of the things scripting languages are great for. And would greatly help in tasks such as cutscenes, dialog systems etc.

    They would help people polish their games without needing to develop more complex systems just for ,say, a cutscene system.

    And more than just the scripty things!
    Man, writing a log in system with proper handshakes require managing a lot of different states!
    Or you can use a couple coroutines and describe the sequence of state really naturally, writing the logic as if you didn't have to wait for server responses and all!

    They are a tremendously useful tool!
     
    Last edited: Jul 8, 2019

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice