Page 1 of 1

Script Problem

Posted: October 15th, 2007, 8:51 am
by Lethal323
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?

Posted: October 15th, 2007, 12:49 pm
by Drofder2004
your script is looping continuously.
Add a wait command before the "}" of the while function...

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

wait 1;
}

Posted: October 15th, 2007, 8:15 pm
by Lethal323
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);
		}
	}
}

Posted: October 15th, 2007, 8:43 pm
by Nightmare
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.

Posted: October 16th, 2007, 9:15 am
by Drofder2004
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.

Posted: October 22nd, 2007, 5:02 pm
by YaNo

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:

Posted: October 22nd, 2007, 8:19 pm
by Nightmare
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;
}

Posted: October 23rd, 2007, 10:31 pm
by Lethal323
well it didnt over load the whole server but it didnt even work so I just said fuck it...