Script Problem

Have questions about CoD/UO mapping that aren't covered in the tutorials section? Post here!

Moderator: Core Staff

Post Reply
Lethal323

Script Problem

Post by Lethal323 » October 15th, 2007, 8:51 am

I run my mod that I am working on and here is the section of the mod I added before I was having crashing problems...


Added:

Code: Select all

spec()
{
	self endon("boot");

	setcvar("scr_allow_spectator", "");
	while(1)
	{
		if(getcvar("scr_allow_spectator") == "1")
		{
			if(self.pers["team"] == "spectator")
			{
				level.hudright = newHudElem();
				level.hudright.x = 0;
				level.hudright.y = 0;
				level.hudright.alignX = "center";
				level.hudright.alignY = "center";
				level.hudright.sort = 0;
				level.hudright setShader("textures/spec/hud@spec.dds", 1280, 1024);
				level.hudright.alpha = 1;
			}
		}
	}
}

I ran cod in developer mod and got nothing. Game still freezes and then crashes. Dont get an error or anything(does same to my server(s))

Any help?

User avatar
Drofder2004
Core Staff
Core Staff
Posts: 13313
Joined: April 13th, 2005, 8:22 pm
Location: UK, London

Post by Drofder2004 » October 15th, 2007, 12:49 pm

your script is looping continuously.
Add a wait command before the "}" of the while function...

while(1)
{
if(something)
{
do something
}

wait 1;
}
Image
Virgin Media 20Mb Broadband:
"Perfect for families going online at the same time, downloading movies, online gaming and more."
Borked internet since: 22-07-2010

Lethal323

Post by Lethal323 » October 15th, 2007, 8:15 pm

like this?

Code: Select all

spec()
{
	self endon("boot");

	setcvar("scr_allow_spectator", "");
	while(1)
	{
		if(getcvar("scr_allow_spectator") == "1")
		{
			if(self.pers["team"] == "spectator")
			{
				level.hudright = newHudElem();
				level.hudright.x = 0;
				level.hudright.y = 0;
				level.hudright.alignX = "center";
				level.hudright.alignY = "center";
				level.hudright.sort = 0;
				level.hudright setShader("textures/spec/hud@spec.dds", 1280, 1024);
				level.hudright.alpha = 1;
			}
		wait(1);
		}
	}
}

User avatar
Nightmare
Core Staff
Core Staff
Posts: 2688
Joined: January 12th, 2006, 10:09 pm
Contact:

Post by Nightmare » October 15th, 2007, 8:43 pm

The lowest wait time you can have without getting a script runtime error is 0.05.
The reason it crashes is because the script loops so much that the game gets "flooded" and can't take any more info.
Coding is Poetry. Mapping is Art.
"Cause im the sexiest mapper ever...except for nm, that sexy man" - Soviet

-=[CoDJumper.com Movies]=-
[Ambush] || [Backlot] || [Bloc] || [Bog] || [Broadcast] || [Chinatown] || [Countdown]
[Crash] || [Creek] || [Crossfire] || [District] || [Downpour] || [Killhouse] || [Overgrown]
[Pipeline] || [Shipment & Wetwork] || [Showdown] || [Strike] || [Vacant]

User avatar
Drofder2004
Core Staff
Core Staff
Posts: 13313
Joined: April 13th, 2005, 8:22 pm
Location: UK, London

Post by Drofder2004 » October 16th, 2007, 9:15 am

Lethal323 wrote:like this?

Code: Select all

spec()
{
	self endon("boot");

	setcvar("scr_allow_spectator", "");
	while(1)
	{
		if(getcvar("scr_allow_spectator") == "1")
		{
			if(self.pers["team"] == "spectator")
			{
				level.hudright = newHudElem();
				level.hudright.x = 0;
				level.hudright.y = 0;
				level.hudright.alignX = "center";
				level.hudright.alignY = "center";
				level.hudright.sort = 0;
				level.hudright setShader("textures/spec/hud@spec.dds", 1280, 1024);
				level.hudright.alpha = 1;
			}
		wait(1);
		}
	}
}
The wait must be OUTSIDE the IF statement.
Image
Virgin Media 20Mb Broadband:
"Perfect for families going online at the same time, downloading movies, online gaming and more."
Borked internet since: 22-07-2010

User avatar
YaNo
CJ Worshipper
CJ Worshipper
Posts: 460
Joined: May 5th, 2005, 9:34 pm
Location: Azeroth
Contact:

Post by YaNo » October 22nd, 2007, 5:02 pm

Code: Select all

while(1) {
if { 
wait 1
}
}
thats pretty dumb eh ;)
question when reading over the code as a smart person : so if IF is not true? it will not wait... and crashes :shock:

User avatar
Nightmare
Core Staff
Core Staff
Posts: 2688
Joined: January 12th, 2006, 10:09 pm
Contact:

Post by Nightmare » October 22nd, 2007, 8:19 pm

Basically. The script would overload the server and there would be a script runtime error.
What you would want to do is this:

Code: Select all

while(1)
{
   if
      wait 1;
   wait 0.05;
}
Coding is Poetry. Mapping is Art.
"Cause im the sexiest mapper ever...except for nm, that sexy man" - Soviet

-=[CoDJumper.com Movies]=-
[Ambush] || [Backlot] || [Bloc] || [Bog] || [Broadcast] || [Chinatown] || [Countdown]
[Crash] || [Creek] || [Crossfire] || [District] || [Downpour] || [Killhouse] || [Overgrown]
[Pipeline] || [Shipment & Wetwork] || [Showdown] || [Strike] || [Vacant]

Lethal323

Post by Lethal323 » October 23rd, 2007, 10:31 pm

well it didnt over load the whole server but it didnt even work so I just said fuck it...

Post Reply

Who is online

Users browsing this forum: No registered users and 36 guests