View Single Post
Old 22-04-11, 12:29   #98
Raymond
Member
 
Joined: Nov 2007
Posts: 1,689
Default

This is a response on a question by Jixan in another thread:
"Also, I want to do a switch puzzle in which 5 switches have to be pressed in order to open a door, but they have to be pressed in a certain order...is that possible in the editor? I don't mind if it needs scripting. "
First of all you need to know the basics of triggergroups (see NG_Center reference) and variables (see especially Paolones docu in his variable project).

A.
In a first part I`ll explain, how to trigger/"antitrigger" something with a switch, what´s not about a object/a flipmap. Only for this two situations the normal hardcoded switch-setup works. But if you want to use other action triggers or flipeffects in such a pair, you need to achieve it in another way. This is also needed to answer the question of Jixan later on, but the setup can be used for any pair of triggers.

The setup is explained for a pull switch to move a box two tiles back and forth

1. We need to normal switch trigger for the switch, because this trigger causes Lara to use the switch again (move it up again after it´s pulled down).
2. To trigger the movement of the box with the switch we use the animations of Lara at the switch as a condition in a Triggergroup (TG). So if Lara executes the pull down animation 63, the movemenet of the box in the one direction is triggered and if Lara executes the move up-animation 64, the backward motion is triggered.
The TG would look like this:
Triggergroup=9,$8000, 63, $1E,$5000, 35, $721,$8000+TGROUP_ELSE, 64, $1E,$5000, 35, $723
This TG reads like this:
If Lara executes animation 63, then mobve moveable 35 2 sectors eastward, else if Lara executes animation 64, then move moveable 35 2 sectors westward.
You add your wished action triggers or flipeffects in this TG of course. For other switch types you would have to adjust the used conditions.
This TG you trigger then on the same tile as the switch trigger with the flipeffect:
TriggerGroup. Perform <&>TriggerGroup from script.dat in (E)way
; <&> : TriggerGroup= 9
; (E) : Mutiple performing (to use when in TriggerGroup there is some condition)

B.
Now to the original question of Jixan. We need to make a sign for the engine, so that it knows, that the switches are pulled in the right order. This sign is, that a certain bit in a certain variable is set, if a switch is pulled. So if a switch is pulled, then we use a flipeffect of this type to set a bit ( here the bit 0 in variavle Local byte Alpha1):
Variables. Numeric. Set in <&>Variable the (E)bit
; <&> : Local Byte Alfa1 (LBA1)
; (E) : Bit 0 ($00000001 ; 1)
For our five switches we use the 5 bits 0 to 4 of LBA1. We check the bits of this variable then with this kind of condition:
Local Byte Alfa1
; <&> : Variables. The <#>Numeric Variable has the (E)Bit set
; (E) : Bit 0 ($00000001 ; 1).
So that the switches must be pulled in the right order these conditions must be fulfilled for example for the third switch:
Switch 1 an switch 2 must have been pulled and therefore bit 0 and bit 1 of LBA1 must be already set as a condition. Then bit 2 can be set with this switch.
So our TG 9 (see A) for switch 3 would look like this:

Triggergroup=9,$8000, 63, $1E,$8000, 64, $2C,$8000, 64, $12C,$2000, 234, $240,$8000+TGROUP_ELSE, 64, $1E,$2000, 235, $240,$2000, 235, $340,$2000, 235, $440

; Exporting: CONDITION(44:60) for PARAMETER(64)
; <#> : Local Byte Alfa1
; <&> : Variables. The <#>Numeric Variable has the (E)Bit set
; (E) : Bit 0 ($00000001 ; 1)
; Values to add in script command: $8000, 64, $2C


; Exporting: CONDITION(44:60) for PARAMETER(64)
; <#> : Local Byte Alfa1
; <&> : Variables. The <#>Numeric Variable has the (E)Bit set
; (E) : Bit 1 ($00000002 ; 2)
; Values to add in script command: $8000, 64, $12C

; Exporting: TRIGGER(576:0) for FLIPEFFECT(234)
; <#> : Variables. Numeric. Set in <&>Variable the (E)bit
; <&> : Local Byte Alfa1
; (E) : Bit 2 ($00000004 ; 4)
; Values to add in script command: $2000, 234, $240

; Exporting: TRIGGER(576:0) for FLIPEFFECT(235)
; <#> : Variables. Numeric. Clear in <&>Variable the (E)bit
; <&> : Local Byte Alfa1
; (E) : Bit 2 ($00000004 ; 4)
; Values to add in script command: $2000, 235, $240 (and also $2000, 235, $340 for clearing bit 3 and $2000, 235, $440 for clearing bit 4)

As you see, if the switch 3 is moved up, the bit 2 in LBA 1 is cleared again. To maintain the right order of pulling the switches, also the bits have to be cleared, which are set in the later switches. So here also bits 3 and 4 must be cleared again.
With the same principle you built the TG´s for the other switches.

So if all 5 switches are pulled in the correct order the five bits 0-4 in LBA1 are set and only then.
Finally you script a Globaltrigger, which triggers the wished event (open the door 12 here for instance), if all these five bits are set:
Globaltrigger= 1,IGNORE, GT_CONDITION_GROUP,IGNORE, 1,2,3
Triggergroup=1,$8000, 64, $2C,$8000, 64, $12C,$8000, 64, $22C,$8000, 64, $32C,$8000, 64, $42C (check, if the five bits are set)
Triggergroup=2,$5000, 12, $11A (open door 12)
Triggergroup=3,$5000, 12, $1A (close door 12)

So door 12 opens, if all five switches are pulled in the right order and only then.

Last edited by Raymond; 22-04-11 at 15:36.
Raymond is offline