UGX-Mods Login

or login with an authentication provider below
Sign In with Google
Sign In with Twitter
Sign In with Discord
Sign In with Steam
Sign In with Facebook
Sign In with Twitch

Calling functions when to use thread

broken avatar :(
Created 6 years ago
by Doodles_Inc
0 Members and 1 Guest are viewing this topic.
1,059 views
broken avatar :(
×
broken avatar :(
Location: br
Date Registered: 20 April 2016
Last active: 2 years ago
Posts
145
Respect
Forum Rank
Pack-a-Puncher
Primary Group
Member
My Contact & Social Links
More
Personal Quote
if I surprised you, you had underestimated me
Signature
if I surprised you, it was because you underestimated me
×
Doodles_Inc's Groups
Doodles_Inc's Contact & Social LinksdoodlescriminoserDoodles_IncDoodlesInc
Another nooby question, I noticed people use thread to call functions, is it needed? What does it do really?
What's the difference between
Code Snippet
Plaintext
function(argument)
and
Code Snippet
Plaintext
thread function(argument)
?
Last Edit: July 10, 2018, 06:42:46 pm by Doodles_Inc
Marked as best answer by Doodles_Inc 6 years ago
broken avatar :(
×
broken avatar :(
Location: nlApeldoorn
Date Registered: 17 December 2013
Last active: 1 year ago
Posts
1,187
Respect
1,404Add +1
Forum Rank
Zombie Colossus
Primary Group
Community Scripter Elite
My Groups
More
My Contact & Social Links
More
Personal Quote
It aint much, if it aint Dutch
Signature
×
BluntStuffy's Groups
Donator ♥ Benevolent Soul who has our eternal gratitude and exclusive access to betas and the donator section of the forum.
Community Scripter Elite Has shown excellence and experience in the area of custom scripting in the UGX-Mods community.
Oil Rig Beta Access
Oil Rig Beta Access
BluntStuffy's Contact & Social LinksBluntstuffy@BluntZombieBluntStuffyStuffyZombie
When you just call a function, the execution is not going to continue till that function ends. Only when that function is completed, the Original execution-chain will continue.

When you thread a function the execution will continue as well and all code below it will immediately be executed.


So for example, if you call the function AddStuffToVariable() it will print "I have increased":
Code Snippet
Plaintext
SomeFunction()
{
level.SomeVariable = 1;

Add_Stuff_To_Variable();

if( level.SomeVariable == 2 )
{
Iprintln( "I have increased" );
}
else
{
Iprintln( "I'm still 1" );
}
}
Add_Stuff_To_Variable()
{
wait 1;
level.SomeVariable++;
}




But if you thread it it will print "I'm still 1" because it immediately executes that code, and the variable will only be increased a second later..:
Code Snippet
Plaintext
SomeFunction()
{
level.SomeVariable = 1;

thread Add_Stuff_To_Variable();

if( level.SomeVariable == 2 )
{
Iprintln( "I have increased" );
}
else
{
Iprintln( "I'm still 1" );
}
}
Add_Stuff_To_Variable()
{
wait 1;
level.SomeVariable++;
}
broken avatar :(
×
broken avatar :(
Location: br
Date Registered: 20 April 2016
Last active: 2 years ago
Posts
145
Respect
Forum Rank
Pack-a-Puncher
Primary Group
Member
My Contact & Social Links
More
Personal Quote
if I surprised you, you had underestimated me
×
Doodles_Inc's Groups
Doodles_Inc's Contact & Social LinksdoodlescriminoserDoodles_IncDoodlesInc
Thanks for the clear explanation  :D

 
Loading ...