(adsbygoogle = window.adsbygoogle || []).push({});
I see people getting this alot and nobody really understands :yuno:. You would through legit basic programming.
First thing: Difference between entities
entities are objects found throughout the game whether it be a trigger radius, an environment, a variable, or even a player. most people don't know what level is. Well level is an entity that is controlled at startup. It is like the basic entity that controls the game (in a match). Level function will execute that function for all players or atleast effect them.
Self: self is the entity currently running the function for example
onJoin()
{
for(;
{
level waittill("connected", player);
player thread welcome();
}
}
welcome()
{
self iPrintlnBold("hi");
}
In that case self is the player that was connected through the game and was what executed the thread welcome.
example two:
init()
{
level thread onPlayerConnect();
level thread execForAll();
}
execForAll()
{
trig = self spawn("trigger", (0,0,0));
}
in that function an entity named "trig" is being created by the Level. Notice how level executed it so SELF is LEVEL. in this instance self is not a player such as yourself.
Second Thing: Basic understanding of functions
Now im surprised most of you don't know how to do just the basics.
self thread welcome();
That makes the entity "self" run the function welcome parallel to the game running.
self doAFunction();
self thread welcome();
}
doAFunction()
{
for(i=0;i<100;i++)
wait 1;
}
Now see you don't need thread. All thread makes it do is run parallel. In this instance it would have to wait 100 seconds before executing the function welcome. All thread does is run it alongside another function. you DONT need thread all the time and in most cases if used to much it crashes the game.
init()
{
welcome();
}
You guessed it, you don't even need an entity executing the function. If an entity is not defined the game engine will run it but like in a level bases. so it will execute welcome whatever it does without affecting any other entities.
I hope this helps you learn to code better and makes you a little less confused because tbh most of the scripts I look at are sloppy, have logical errors, and could easily crash the game, or could've been made better.
Welcome