Followed the instructions for the multiple floor elevator, but once in game the elevator goes to the second floor and back to the first floor without stopping. I named all my stuff according to the tut. Here is the script:
main:
exec global/ai.scr
exec global/cardgame.scr
exec global/door_locked.scr::lock
level waittill prespawn
$down_switch bind $elevator_cab // binds switches to elevator
$up_switch bind $elevator_cab
$down_trigger bind $down_switch// binds triggers to switches
$up_trigger bind $up_switch
//$elevator_cab movedown 8 //This was throwing my cab off
//$elevator_cab time 0
//$elevator_cab move
$elevator_cab speed 64 // sets speed to 64 units/s
level.elepos = 1 // starts on floor 1
$elevator_cab2 speed 64
level.script = "maps/untitled.scr"
level waittill spawn
$player item weapons/colt45.tik
$player useweaponclass pistol
thread elevator_prep
end
elevator_prep:
thread movedown
thread moveup
end
movedown:
$down_trigger waittill trigger// waits until the player triggers the trigger
if (level.elepos == 1)// if the elevator is on floor 1 then end because it cant go down anymore
end
$up_trigger nottriggerable // turns off the triggers until the elevator is done moving
$down_trigger nottriggerable
local.position = level.elepos // sets another variable
$down_switch anim turn //turns the switch
$elevator_cab loopsound lighthouse_run // makes some noise
$elevator_cab moveto $("floor" + (local.position - 1)) // move to the floor below the one that it is on
$elevator_cab waitmove
$elevator_cab stoploopsound
$down_switch anim idle
level.elepos--
$down_trigger triggerable // turns the triggers back on
$up_trigger triggerable
goto elevator_prep
end
moveup:
$up_trigger waittill trigger
if (level.elepos == 5)// if the elevator is at the top then end because it cant go up anymore
end
$down_trigger nottriggerable
$up_trigger nottriggerable
local.position = level.elepos
$up_switch anim turn
$elevator_cab loopsound lighthouse_run
$elevator_cab moveto $("floor" + (local.position + 1))
$elevator_cab waitmove
$elevator_cab stoploopsound
$up_switch anim idle
level.elepos++
$up_trigger triggerable
$down_trigger triggerable
goto elevator_prep
end
I have not read Erick's turtorial but I can tell by the scripting what it must be . That type of script has been around for a while . Elevators can be done many ways . Any way looking at your scirpt I would say it has to be a problem with either the targetnames or the triggers or both . Most likely the triggers .
$("floor" + (local.position - 1))
That suggests that you have an entity with a targetname of $floor1 for floor 1 and named like that up to the top floor so if the top floor is 5 then one called $floor5 . The script says
$elevator_cab moveto $("floor" + (local.position - 1)) // move to the floor below the one that it is on
$elevator_cab waitmove
At this point the triggers are suppose to be nottriggerable providing you have given them the correct targetnames .
$up_trigger nottriggerable // turns off the triggers until the elevator is done moving
$down_trigger nottriggerable
The script is paused until the elevator reaches the next floor because of the waitmove statement . Ok so the only way that the down thread can run is if the trigger is triggered . The triggers are not turned back on untill the elevevator is where it is suppose to be so the question is what is triggering the trigger ? Check where you have placed the triggers and if you used the right type of trigger . I assume the script asks you to use trigger uses which can only be triggered by you pressing the use key .
Ok I just spotted another major flaw . When the down or up thread runs there is at the end of the thread this line .
goto elevator_prep
The elevator_prep thread starts two threads
elevator_prep:
thread movedown
thread moveup
end
but what if say you moved up but not down rerunning the elevator_prep thread starts two new threads now you have two movedown threads waiting for you to use the down trigger . If you move up five times you have 5 movedown thread waiting to run . It is bad practice to use goto to make a loop in the first place . That is sloppy scripting . Use while loops instead or at the very least have the movedown thread goto the movedown thread not the elevator_prep thread . To use a while loop do it like this and only call the thread once .
movedown:
while(1)
{
$down_trigger waittill trigger// waits until the player triggers the trigger
if (level.elepos > 1)// if the elevator is on a floor higher than 1
{
$up_trigger nottriggerable // turns off the triggers until the elevator is done moving
$down_trigger nottriggerable
local.position = level.elepos // sets another variable
$down_switch anim turn //turns the switch
$elevator_cab loopsound lighthouse_run // makes some noise
$elevator_cab moveto $("floor" + (local.position - 1)) // move to the floor below the one that it is on
$elevator_cab waitmove
$elevator_cab stoploopsound
$down_switch anim idle
level.elepos--
}
$down_trigger triggerable // turns the triggers back on
$up_trigger triggerable
}
end
Just as a test, I took out the "thread movedown" out of the equation and now the elevator moves up to each of the 5 floors.
What I want to happen is if I am on floor 2, I want the option of going to floor 3 or 1 (etc for the other floors). Now that I took the movedown out, I can't get back down a floor.
I tried yours bdbodger, but could't get the elevator going.
movedown:
$down_trigger waittill trigger// waits until the player triggers the trigger
if (level.elepos == 1)// if the elevator is on floor 1 then end because it cant go down anymore
end
$up_trigger nottriggerable // turns off the triggers until the elevator is done moving
$down_trigger nottriggerable
local.position = level.elepos // sets another variable
$down_switch anim turn //turns the switch
$elevator_cab loopsound lighthouse_run // makes some noise
$elevator_cab moveto $("floor" + (local.position - 1)) // move to the floor below the one that it is on
$elevator_cab waitmove
$elevator_cab stoploopsound
$down_switch anim idle
level.elepos--
$down_trigger triggerable // turns the triggers back on
$up_trigger triggerable
end
moveup:
$up_trigger waittill trigger
if (level.elepos == 5)// if the elevator is at the top then end because it cant go up anymore
end
$down_trigger nottriggerable
$up_trigger nottriggerable
local.position = level.elepos
$up_switch anim turn
$elevator_cab loopsound lighthouse_run
$elevator_cab moveto $("floor" + (local.position + 1))
$elevator_cab waitmove
$elevator_cab stoploopsound
$up_switch anim idle
level.elepos++
$up_trigger triggerable
$down_trigger triggerable
end
erick wrote:@bdbodger You can have two threads running at the same time. Another way is to make setthreads on the triggers. One with movedown and one with moveup.
Yes but in this case both threads are the same thread and you don't want to have two threads . Setthread is good to use you have done it right by turning off both trigger to stop the setthread from creating two threads running at the same time . Only one thing though
$down_trigger waittill trigger
you don't usually use waittill trigger in a thread started by setthread . I mean the thread is started when the trigger is triggered so what exactly are you waiting for ? What reason would you have to pause the thread from running untill the trigger is triggered again ? waittill trigger is usually used in a looping thread . The thread loops once and then waits to be triggered again then runs through the loop again then waits again . That makes sence right . waittill trigger is a wait for the trigger to be triggered again unless you have a reason for the thread to wait then you don't need to use it .