Login / Registrieren
DE EN FR ES IT CZ
Zurück Nach oben

Question about loops

  • #1, by ke4 11 years ago Zitieren
    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!
  • #2, by Simon_ASA 11 years ago Zitieren
    This is a good question because I also have several loops in definition scripts.
  • #3, by sebastian 11 years ago Zitieren
    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)?
  • #4, by ke4 11 years ago Zitieren
    I mean mostly registerEventHandler loops
  • #5, by Alex 11 years ago Zitieren
    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.
  • #6, by ke4 11 years ago Zitieren
    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.
  • #7, by Alex 11 years ago Zitieren
    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.
  • #8, by ke4 11 years ago Zitieren
    Okey thank you Alex.