script shortening

Archive of the old editing forum
Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. This forum is archived - please use this set of forums to ask new questions.
User avatar
Bio Hazard
Posts: 4019
Joined: Fri Aug 15, 2003 8:15 pm
Location: ferret ~/C/ZDL $

script shortening

Post by Bio Hazard »

anybody have any idea how to shorten this script?

Code: Select all

//////////////////////////////////
// start my big elevator script //
//////////////////////////////////

int eleopen;
int doorbroken;
int elemove;

script 1 (void)
{
	if (doorbroken == 1) // if the door is broken
	{
		eleopen = 1;									// door is open
		polyobj_move(1,5,128,5);						// door open
		polyobj_move(2,5,0,55);							// door open
		light_fade (13,128,90);							// light up the room
		light_fade (17,120,90);							// light up the room
		light_fade (20,120,90);							// light up the room
		thing_activate(19);								// sparks
		delay(const:256);
		polyobj_move(1,5,0,5);							// door close
		polyobj_move(2,5,128,55);						// door open
		light_fade (13,100,90);							// light down the room
		light_fade (17,100,90);							// light down the room
		light_fade (20,96,90);							// light down the room
		thing_activate(19);								// sparks
		delay(const:90);
		eleopen = 0;									// door is closed
	}

	if (doorbroken == 0) // inital elevator open
	{
		eleopen = 1;									// door is open
		polyobj_move(1,5,128,55);						// door open
		polyobj_move(2,5,0,55);							// door open
		light_fade (13,128,90);							// light up the room
		light_fade (17,120,90);							// light up the room
		light_fade (20,120,90);							// light up the room
		delay(const:256);
		polyobj_move(1,5,0,20);							// door close
		polyobj_move(2,5,128,55);						// door open
		light_fade (13,100,90);							// light down the room
		light_fade (17,100,90);							// light down the room
		light_fade (20,96,90);							// light down the room
		delay(const:40);
		thingsound(18,"explode",100);					// door blowing up
		delay(const:30);
		thing_activate(19);								// sparks
		doorbroken = 1;									// door is now broken
		delay(const:15);
		eleopen = 0;									// door is closed
		delay(const:15);
		thing_deactivate(19);							// reset sparks
		delay(const:1);
		thing_activate(19);								// more sparks
	}

}

script 2 (void) // inside elevator doors
{
	if (elemove == 0)
	{
		if (eleopen == 0)
		{
			acs_execute(1,0,0,0,0);						// open the doors
		}
	}

	if (elemove == 1)
	{
		print(s:"Warning: Elevator in Motion");			// wait you idiot
	}
}

script 3 (void) // elevator
{
if (eleopen == 1)
	{
		print(s:"Warning: Doors Open");					// wait you idiot
	}
if (eleopen == 0)
	{
		print(s:"Going down!");
		thingsound(22,"elebell",100);					// elevator bell
		elemove = 1;									// elevator is moving
		floor_lowerbyvalue(21,10,750);					// move the elevator
		ceiling_lowerbyvalue(21,10,750);				// move the elevator
		light_fade (28,32,512);							// light down the window
		delay(const:512);
		radius_Quake (5,15,0,64,22);					// elevator stops
		thingsound(22,"elebell",100);					// elevator bell
		elemove = 0;									// elevator not moving
	}
}
Last edited by Bio Hazard on Thu Aug 21, 2003 2:02 am, edited 1 time in total.
User avatar
Chris
Posts: 3000
Joined: Thu Jul 17, 2003 12:07 am
Graphics Processor: ATI/AMD with Vulkan/Metal Support

Post by Chris »

Code: Select all

script 1 (void)
{
   eleopen = 1;                           // door is open
   polyobj_move(1,5,128,5);                  // door open
   polyobj_move(2,5,0,55);                     // door open
   light_fade (13,128,90);                     // light up the room
   light_fade (17,120,90);                     // light up the room
   light_fade (20,120,90);                     // light up the room

   if (doorbroken == 1) // if the door is broken
   {
      thing_activate(19);                        // sparks
      delay(const:256);
      polyobj_move(1,5,0,5);                     // door close
      polyobj_move(2,5,128,55);                  // door open
      light_fade (13,100,90);                     // light down the room
      light_fade (17,100,90);                     // light down the room
      light_fade (20,96,90);                     // light down the room
   }

   if (doorbroken == 0) // inital elevator open
   {
      delay(const:256);
      polyobj_move(1,5,0,20);                     // door close
      polyobj_move(2,5,128,55);                  // door open
      light_fade (13,100,90);                     // light down the room
      light_fade (17,100,90);                     // light down the room
      light_fade (20,96,90);                     // light down the room
      delay(const:40);
      thingsound(18,"explode",100);               // door blowing up
      delay(const:30);
      thing_activate(19);                        // sparks
      doorbroken = 1;                           // door is now broken
      delay(const:30);
      thing_deactivate(19);                     // reset sparks
      delay(const:1);
   }

   thing_activate(19);                        // sparks
   delay(const:90);
   eleopen = 0;                           // door is closed
}
User avatar
Hirogen2
Posts: 2033
Joined: Sat Jul 19, 2003 6:15 am
Operating System Version (Optional): Tumbleweed x64
Graphics Processor: Intel with Vulkan/Metal Support
Location: Central Germany

Re: script shortening

Post by Hirogen2 »

How about removing the whitespaces.

Change

Code: Select all

		floor_lowerbyvalue(21,10,750);					// move the elevator
		ceiling_lowerbyvalue(21,10,750);				// move the elevator
into (there are different possibilites):

Code: Select all

FloorAndCeiling_LowerByValue(...);
Elevator_RaiseToNearest(...);
Elevator_MoveToFloor(...);
Elevator_LowerToNearest(...);
Check them at http://zdoom.sf.net/reference/act_floorceil.html
Cyb
Posts: 912
Joined: Tue Jul 15, 2003 5:12 pm

Post by Cyb »

Code: Select all

/////////////////////////////////////////
// start my [less] big elevator script //
/////////////////////////////////////////

int eleopen, doorbroken, elemove;

script 1 (void)
{
   eleopen = 1;                // door is open
   polyobj_move(1,5,128,5);    // door open
   polyobj_move(2,5,0,55);     // door open
   light_fade (13,128,90);     // light up the room
   light_fade (17,120,90);     // light up the room
   light_fade (20,120,90);     // light up the room
   if(doorbroken) thing_activate(19);
   delay(const:256);
   polyobj_move(1,5,0,5);      // door close
   polyobj_move(2,5,128,55);   // door open
   light_fade (13,100,90);     // light down the room
   light_fade (17,100,90);     // light down the room
   light_fade (20,96,90);      // light down the room

   if (!doorbroken) // inital elevator open
   {
      delay(const:40);
      thingsound(18,"explode",100);  // door blowing up
      delay(const:30);
      thing_activate(19);            // sparks
      doorbroken = 1;                // door is now broken
      delay(const:15);
      eleopen = 0;                   // door is closed
      delay(const:15);
      thing_deactivate(19);          // reset sparks
      delay(const:1);
      thing_activate(19);            // more sparks
   }
   else                    // otherwise the door is broken
   {
      thing_activate(19);  // sparks
      delay(const:90);
      eleopen = 0;         // door is closed
   }
}

script 2 (void) // inside elevator doors
{
   if (!elemove && !eleopen)
      acs_execute(1,0,0,0,0);                  // open the doors
   else if (elemove)
      print(s:"Warning: Elevator in Motion");  // wait you idiot
}

script 3 (void) // elevator
{
   if (eleopen)
      print(s:"Warning: Doors Open");   // wait you idiot
   else
   {
      print(s:"Going down!");
      thingsound(22,"elebell",100);     // elevator bell
      elemove = 1;                      // elevator is moving
      floor_lowerbyvalue(21,10,750);    // move the elevator
      ceiling_lowerbyvalue(21,10,750);  // move the elevator
      light_fade (28,32,512);           // light down the window
      delay(const:512);
      radius_Quake (5,15,0,64,22);      // elevator stops
      thingsound(22,"elebell",100);     // elevator bell
      elemove = 0;                      // elevator not moving
   }
}
should work
User avatar
randomlag
Posts: 405
Joined: Thu Jul 17, 2003 10:10 pm

Post by randomlag »

Just something different

Code: Select all

int eleopen; 
int doorbroken; 
int elemove; 

//==========================================================
// common functions
//==========================================================

function void lightfade(void)
{

     light_fade (13,100,90);        // light down the room 
     light_fade (17,100,90);        // light down the room 
     light_fade (20,96,90);         // light down the room 
}

function void dooropen1(void)
{    
     eleopen = 1;                    // door is open 
    
     polyobj_move(1,5,128,55);       // door open 
     polyobj_move(2,5,0,55);         // door open
        
     lightfade();                    // light down the room
}

function void dooropen2(void)
{
      delay(const:256); 

      polyobj_move(1,5,0,5);         // door close 
      polyobj_move(2,5,128,55);      // door open 

      lightfade();                   // light down the room
}

//==========================================================
//      script 1 + description
//==========================================================

script 1 (void) 
{ 

   if (doorbroken)                   // if the door is broken 
   { 
      dooropen1()                    // doors

      thing_activate(19);            // sparks 

      dooropen2()                    // doors light down

      thing_activate(19);            // sparks 
      delay(const:90); 

      eleopen = 0;                   // door is closed 
   } 
   else
   // inital elevator open 
   { 
      dooropen2()                    // doors light down

      delay(const:40); 
      thingsound(18,"explode",100);  // door blowing up 
      delay(const:30); 

      thing_activate(19);            // sparks 
      doorbroken = 1;                // door is now broken 

      delay(const:15); 

      eleopen = 0;                   // door is closed 

      delay(const:15); 

      thing_deactivate(19);          // reset sparks 
      delay(const:1); 
      thing_activate(19);            // more sparks 
   } 

} 

//==========================================================
//      script 2 + description
//==========================================================

script 2 (void) // inside elevator doors 
{ 
   if (!elemove 
   &&  !eleopen) 
   { 
       acs_execute(1,0,0,0,0);                  // open the doors 
   } 

   if (elemove)
   { 
      print(s:"Warning: Elevator in Motion");   // wait you idiot 
   } 

} 

//==========================================================
//      script 3 + description
//==========================================================

script 3 (void) // elevator 
{ 
   if (elopen)
   { 
      print(s:"Warning: Doors Open");           // wait you idiot 
   }
   else 
   { 
      print(s:"Going down!"); 
      thingsound(22,"elebell",100);             // elevator bell 

      elemove = 1;                              // elevator is moving 
      
      floor_lowerbyvalue(21,10,750);            // move the elevator 
      ceiling_lowerbyvalue(21,10,750);          // move the elevator 
      light_fade (28,32,512);                   // light down the window 
      delay(const:512); 
      radius_Quake (5,15,0,64,22);              // elevator stops 
      thingsound(22,"elebell",100);             // elevator bell 
      
      elemove = 0;                              // elevator not moving 
   } 
}
User avatar
Hirogen2
Posts: 2033
Joined: Sat Jul 19, 2003 6:15 am
Operating System Version (Optional): Tumbleweed x64
Graphics Processor: Intel with Vulkan/Metal Support
Location: Central Germany

Post by Hirogen2 »

Cool, I did not knew such "functions" were possible. It is definitely time to update ACS docs.
Still consider the elevator functions.
BTW, You forgot some semicolons, randomlag.
User avatar
randomlag
Posts: 405
Joined: Thu Jul 17, 2003 10:10 pm

Post by randomlag »

But I'm consistent 8-)

Oops, I forgot about the delay stuff not allowed inside a function. Always helps to actually compile :oops:

Return to “Editing (Archive)”