Thread versus exec...

Post your scripting questions / solutions here

Moderator: Moderators

Post Reply
User avatar
G3mInI
First Lieutenant
Posts: 187
Joined: Sat Jun 29, 2002 3:49 am

Thread versus exec...

Post by G3mInI »

I have an .scr file in a global folder that runs some effects on my map that I am making. A couple of scripted entities being spawned and then a couple of while loops (blinking dynamic lights, and occasional dust falling from a ceiling).

My question is, in my level script, what is the difference between saying thread blah blah.scr versus exec blah blah?

I see in the original scripts by mohaa some scripts like door_lockeds.scr are executed, whereas others such as obj_dm.scr are threaded from the main level script.

What is actually the difference between threading an .scr file and executing it?

G3mInI
*Area51*G3mInI****Gen

http://www.area51moh.com
Elgan
Lieutenant General
Posts: 890
Joined: Tue Apr 13, 2004 10:43 pm
Location: uk
Contact:

Post by Elgan »

thread
waitthread

^^ Used when calling a thread in the same file/script

exec
waitexec

^^ used when calling another script/file


To call a thread in another script, use the :: thing.

Code: Select all

exec global/scriptname.scr::threadname
jv_map
Site Admin
Posts: 6521
Joined: Tue Sep 03, 2002 2:53 pm
Location: The Netherlands
Contact:

Post by jv_map »

It is also possible to 'thread' from another script in the same way :wink:

As far as I know there is only a very subtle difference between 'thread' and 'exec', which is only apparent when calling threads within the same file. 'exec' creates a new thread group, whereas 'thread' expands the current thread group, provided it is posted as an event for the current thread ('local') and not as an event for a specific listener.

:?

I realize that sentence may not make a lot of sense so I'll try a more illustrative approach. First some defs

A thread group is just a bunch of threads (processes) which are bundled internally by the script interpreter. Usually the concept is unimportant for scripting unless you are using the 'group' object to store variables, since this requires the threads you want to share variables to belong to the same thread group.

Thread groups may be created when new threads start and may be destroyed when all of its threads have ended.

Individual threads in a thread group always belong to the same 'physical' script file (.scr).

Now it is important to take a closer look at how threads may be started. There are a couple of options:
  1. thread somethread
  2. thread somescript::somethread
  3. someobject thread somethread
  4. someobject thread somescript::somethread
  5. exec somescript
  6. exec somescript::somethread
  7. someobject exec somescript
  8. someobject exec somescript::somethread
Additionally, there are also waitthread / waitexec variants which I will discuss in a moment.

Option 1 is the only option that will gently expand the current thread group. All other options will lead to new thread groups being created.

Note that 'someobject' includes entities ('$door thread do_this'), self ('self thread do_that'), or any other listeners.

For waitthread/waitexec the situation is similar, only 'waitthread somethread' preserves thread group.

So the difference between 'thread' and 'exec':
thread may maintain thread group, exec never does

There is also another difference between 'waitthread' and 'waitexec':
waitthread waits for the thread to finish, waitexec waits for the entire thread group to finish. The results of this may be quite unexpected and I therefore advise always to use waitthread instead of waitexec.

This ought to help 8-)
Image
User avatar
G3mInI
First Lieutenant
Posts: 187
Joined: Sat Jun 29, 2002 3:49 am

Post by G3mInI »

Thanks for that explanation...

Which of course leads me to a few more questions...

If I am wanting to run some 'processes' which have nothing to do with the main script (ie. two seperate while loops which are creating some special effects in the same script file) then I should execute this script from my main level script correct?

Another question is... How many concurrent threads can the mohaa engine handle? And at what point does lag become introduced?

I am beginning to get out of my league here so to speak so the last questions may not even be asked correctly. I just don't want to introduce lag into my map... I like the effects but if they cause lag, then I can do without them...

Along those lines.... Here is the special effects script I am executing, which works well and does what I want, but I would like it if any scripter out there can tell me how to condense this or write it better than it is....

Code: Select all

//Various effects for building1 map



//spawn some stuff
main:

	thread dust_effects


	level.corona1 = spawn script_model model "static/corona_orange.tik" "targetname" "corona" scale "1.0"
	level.corona1.origin = ( 1200.00 668.00 0.00 )
	
	level.corona2 = spawn script_model model "static/corona_orange.tik" "targetname" "corona" scale "1.0"
	level.corona2.origin = ( 930.00 1704.00 0.00 )
	
	level.corona3 = spawn script_model model "static/corona_orange.tik" "targetname" "corona" scale "1.0"
	level.corona3.origin = ( 660.00 2470.00 0.00 )

	level.corona4 = spawn script_model model "static/corona_orange.tik" "targetname" "corona" scale "1.0"
	level.corona4.origin = ( 930.00 2740.00 0.00 )

	level.corona5 = spawn script_model model "static/corona_orange.tik" "targetname" "corona" scale "1.0"
	level.corona5.origin = ( 1200.00 3506.00 0.00 )
	
	level.corona6 = spawn script_model model "static/corona_orange.tik" "targetname" "corona" scale "1.0"
	level.corona6.origin = ( 930.00 3776.00 0.00 )
	
	level.corona7 = spawn script_model model "static/corona_orange.tik" "targetname" "corona" scale "1.0"
	level.corona7.origin = ( 1200.00 3776.00 0.00 )
	
	level.corona8 = spawn script_model model "static/corona_orange.tik" "targetname" "corona" scale "1.0"
	level.corona8.origin = ( 1200.00 3258.00 0.00 )
	
	level.corona9 = spawn script_model model "static/corona_orange.tik" "targetname" "corona" scale "1.0"
	level.corona9.origin = ( 1200.00 3010.00 0.00 )
	
	level.corona10 = spawn script_model model "static/corona_orange.tik" "targetname" "corona" scale "1.0"
	level.corona10.origin = ( 1200.00 2740.00 0.00 )
	
	level.corona11 = spawn script_model model "static/corona_orange.tik" "targetname" "corona" scale "1.0"
	level.corona11.origin = ( 660.00 2740.00 0.00 )
	
	level.corona12 = spawn script_model model "static/corona_orange.tik" "targetname" "corona" scale "1.0"
	level.corona12.origin = ( 660.00 2222.00 0.00 )
	
	level.corona13 = spawn script_model model "static/corona_orange.tik" "targetname" "corona" scale "1.0"
	level.corona13.origin = ( 660.00 1974.00 0.00 )
	
	level.corona14 = spawn script_model model "static/corona_orange.tik" "targetname" "corona" scale "1.0"
	level.corona14.origin = ( 660.00 1704.00 0.00 )
	
	level.corona15 = spawn script_model model "static/corona_orange.tik" "targetname" "corona" scale "1.0"
	level.corona15.origin = ( 1200.00 1704.00 0.00 )
	
	level.corona16 = spawn script_model model "static/corona_orange.tik" "targetname" "corona" scale "1.0"
	level.corona16.origin = ( 1200.00 1434.00 0.00 )
	
	level.corona17 = spawn script_model model "static/corona_orange.tik" "targetname" "corona" scale "1.0"
	level.corona17.origin = ( 1200.00 1186.00 0.00 )
	
	level.corona18 = spawn script_model model "static/corona_orange.tik" "targetname" "corona" scale "1.0"
	level.corona18.origin = ( 1200.00 938.00 0.00 )
	
	level.corona19 = spawn script_model model "static/corona_orange.tik" "targetname" "corona" scale "1.0"
	level.corona19.origin = ( 930.00 668.00 0.00 )
	
	thread blinker
	

end

blinker:

while(1)
	{	
		local.choice = (randomint $corona.size + 1)
		thread blink_me local.choice
		
		local.choice2 = (randomint $corona.size + 1)
		if((local.choice2 != local.choice))
			thread blink_me local.choice2
			
		local.choice3 = (randomint $corona.size + 1)
		if(((local.choice3 != local.choice)&&(local.choice3 != local.choice2)))
			thread blink_me local.choice3
			
		local.choice4 = (randomint $corona.size + 1)
		if(((local.choice4 != local.choice)&&(local.choice4 != local.choice2)&&(local.choice4 != local.choice3)))
			thread blink_me local.choice4
			
		local.choice5 = (randomint $corona.size + 1)
		if(((local.choice5 != local.choice)&&(local.choice5 != local.choice2)&&(local.choice5 != local.choice3)&&(local.choice5 != local.choice4)))
			thread blink_me local.choice5
			
		local.choice6 = (randomint $corona.size + 1)
		if(((local.choice6 != local.choice)&&(local.choice6 != local.choice2)&&(local.choice6 != local.choice3)&&(local.choice6 != local.choice4)&&(local.choice6 != local.choice5)))
			thread blink_me local.choice6
		
		wait (randomint 4 + 8)
	}
	
end	

blink_me local.x:
		$corona[local.x] loopsound m1l2b_radio2
		$corona[local.x] hide
		wait .1
		$corona[local.x] show
		wait .1
		$corona[local.x] hide
		wait .1
		$corona[local.x] show
		wait .1
		$corona[local.x] hide
		wait .1
		$corona[local.x] show
		wait .2
		$corona[local.x] hide
		wait .1
		$corona[local.x] show
		wait .1
		$corona[local.x] hide
		wait .1
		$corona[local.x] show
		wait .1
		$corona[local.x] hide
		wait .1
		$corona[local.x] show
		$corona[local.x] stoploopsound m1l2b_radio2

end

dust_effects:

while (1)
	{
		local.choice1 = (randomint $dust.size + 1)
		thread dusting local.choice1
		
		local.choice2 = (randomint $dust.size + 1)
			if(local.choice2 != local.choice1)
			thread dusting local.choice2
		
		local.choice3 = (randomint $dust.size + 1)
			if((local.choice3 != local.choice1) && (local.choice3 != local.choice2))
			thread dusting local.choice3
		
		local.choice4 = (randomint $dust.size + 1)
		if((local.choice4 != local.choice1) && (local.choice4 != local.choice2) && (local.choice4 != local.choice3))
		thread dusting local.choice4
		
		wait (randomint 1 + 7)
	}
	
end	

dusting local.x:

$dust[local.x] anim start

end
Basically the coronas will blink and play the static sound which works and sounds good to the player...and since the sound I am playing is already included for obj maps in ubersound, I don't need an scriptmaster workaround. The dust does pretty much the same where an effect or two will animate... The scene is dark underground type tunnel... and I wanted to create dust falling randomly and flickering lights randomly. I have a feeling it could be better as far as randomness is concerned because it seems like two or 3 go off at same time... I would really like it to be totally random and when 1 light flickers maybe another light a bit further down will flicker a few seconds later instead of at same time. But my knowledge of scripting could only come up with this which does work and looks ok since you can only see about 4 lights at any one time, same with the dust entities.

G3mInI
*Area51*G3mInI****Gen

http://www.area51moh.com
Post Reply