Page 1 of 1

Two-level elevator: demons in my script, I'm stumped

Posted: Wed Jan 21, 2004 4:08 am
by BirdsofaFeather
I'm having a little trouble with this elevator of mine (yes, an elevator, very sorry). It's only a two level elevator, very simple. I have three triggers total for it: one inside the elevator that extends to cover both the top and bottom switches inside the elevator shaft (warehouse_elevator_trigger) and then two more triggers, one at the top outside the elevator and one at the bottom outside, both for calling the elevator (warehouse_elevator_trigger_top and warehouse_elevator_trigger_bottom respectively). When the elevator is moved to the bottom (warepos 0) whether by the trigger inside or if it is called there by the bottom switch, I don't have a problem. The elevator stops, the doors open and stay open, and it waits for another trigger. But if it gets moved to the top (warepos 1) it reaches the top, opens the doors up there, and quickly closes them and moves back down to the bottom as if I had initiated the warehouse_elevator_movedown method immediatly after reaching the top. Here's my code, I just can't figure out what's wrong:

Code: Select all

//---------------------------
// Warehouse Elevator
//---------------------------

warehouse_elevator_prep:

	$warehouse_elevator moveto $warehouse_top
	$warehouse_elevator speed 80
	$warehouse_elevator move
	$warehouse_door_bottom_right speed 48
	$warehouse_door_bottom_left speed 48
	$warehouse_door_top_right speed 48
	$warehouse_door_top_left speed 48
	$warehouse_door_top_right moveNorth 38
	$warehouse_door_top_left moveSouth 38
	$warehouse_door_top_right move
	$warehouse_door_top_left move

	level.warepos = 1

	thread warehouse_elevator_standby //run inner trigger thread
	thread warehouse_elevator_triggertop_standby //run top outer trigger thread
	thread warehouse_elevator_triggerbottom_standby //run bottom outer trigger thread

warehouse_elevator_standby:

	$warehouse_elevator_trigger triggerable
	$warehouse_elevator_trigger waittill trigger

	if (level.warepos == 0)
	{
		goto warehouse_elevator_moveup
		end
	}
	else if (level.warepos == 1)
	{
		goto warehouse_elevator_movedown
		end
	}

end

warehouse_elevator_triggertop_standby:

	$warehouse_elevator_trigger_top triggerable
	$warehouse_elevator_trigger_top waittill trigger

	if (level.warepos == 0)
	{
		goto warehouse_elevator_moveup
		end
	}
	else
	{
		goto warehouse_elevator_triggertop_standby
	}

end

warehouse_elevator_triggerbottom_standby:

	$warehouse_elevator_trigger_bottom triggerable
	$warehouse_elevator_trigger_bottom waittill trigger

	if (level.warepos == 1)
	{
		goto warehouse_elevator_movedown
		end
	}
	else
	{
		goto warehouse_elevator_triggerbottom_standby
	}

end

warehouse_elevator_moveup:

	$warehouse_elevator_trigger nottriggerable
	$warehouse_elevator_trigger_top nottriggerable
	$warehouse_elevator_trigger_bottom nottriggerable

	$warehouse_elevator moveto $warehouse_top

	$warehouse_door_bottom_right moveNorth 38 //close bottom doors
	$warehouse_door_bottom_left moveSouth 38
	$warehouse_elevator playsound door_metal_close_move
	$warehouse_door_bottom_right move
	$warehouse_door_bottom_left waitmove
	$warehouse_elevator playsound door_metal_close_stop	
	
	wait .5

	$warehouse_elevator loopsound lighthouse_run
	$warehouse_elevator waitmove
	$warehouse_elevator loopsound lighthouse_run wait

	$warehouse_door_top_right moveNorth 38 //open top doors
	$warehouse_door_top_left moveSouth 38
	$warehouse_elevator playsound door_metal_open_move
	$warehouse_door_top_right move
	$warehouse_door_top_left waitmove
	$warehouse_elevator playsound door_metal_open_stop

	level.warepos = 1

	thread warehouse_elevator_standby
	thread warehouse_elevator_triggertop_standby
	thread warehouse_elevator_triggerbottom_standby


warehouse_elevator_movedown:

	$warehouse_elevator_trigger nottriggerable
	$warehouse_elevator_trigger_top nottriggerable
	$warehouse_elevator_trigger_bottom nottriggerable
		
	$warehouse_elevator moveto $warehouse_bottom

	$warehouse_door_top_right moveSouth 38 //close top doors
	$warehouse_door_top_left moveNorth 38
	$warehouse_elevator playsound door_metal_close_move
	$warehouse_door_top_right move
	$warehouse_door_top_left waitmove
	$warehouse_elevator playsound door_metal_close_stop

	wait .5

	$warehouse_elevator loopsound lighthouse_run
	$warehouse_elevator waitmove
	$warehouse_elevator loopsound lighthouse_run wait

	$warehouse_door_bottom_right moveSouth 38 //open bottom doors
	$warehouse_door_bottom_left moveNorth 38
	$warehouse_elevator playsound door_metal_open_move
	$warehouse_door_bottom_right move
	$warehouse_door_bottom_left waitmove
	$warehouse_elevator playsound door_metal_open_stop	

	level.warepos = 0

	thread warehouse_elevator_standby
	thread warehouse_elevator_triggertop_standby
	thread warehouse_elevator_triggerbottom_standby

end	
Thanks in advance to anyone who can figure out this demon in my code.

Posted: Wed Jan 21, 2004 4:12 am
by omniscient
i would strongly recommend not using the goto command. im not a scripting guru, but i know goto is the devil.

Posted: Wed Jan 21, 2004 4:15 am
by BirdsofaFeather
like....just use the thread command instead of goto? eh...I can try it...won't hurt that's for sure

Posted: Wed Jan 21, 2004 4:24 am
by digitac
first .

close

Code: Select all

warehouse_elevator_prep: 
it doesn't got an end

if u use goto it will cut of your script and continues on the thread your starting
so better is to use thread

I recommend to add a main: thread so your script has a default thread

any questions ask them

DigitaC

Posted: Wed Jan 21, 2004 4:24 am
by omniscient
hehe, we need some of the other people on, im not that smart (i also havent read through it yet, im kinda tired) tomorrow if u dont have an answer ill look at it and see if i notcie anyhting.

Posted: Wed Jan 21, 2004 11:43 am
by Bjarne BZR
I'd redo the structure like this ( using the warehouse_elevator_standby method as an example ) :

Code: Select all

warehouse_elevator_standby:
   $warehouse_elevator_trigger triggerable
   while(true) // Forever
   {
      $warehouse_elevator_trigger waittill trigger
      $warehouse_elevator_trigger nottriggerable
      if (level.warepos == 0)
      {
         waitthread warehouse_elevator_moveup
      }
      else
      {
         if (level.warepos == 1)
         {
            waitthread warehouse_elevator_movedown
         }
      }
      $warehouse_elevator_trigger triggerable
   }
end 
This way the trigger cant start multiple paralell movement threads, and is only triggerable again once the elevator has completed its movement.

Your strange behaviour is probably because you have no idea what so ever what your script is actually doing. So remove the goto's and replace them with thread or waitthread.

I also suggest using a 3:rd elevator state (level.warepos = -1) to signal to the elevator system that the elevator is busy moving.

Posted: Wed Jan 21, 2004 11:47 am
by Bjarne BZR
BTW: Is there a need for an elevator construction basics thread?
People seem to have big probs with elevators in general...

Posted: Wed Jan 21, 2004 7:27 pm
by BirdsofaFeather
thanks for the help guys, i've tried all the things you mentioned, unfortunatly I can't see if they work because my map simply will not load my script for some reason. The script is simply not loaded every time I start the map, so I have to figure that out first I guess.

Re: Two-level elevator: demons in my script, I'm stumped

Posted: Wed Jan 21, 2004 7:43 pm
by nuggets
BirdsofaFeather wrote:I'm having a little trouble with this elevator of mine (yes, an elevator, very sorry). It's only a two level elevator, very simple. I have three triggers total for it: one inside the elevator that extends to cover both the top and bottom switches inside the elevator shaft (warehouse_elevator_trigger) and then two more triggers, one at the top outside the elevator and one at the bottom outside, both for calling the elevator (warehouse_elevator_trigger_top and warehouse_elevator_trigger_bottom respectively). When the elevator is moved to the bottom (warepos 0) whether by the trigger inside or if it is called there by the bottom switch, I don't have a problem. The elevator stops, the doors open and stay open, and it waits for another trigger. But if it gets moved to the top (warepos 1) it reaches the top, opens the doors up there, and quickly closes them and moves back down to the bottom as if I had initiated the warehouse_elevator_movedown method immediatly after reaching the top. Here's my code, I just can't figure out what's wrong:

Code: Select all

//---------------------------
// Warehouse Elevator
//---------------------------

warehouse_elevator_prep:

	$warehouse_elevator moveto $warehouse_top
	$warehouse_elevator speed 80
	$warehouse_elevator move
	$warehouse_door_bottom_right speed 48
	$warehouse_door_bottom_left speed 48
	$warehouse_door_top_right speed 48
	$warehouse_door_top_left speed 48
	$warehouse_door_top_right moveNorth 38
	$warehouse_door_top_left moveSouth 38
	$warehouse_door_top_right move
	$warehouse_door_top_left move

	level.warepos = 1

	thread warehouse_elevator_standby //run inner trigger thread
	thread warehouse_elevator_triggertop_standby //run top outer trigger thread
	thread warehouse_elevator_triggerbottom_standby //run bottom outer trigger thread

end //one here thanks to digitac
warehouse_elevator_standby:

	$warehouse_elevator_trigger triggerable
	$warehouse_elevator_trigger waittill trigger

	if (level.warepos == 0)
	{
		goto warehouse_elevator_moveup
		end
	}
	else if (level.warepos == 1)
	{
		goto warehouse_elevator_movedown
		end
	}

end

warehouse_elevator_triggertop_standby:

	$warehouse_elevator_trigger_top triggerable
	$warehouse_elevator_trigger_top waittill trigger

	if (level.warepos == 0)
	{
		goto warehouse_elevator_moveup
		end
	}
	else
	{
		goto warehouse_elevator_triggertop_standby
	}

end

warehouse_elevator_triggerbottom_standby:

	$warehouse_elevator_trigger_bottom triggerable
	$warehouse_elevator_trigger_bottom waittill trigger

	if (level.warepos == 1)
	{
		goto warehouse_elevator_movedown
		end
	}
	else
	{
		goto warehouse_elevator_triggerbottom_standby
	}

end

warehouse_elevator_moveup:

	$warehouse_elevator_trigger nottriggerable
	$warehouse_elevator_trigger_top nottriggerable
	$warehouse_elevator_trigger_bottom nottriggerable

	$warehouse_elevator moveto $warehouse_top

	$warehouse_door_bottom_right moveNorth 38 //close bottom doors
	$warehouse_door_bottom_left moveSouth 38
	$warehouse_elevator playsound door_metal_close_move
	$warehouse_door_bottom_right move
	$warehouse_door_bottom_left waitmove
	$warehouse_elevator playsound door_metal_close_stop	
	
	wait .5

	$warehouse_elevator loopsound lighthouse_run
	$warehouse_elevator waitmove
	$warehouse_elevator loopsound lighthouse_run wait

	$warehouse_door_top_right moveNorth 38 //open top doors
	$warehouse_door_top_left moveSouth 38
	$warehouse_elevator playsound door_metal_open_move
	$warehouse_door_top_right move
	$warehouse_door_top_left waitmove
	$warehouse_elevator playsound door_metal_open_stop

	level.warepos = 1

	thread warehouse_elevator_standby
	thread warehouse_elevator_triggertop_standby
	thread warehouse_elevator_triggerbottom_standby

end //and this one will make it stop going straight down

warehouse_elevator_movedown:

	$warehouse_elevator_trigger nottriggerable
	$warehouse_elevator_trigger_top nottriggerable
	$warehouse_elevator_trigger_bottom nottriggerable
		
	$warehouse_elevator moveto $warehouse_bottom

	$warehouse_door_top_right moveSouth 38 //close top doors
	$warehouse_door_top_left moveNorth 38
	$warehouse_elevator playsound door_metal_close_move
	$warehouse_door_top_right move
	$warehouse_door_top_left waitmove
	$warehouse_elevator playsound door_metal_close_stop

	wait .5

	$warehouse_elevator loopsound lighthouse_run
	$warehouse_elevator waitmove
	$warehouse_elevator loopsound lighthouse_run wait

	$warehouse_door_bottom_right moveSouth 38 //open bottom doors
	$warehouse_door_bottom_left moveNorth 38
	$warehouse_elevator playsound door_metal_open_move
	$warehouse_door_bottom_right move
	$warehouse_door_bottom_left waitmove
	$warehouse_elevator playsound door_metal_open_stop	

	level.warepos = 0

	thread warehouse_elevator_standby
	thread warehouse_elevator_triggertop_standby
	thread warehouse_elevator_triggerbottom_standby

end	
Thanks in advance to anyone who can figure out this demon in my code.
lol, you have initiated it to come back down straight after it has gone up, you need an end where demonstrated, if your still having problems with your script have a look in the console, it'll tell you where your going wrong

post the whole of your script if that doesn't help

Posted: Wed Jan 21, 2004 7:53 pm
by BirdsofaFeather
lol, you have initiated it to come back down straight after it has gone up, you need an end where demonstrated, if your still having problems with your script have a look in the console, it'll tell you where your going wrong
OMG!! I can't believe that's what's been bugging me for this long! That was it, unbelievable! I checked that code at least 20 times, and I never even noticed that was missing. Thanks man, maybe you can figure out my rocket problem too (I'll post that in a new topic).