Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

help with threads?

Asked by 8 years ago

So i know that a thread is and that adding a new script to a game can be considered like creating a new thread so when it comes to developing a game would it be better to organize my code into one local and one server script that then access several module scripts much like a class would with the local and server scripts executing several things at once using methods like coroutines and spawn() or have several local and server scripts that all do a set thing?

1 answer

Log in to vote
1
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
8 years ago

In general:

  • Code on fewer coroutines will be faster
  • Code on more coroutines is easier to write (at least at first blush)

Coroutines are not threads.

Coroutines work with a scheduler to determine who-works-when. Only one coroutine works at a time, and switching between them takes a bit of time. That's why code with many different scripts / spawned coroutines gets slow.


Having multiple scripts is not a problem. 2 or 3 or 10 shouldn't be bad at all.

What you might want to avoid is situations where you have many copies of the same script, e.g., each one running one NPC / vehicle / turret / etc.

See here for both versions of code -- with spawn and without

0
ok thank you this helped a lot ProfessorSev 220 — 8y
Ad

Answer this question