Iterator practices

Discussion in 'Scripting Workshop' started by Lovechld2000, May 10, 2019.

  1. Lovechld2000

    Lovechld2000 NI Product Owner

    Messages:
    234
    I've tried to make an integer var $i loop up a lot of things , alter groups of items in the gui, affect a set of groups' engine parameters and with some testing I was not able to get erratic behaviour making them all happen at the same time. It did everything without any issues on a small scale.
    How can $i hold all these different values for all these different processes?
    Is it so fast it's doing everything without a problem?
    Is $i multi tasking when in a kontakt function,?
    If I have a heavy script, should I have different iterators for different processes?
    I couldn't find documentation about this. Is there a best practice standard for using iterator integer vars on a bigger scale, ie when you have 100 + functions ?
     
  2. EvilDragon

    EvilDragon Moderator Moderator

    Messages:
    14,599
    It goes like this. If you don't have any wait() in any callbacks, you can use one iterator variable everywhere, because callbacks are guaranteed to execute in a serial fashion one after another and in a single thread (meaning for each callback $i will be correctly reset and iterated upon). As soon as you have any wait() in callbacks that feature that same variable as iterator, you could get issues because multithreading starts to happen then.

    In general it's a good idea to have local iterator variables per function, just to make things cleaner. Of course KSP doesn't support local variables, so you should use SublimeKSP that does provide this feature :)
     
  3. Lovechld2000

    Lovechld2000 NI Product Owner

    Messages:
    234
    cheers man. that is very useful to know