simplify a script

Post your scripting questions / solutions here

Moderator: Moderators

fuhrer
Captain
Posts: 253
Joined: Sun Mar 14, 2004 3:36 am

simplify a script

Post by fuhrer »

i have a lift with 4 floors, trigger use on each floor and 4 triggers inside to move the lift to the desired floor using waypoints. All triggers are using setthreads.

is there a way i can maybe put all of them into one thread, so if i had 15 floors i wouldnt need 30 threads?

Code: Select all

//--------------//
// Lift Buttons //
//--------------//

1st:
	$lift moveto $floor_1	// sets the lifts destination
	$lift move		// moves the lift to that destination
end


2nd:
	$lift moveto $floor_2
	$lift move
end


3rd:
	$lift moveto $floor_3
	$lift move
end


4th:
	$lift moveto $floor_4
	$lift move
end


//--------------//
// Call Buttons //
//--------------//

call_1:
	$lift moveto $floor_1
	$lift move
end


call_2:
	$lift moveto $floor_2
	$lift move
end


call_3:
	$lift moveto $floor_3
	$lift move
end


call_4:
	$lift moveto $floor_4
	$lift move
end



end
jv_map
Site Admin
Posts: 6521
Joined: Tue Sep 03, 2002 2:53 pm
Location: The Netherlands
Contact:

Post by jv_map »

Make it like this:

Code: Select all

callthread local.num:
   $lift moveto $("floor_" + local.num)
   $lift move
end
Then you can e.g. simply do:

thread callthread 3

or

thread callthread 4

etc
Image
fuhrer
Captain
Posts: 253
Joined: Sun Mar 14, 2004 3:36 am

Post by fuhrer »

im unfamiliar with callthread, could ya explain a little at what that is doing?
User avatar
wacko
Field Marshal
Posts: 2085
Joined: Fri Jul 05, 2002 8:42 pm
Location: Germany

Post by wacko »

callthread is just a name, u could as well call it something else :wink:
fuhrer
Captain
Posts: 253
Joined: Sun Mar 14, 2004 3:36 am

Post by fuhrer »

ok so what is the local.num doing, i cant see how its working :?
Combat Kirby
Lance Corporal
Posts: 18
Joined: Wed Mar 03, 2004 7:50 pm

Post by Combat Kirby »

thread callthread 3

local.num will = 3



thread callthread 4

local.num will = 4


local.num will pickup the parameter that is sent to it when a value is to the right of the calling thread.
fuhrer
Captain
Posts: 253
Joined: Sun Mar 14, 2004 3:36 am

Post by fuhrer »

i think i get it but how do i write that in the script?
nuggets
General
Posts: 1006
Joined: Fri Feb 28, 2003 2:57 am
Location: U-england-K (england in the UK) :P
Contact:

Post by nuggets »

there's no point in having two seperate threads for each button inside and outside the elevator that call it to the same floor.

1st:
$lift moveto $floor_1 // sets the lifts destination
$lift move // moves the lift to that destination
end

and

call_1:
$lift moveto $floor_1
$lift move
end

they do the same thing, so have just one setthread

key: setthread
value: call

also if you were to add the floor to each trigger
key: #floor
value: 1 //change respectively 2, 3, 4

you could simplify your script to be no more than

call:
$lift moveto $("floor_" + self.number)
$lift move
end
hope this helps, prob not cos it's all foreign 2 me :-/
fuhrer
Captain
Posts: 253
Joined: Sun Mar 14, 2004 3:36 am

Post by fuhrer »

so i leave everything as it is now in the map file, cept make all triggers

setthread
call

and have the targetnames on each floor the same i.e.

inner trigger floor 1:

key #floor
value 1

outer trigger floor1:

key #floor
value 1

ah!! is self.number looking at which trigger is pressed and takin the value property??? but then would self.number have to be self.value?

so pressing the inner or outer button for floor 4 it would take the value of 4.

but then would self.number have to be self.value? and would it need to be set in prespawn?


Also....

I now have

Code: Select all

$1st_doors doopen
how do i make the script close the right set of doors?
User avatar
wacko
Field Marshal
Posts: 2085
Joined: Fri Jul 05, 2002 8:42 pm
Location: Germany

Post by wacko »

nuggets wrote:also if you were to add the floor to each trigger
key: #floor
value: 1 //change respectively 2, 3, 4

you could simplify your script to be no more than

call:
$lift moveto $("floor_" + self.number)
$lift move
end
atleast me, i don't get this: why is the value given to something called #floor and then taken from something called number
fuhrer
Captain
Posts: 253
Joined: Sun Mar 14, 2004 3:36 am

Post by fuhrer »

my triggers only work if i unbind them from the lift...

seems using self. wont work if the trigger callin the thread is bound to something :?

also i was trying to be clever with the door closing by using a variable...

Code: Select all

call: 
	
	thread triggers_off
	level.doors doclose
	$lift moveto $("floor_" + self.floor)
	$lift loopsound lift_sound
	$lift waitmove			
	$lift loopsound lift_sound wait
	$("doors_" + self.floor) doopen
	$("doors_" + self.floor) playsound lift_gate
	level.doors = $("doors_" + self.floor)
	wait 1.5
	thread triggers_on
end
now the doors dont close, is there a way i can make that so that the doors on the floor that the lift was last at will close when the lift is called to another floor. (simple way)


AND, is there a command to turn off all the triggers at once, instead of having them turn off in another thread i.e. all triggers nottriggerable
nuggets
General
Posts: 1006
Joined: Fri Feb 28, 2003 2:57 am
Location: U-england-K (england in the UK) :P
Contact:

Post by nuggets »

lmao. oops and oversight on my part :P

use self.floor not self.number :oops:
hope this helps, prob not cos it's all foreign 2 me :-/
User avatar
tltrude
Chuck Norris
Posts: 4774
Joined: Sun Jul 07, 2002 4:03 am
Location: Oklahoma, USA
Contact:

Post by tltrude »

The first "level.doors doclose" does not know what the value of "level.doors" is, so it will be "NIL".
Tom Trude,

Image
fuhrer
Captain
Posts: 253
Joined: Sun Mar 14, 2004 3:36 am

Post by fuhrer »

hm, so that would work?
nuggets
General
Posts: 1006
Joined: Fri Feb 28, 2003 2:57 am
Location: U-england-K (england in the UK) :P
Contact:

Post by nuggets »

post the whole script you've got, i'd imagine that you've set level.doors when your binding the buttons to the elevator
hope this helps, prob not cos it's all foreign 2 me :-/
Post Reply