Question about loops

  • #1, by ke4Monday, 17. August 2015, 19:00 9 years ago
    Hi,

    i wanto ask you, how much are the loop scripts gruelling the system?
    I wanted dragged items to disappear in invetory, which is done by tile covering the item, but for recalling that i had to set up a loop checking if there is some dragged item.

    And there is a loop for aligning the text, loop for positioning the character shadow etc etc..

    how many loops is still ok for the system?
    Thanks!

    Key Killer

    810 Posts


  • #2, by Simon_ASAMonday, 17. August 2015, 19:19 9 years ago
    This is a good question because I also have several loops in definition scripts.

    Great Poster

    321 Posts

  • #3, by sebastianMonday, 17. August 2015, 22:13 9 years ago
    indeed, a good question razz
    I think it depends on how the loops are generated: are they normal for, while, etc loops in a lua script or actionsparts who jump to the beginning (which are maybe more resource consuming)?

    Thread Captain

    2346 Posts

  • #4, by ke4Monday, 17. August 2015, 22:18 9 years ago
    I mean mostly registerEventHandler loops

    Key Killer

    810 Posts

  • #5, by AlexTuesday, 18. August 2015, 01:23 9 years ago
    it depends what your event handler is doing. Each event handler is called at max. only one time per player main loop. Usually lua functions are executed very fast so you shouldn't run into any performance issues. Unless your function performs disk I/O or some insane stuff like traversing ten thousands of objects etc.
    I think very long script executions are registered in the log file. If the event handler or function execution takes multiple milliseconds it usually means that you're doing something wrong.

    Great Poster

    378 Posts

  • #6, by ke4Tuesday, 18. August 2015, 08:06 9 years ago
    Thanks alex, i already have issues with occasionally lagging so i try to be careful.

    For example the loop checking the inventory. On every mouse movement if there is no dragged item it sets 10 conditions to false. Works fine, but it runs even if it's not needed, its still setting the conditions even if i'm not working with items. I didn't find another way to make it work so i hope loops like this are ok.

    Key Killer

    810 Posts

  • #7, by AlexTuesday, 18. August 2015, 12:01 9 years ago
    that should be fine. One easy optimization would probably be to store the previous state of last execution (item dragged / not dragged) in a variable and only perform the rest when the state changed.

    Great Poster

    378 Posts

  • #8, by ke4Tuesday, 18. August 2015, 12:05 9 years ago
    Okey thank you Alex.

    Key Killer

    810 Posts