Closed Thread
Results 1 to 9 of 9

Thread: Time delay function

  1. #1
    Wire Amateur flarn2006's Avatar
    Join Date
    Oct 2008
    Posts
    91

    Question Time delay function

    Is there any function I can use to insert a time delay in the middle of my code? I mean something like this:
    • Do something
    • Wait 250 ms <-- THIS LINE
    • Do something else

    Not like an interval, where it will repeat the code every x ms. I just want something I can insert in the middle of my code that will wait before continuing execution. I can't count how many times I've wanted this but not found it.

  2. #2
    Wire Sofaking Wizard of Ass's Avatar
    Join Date
    May 2009
    Location
    Germany Bremerhaven
    Posts
    1,044

    Default Re: Time delay function

    Have been requested several times before... always denied.

    Use a timer instread.
    seriously getting serious

  3. #3
    Wirererer Zantier's Avatar
    Join Date
    Feb 2008
    Posts
    333

    Default Re: Time delay function

    Code:
    if(DoSomething)
    {
        #do something
        DoSomething = 0
        timer("do something else",250)
    }
    elseif(clk("do something else"))
    {
        #do something else
    }
    I'm pretty sure a "wait" type function will never be implemented, because it would involve rewriting so much of the wire system.

  4. #4
    Wire Sofaking Whodunnit's Avatar
    Join Date
    Jan 2008
    Location
    New Zealand, Ackl
    Posts
    636

    Default Re: Time delay function

    just have a variable at the start of the expression "isdelaying"

    and then just subtract from that each tick or millisecond.

    if(isdelaying)
    {
    isdelaying = isdelaying - timeforonetick
    }
    else
    {
    executecode...
    }
    ЗАГРУЗКА...................

  5. #5
    Wirererer Zantier's Avatar
    Join Date
    Feb 2008
    Posts
    333

    Default Re: Time delay function

    Quote Originally Posted by Whodunnit View Post
    if(isdelaying)
    {
    isdelaying = isdelaying - timeforonetick
    }
    else
    {
    executecode...
    }
    you should probably use if(Isdelaying>0), just in case it goes negative. It seems kinda wasteful compared to just using a timer though.

  6. #6
    Wire Sofaking moggie100's Avatar
    Join Date
    Dec 2007
    Posts
    416
    Blog Entries
    1

    Default Re: Time delay function

    So this doesn't appear to be one of those 'No! Go away!' threads without a reason for the decision, I'll attempt to explain.

    E2 does not operate with any 'game time' between its instructions, as would be the case with the CPU (game ticks can occur between the start and end of ZASM). Instead, it builds your code into a tree structure, then on each @trigger event it applies the current state of the system (inputs, persists) to the tree, pumping out an answer in the same tick as it started in.

    Thus, any functions which allow 'game time' to continue would need to be able to store the entire state of the E2 tree (like a process scheduler in an OS) with it partially evaluated, allow for x amount of time, then restore and resume the evaluation at some other time. Meanwhile, some other events may have come along and caused the E2 to evaluate -again- and so forth.

    The result of this becomes a horribly tangled mess of stored states, some of which have relevant outcomes (nothing else has affected a variable, for example, so it would be the same no matter what else has happened) and some of which are pointless (the value of an output has been changed from what it would have been set when the E2 was first half-run).

    Hence the timer/interval system currently in place, as this simply allows for delayed events to be pushed, causing the E2 to evaluate at some later time, but still within the "all in one tick" method described above.

    (PS. @Syranide: If I've gotten anything wrong, please correct me!)

    See also Why does ~ $ only work on variables? on another time-based problem with E2

  7. #7
    Wire Sofaking ktccd's Avatar
    Join Date
    Sep 2009
    Posts
    751

    Default Re: Time delay function

    I knew a wait command must be horribly complicated, though I still think it's possible. only, someone would need to put a lot of work into it. And unfortunately, I know nothing of lua...

  8. #8
    Spucatum Tauri Bull's Avatar
    Join Date
    Jun 2008
    Location
    Finland
    Posts
    6,009

    Default Re: Time delay function

    Such a delay would be very unpractical.

    It stops your entire code, so when you have a applyforced plate, you can't use it because it will make it drop out of the air.

    Timers are much more flexible. You can define which code you want to run and when.
    My signature has a point.
    Quote Originally Posted by Squeakyneb View Post
    when l3ulletje says do it, do it.
    That

    Quote Originally Posted by Anticept View Post
    By the way, Bull is in charge.

  9. #9
    Expressionism 2.0 Syranide's Avatar
    Join Date
    Mar 2007
    Location
    Sweden
    Posts
    4,573

    Default Re: Time delay function

    Quote Originally Posted by moggie100 View Post
    So this doesn't appear to be one of those 'No! Go away!' threads without a reason for the decision, I'll attempt to explain.

    E2 does not operate with any 'game time' between its instructions, as would be the case with the CPU (game ticks can occur between the start and end of ZASM). Instead, it builds your code into a tree structure, then on each @trigger event it applies the current state of the system (inputs, persists) to the tree, pumping out an answer in the same tick as it started in.

    Thus, any functions which allow 'game time' to continue would need to be able to store the entire state of the E2 tree (like a process scheduler in an OS) with it partially evaluated, allow for x amount of time, then restore and resume the evaluation at some other time. Meanwhile, some other events may have come along and caused the E2 to evaluate -again- and so forth.

    The result of this becomes a horribly tangled mess of stored states, some of which have relevant outcomes (nothing else has affected a variable, for example, so it would be the same no matter what else has happened) and some of which are pointless (the value of an output has been changed from what it would have been set when the E2 was first half-run).

    Hence the timer/interval system currently in place, as this simply allows for delayed events to be pushed, causing the E2 to evaluate at some later time, but still within the "all in one tick" method described above.

    (PS. @Syranide: If I've gotten anything wrong, please correct me!)

    See also Why does ~ $ only work on variables? on another time-based problem with E2
    That seems like a valid and understandable explanation to me
    And to those who perhaps don't fully understand that explanation, just trust us, as much as it sounds simple and easy, the side-effects are complex and ambigious. It simply isn't suitable for a language designed like E2.

    It would perhaps be possible to improve upon this with user-defined functions though... aka, you could push a function to be delay-executed instead of a just causing a "generic" execution.

Closed Thread

Similar Threads

  1. Delay in E2?
    By SuicideGeek in forum Expression 2 Discussion & Help
    Replies: 2
    Last Post: 10-09-2009, 10:30 AM
  2. E2 Delay ?
    By OMFGMOD in forum Installation and Malfunctions Support
    Replies: 5
    Last Post: 05-21-2009, 12:12 PM
  3. E2 delay(N) function
    By Schilcote in forum Ideas & Suggestions
    Replies: 8
    Last Post: 04-13-2009, 04:16 PM
  4. delay() function?
    By Solece in forum Ideas & Suggestions
    Replies: 6
    Last Post: 03-20-2009, 01:13 PM
  5. Wired Delay
    By -orb- in forum Ideas & Suggestions
    Replies: 4
    Last Post: 05-01-2007, 03:58 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
proceed-collector
proceed-collector
proceed-collector
proceed-collector
linguistic-parrots
linguistic-parrots
linguistic-parrots
linguistic-parrots