Welcome to Keen Software House Forums! Log in or Sign up to interact with the KSH community.
  1. You are currently browsing our forum as a guest. Create your own forum account to access all forum functionality.

Script freezes game

Discussion in 'Programming (In-game)' started by cheb, May 28, 2020.

Thread Status:
This last post in this thread was made more than 31 days old.
  1. cheb Trainee Engineer

    Messages:
    12
    Are ingame scripts running in main thread?
    I made a sorter for my storage. Every time it works, game freezes on ~0.5 second =(
    It freezes even i transfer one stack.
     
  2. Malware Master Engineer

    Messages:
    9,865
    Correct, scripts are not threaded.

    (Please don't ask why. Too long an explanation. In short, scripts are experimental for a reason.)
     
  3. cheb Trainee Engineer

    Messages:
    12
    This is awful :(. And as I understand it, Threads are blacklisted in api?
    How then scripts work in multiplayer. Every clients stops and wait every script execution?
     
  4. Malware Master Engineer

    Messages:
    9,865
    Yes. But it's not as bad as you might think. Scripts are really fast. That is, unless you botch them up badly. It's not the script that is your problem, but the inventory system.

    You're doing too much in a single tick. You need to split it up.

    Like this, for example.
    https://github.com/malware-dev/MDK-SE/wiki/Coroutines---Run-operations-over-multiple-ticks

    Threads are not whitelisted for the same reason that the PB itself is not threaded. The API is not threadsafe (to the level that noobs can use it safely).
     
  5. cheb Trainee Engineer

    Messages:
    12
    Thank you. It seems i found the problem: https://forum.keenswh.com/threads/system-text-regularexpressions-performance-in-scripts.7404059/
     
  6. Malware Master Engineer

    Messages:
    9,865
    Oooooo yes. Do not regular expressions. They be slooow.

    For your info though. It is the very same compiler used. The very same instances. This IS pure C#. The PB does nothing special with the code other than inject some per-junction infinite loop protection. That's all.

    For the record; I know this for a fact because I wrote the compiler system in use. No guessing or assumptions involved.

    But. There is a lot going on in the game, threaded.
     
  7. cheb Trainee Engineer

    Messages:
    12
    How this affects Regex objects? Some variable locks?
     
  8. Malware Master Engineer

    Messages:
    9,865
    No, it will affect the scheduler determining when the various threads runs. Even threading isn't free processing, after all.

    This is the only thing I can imagine would affect it, if you're not running .NET Core or something locally rather than .NET 4.6.1, and as such might have a better optimized Regex... ¯\_(ツ)_/¯

    because if not, it's the exact same code running.
     
    Last edited: May 29, 2020
Thread Status:
This last post in this thread was made more than 31 days old.