Page 1 of 2

About thread lifetime

Posted: Wed Dec 15, 2004 3:13 am
by Deutsche Dogge
Question about thread lifetime

If i start a thread from a map .scr file like this

Code: Select all

thread myscriptfile.scr::mythread
and the thread is like this

Code: Select all

mythread:
	local.i = 0
	while(1)
	{
		switch(local.i)
		{
			case 1:
				iprintlnbold "print message 1"
				local.i = 2
				break
	
			case 2:
				iprintlnbold "print message 2"
				local.i = 3
				break

			case 3:
				iprintlnbold "print message 3"
				local.i = 4
				break

			case 4:
				iprintlnbold "print message 4"
				local.i = 1
				break

			default:
				iprintlnbold "print start message"
				local.i = 1
				break;
		}
		wait 45
	}
	
end
When the map is over and the server loads a new one, is this thread disposed automatically or i have to find a way to kill it manually?

Posted: Wed Dec 15, 2004 3:19 am
by Elgan
auto dies,

Posted: Wed Dec 15, 2004 3:48 am
by Deutsche Dogge
great, thanks :)
this is actually my first script so i didn't know :)

Posted: Wed Dec 15, 2004 9:28 am
by lizardkid
though,,, i have to say none of those cases will fire, local.i is defined as 0 up there, andall the cases require at least 1.

Posted: Wed Dec 15, 2004 1:00 pm
by jv_map
The default case will fire... kinda dodgy but I suppose it'll work :)

Posted: Wed Dec 15, 2004 11:35 pm
by Elgan
that might be what he was testing to see, workin on learning script

Posted: Thu Dec 16, 2004 12:07 am
by Deutsche Dogge
actually, a default label, in any languages, will catch everything that is not in the other label. And it works :wink:

But here's another question, as i refined my script a bit to use huddraw instead of iprintln and others.

I have 2 methods in my script, the message_loop and the print_center_msg with 2 args. Problem is, if i use a goto to call print_center_msg, it never comes back and ends the script at the first call to it. I also would like to get rid of those goto's. Also, Using exec the console tells me it can't find print_center_msg. How do i specify it is in the same script file?

Code: Select all

message_loop:
	local.m = 0
	while(1)
	{	
		switch(local.m)
		{
			case 1:
				exec print_center_msg "Bienvenue sur le serveur [IRQ] - Welcome on [IRQ] server" 10
				local.m = 2
				break
	
			case 2:
				exec print_center_msg "http://clanirq.no-ip.com pour downloads et nouvelles" 10
				local.m = 3
				break

			case 3:
				exec print_center_msg "Maps Fix par TheCheatPolice, Traduits par [IRQ]" 10
				local.m = 4
				break

			case 4:
				exec print_center_msg "Bazookas sans munitions, autres armes avec plus de munitions" 10
				local.m = 1
				break
				

			default:
				local.m = 1
				break;
		}
		wait 30		//delay between messages
	}
end

print_center_msg local.msg local.duration:
	
	// display the string approximatley centered
	// TODO:change to left-side to avoid gaming annoyance
	huddraw_string 20 local.msg
	huddraw_align 20 center center
	huddraw_rect 20 -150 20 0 0
	
	// display a fade-in
	for(local.i = 0; local.i <= 1; local.i += .2)
	{
		huddraw_alpha 20 local.i
		waitframe
	}
	
	// wait for the amount of time specified
	// TODO: timing tests
	for (local.i = 1; local.i <= local.duration; local.i++)
	{
		wait 1
	}
	
	// display a fade-out
	for (local.i = 1; local.i >= 0; local.i -= .2)
	{
		huddraw_alpha 20 local.i
		waitframe
	}
end

Posted: Thu Dec 16, 2004 12:25 am
by Deutsche Dogge
Ooopss. :oops:

nevermind, i just did some reading of Rjukan scripting guide, will use the fullname to the method. Would use waitthread but there's no need to spawn a new thread in this case. :wink:

Posted: Thu Dec 16, 2004 2:21 am
by Elgan
// wait for the amount of time specified
// TODO: timing tests
for (local.i = 1; local.i <= local.duration; local.i++)
{
wait 1
}


why not just use wait local.duration ?

Posted: Thu Dec 16, 2004 3:21 am
by Deutsche Dogge
Very good point. I have nothing to say against that. :roll:

modifying it right now. :wink:

Posted: Thu Dec 16, 2004 5:52 am
by Deutsche Dogge
Final script, for messages in loop. Edition of specific map.scr is needed by adding this after level waittill spawn until i find a way of calling it at server statup only.

Code: Select all

//this is below level waittill spawn
thread global/server_messages.scr::message_loop
putting the "server_messages.scr" in main/global fodler or in a "global" folder inside a pk3. Customize the mesasges and add case labels as needed.

Code: Select all

// this file is in main/global/server_messages.scr
message_loop:
	local.m = 1
	while(1)
	{	
		switch(local.m)
		{
			case 1:
				wait 5
				waitexec global/server_messages.scr::print_msg "Bienvenue sur le serveur [IRQ] - http://clanirq.no-ip.com" 3
				waitexec global/server_messages.scr::print_msg "Welcome on [IRQ] server - http://clanirq.no-ip.com" 3
				local.m = 2
				break

			case 2:
				wait 5
				waitexec global/server_messages.scr::print_msg "Respectez les autres joueurs, restez polis, c'est un JEU!" 3
				waitexec global/server_messages.scr::print_msg "Respect other players, stay polite, it's a GAME!" 3
				local.m = 3
				break

			case 3:
				wait 5
				waitexec global/server_messages.scr::print_msg "Maps Fix par TheCheatPolice, Traduits par [IRQ]" 3
				waitexec global/server_messages.scr::print_msg "Maps Fix by TheCheatPolice, Translated by [IRQ]" 3
				local.m = 4
				break

			case 4:
				wait 5
				waitexec global/server_messages.scr::print_msg "Bazookas sans munitions, les autres armes ont plus de munitions" 3
				waitexec global/server_messages.scr::print_msg "Bazookas have no ammo, other weapons have extra ammo" 3
				local.m = 5
				break
				
			case 5:
				wait 5
				waitexec global/server_messages.scr::print_msg "http://clanirq.no-ip.com pour downloads, nouvelles et forums" 3
				waitexec global/server_messages.scr::print_msg "http://clanirq.no-ip.com for downloads, news and forums" 3
				local.m = 6
				break
				
			case 6:
				wait 5
				waitexec global/server_messages.scr::print_msg "Allez telecharger les fichiers de jeu sur le site web!" 3
				waitexec global/server_messages.scr::print_msg "Downloads the game files on the website!" 3
				local.m = 1
				break

			default:	// in case something changes local.m, reset it to
				local.m = 1
				break;
		}
		wait 25		//delay between messages in seconds
	}
end

// print the specified message for the specified seconds+2seconds (fade-in/fade-out)
print_msg local.msg local.duration:

	// draw a shadow of the string in black
	huddraw_virtualsize 50 1		// use virtual screen size of 640x480
	huddraw_rect 50 37 -64 0 0		// element id, top, left, width, height (for string, width/height can be 0)
	huddraw_color 50 0.0 0.0 0.0 		// element id, red, green, blue (0.0 to 1.0)
	huddraw_font 50 "courier-16"		// element id, fontname (pak0/fonts/*) 
	huddraw_string 50 local.msg		// element id, string
	huddraw_align 50 "left" "bottom"	// element id, (left/center/right), (top/middle/bottom)
	
	// draw the overlay colored string
	huddraw_virtualsize 51 1
	huddraw_rect 51 35 -65 0 0
	huddraw_color 51 0.9 0.9 0.1 
	huddraw_font 51 "courier-16"
	huddraw_string 51 local.msg
	huddraw_align 51 "left" "bottom"

	// display a fade-in
	for(local.i = 0; local.i <= 1; local.i += .2)
	{
		huddraw_alpha 50 local.i
		huddraw_alpha 51 local.i
		waitframe
	}
	
	// wait for the amount of time specified
	wait local.duration
	
	// display a fade-out
	for (local.i = 1; local.i >= 0; local.i -= .1)
	{
		huddraw_alpha 50 local.i
		huddraw_alpha 51 local.i
		waitframe
	}
end
I call print_message twice for each label for bilingual messages, could be called onlu once or to display a longer message.

it actually display like this:
Image

First fully functionnal script... and i liked doing it :)
Thanks MJ for giving me the extra push i needed to start scripting :wink:

Posted: Thu Dec 16, 2004 11:11 am
by jv_map
Nice, but why are you typing all this stuff:

waitexec global/server_messages.scr::print_msg

when you simply could've typed

waitthread print_msg

instead?

Obviously the big advantage of the latter is that it's shorter to type and will still work even if you ever decide to rename the script file.

Posted: Thu Dec 16, 2004 3:20 pm
by Deutsche Dogge
I assumed that doing a exec was execing the method in the same thread instead of starting a new thread to execute. is that right? If not, i'm gonna do as you say.

Also, is there a way to make a global script variable keeping the name of the script file, like local.file = [scripfilename] and then refer to it like this:
local.file exec print_message "msg" 5 ?

Posted: Thu Dec 16, 2004 3:33 pm
by jv_map
Deutsche Dogge wrote:I assumed that doing a exec was execing the method in the same thread instead of starting a new thread to execute. is that right?
Both start a new thread.
Also, is there a way to make a global script variable keeping the name of the script file, like local.file = [scripfilename] and then refer to it like this:
local.file exec print_message "msg" 5 ?
Yes do it like this:

local.file = "global/somescript.scr"
exec local.file::print_message "msg" 5

Posted: Thu Dec 16, 2004 3:38 pm
by Deutsche Dogge
Well if both starts a new thread, i'll just call waitexec then.

And for the cript filename, is there a way to get the filename automatically? just like in web programming where you can use the "script_name" serevr variable so it's not hard-coded?