 # Main SiteForum Index

• September 16, 2019, 08:25:39 PM • Welcome, Guest Event Branching Tutorial  (Read 833 times)
Pages: French Maid
Xifanie (Webmistress) [Posts: 4462]
##### Event Branching Tutorial
« on: May 10, 2017, 07:06:01 PM »
Today we'll tackle branches and jumps, but we will not really use those names as while they correctly describe what the instructions do, we'll look at each individual instruction one by one.

All of these instructions have one single parameter, which is a ForwardTarget ID or a BackTarget ID.
Jumping Forward
JumpForwardIfNot(xJF)
Jumps to ForwardTarget if Variable 0x0000 is equal to 0. Otherwise simply keeps advancing.
Must be placed before ForwardTarget!
JumpForward(xJF)
Jumps to ForwardTarget.
Must be placed before ForwardTarget!
ForwardTarget(xJF)
Target Destination of JumpForwardIfNot/JumpForward.
Must be placed after JumpForwardIfNot/JumpForward!
Jumping Backward
JumpBack(xJB)
Jumps back to BackTarget.
Must be placed after BackTarget!
BackTarget(xJB)
Target Destination of JumpBack.
Must be placed before JumpBack!

Targets
Forward Targets and Back Targets are essentially the same thing, but they are limited to their current subset of event instructions. Thus ForwardTarget 0x00 and BackTarget 0x00 use different memory allocations and are separate. Only a Forward Instruction can use a Forward Target, and only a Back Instruction can use a Back Target
• A ForwardTarget may only be placed after a Forward Instruction, and can be reused. This means that you may use ForwardTarget 0x00 as often as you want with simple instructions.
• A BackTarget may only be placed before a Back Instruction and cannot be reused.

Conditions
EQ() Equal
Variable 0x0000 = If ( Variable 0x0000 == Variable 0x0001 )
NEQ() Not Equal
Variable 0x0000 = If ( Variable 0x0000 != Variable 0x0001 )
LT() Less Than
Variable 0x0000 = If ( Variable 0x0000 < Variable 0x0001 )
GT() Greater Than
Variable 0x0000 = If ( Variable 0x0000 > Variable 0x0001 )
LTE() Less Than or Equal
Variable 0x0000 = If ( Variable 0x0000 <= Variable 0x0001 )
GTE() Greater Than or Equal
Variable 0x0000 = If ( Variable 0x0000 >= Variable 0x0001 )

Examples:
Note that in each of these examples, I used Target 0xFF to make it easier to remember where the end of the conditions section is.
Player has at least 1 gold. (Aeris Flower Event)
 //Set Variable 0x0000 to War Funds (Variable 0x002C)ZERO(x0000)ADDVar(x0000,x002C)//Set Comparison Value to 0x0001ZERO(x0001)ADD(x0001,x0001)//Greater Than or Equal ComparisonGTE()JumpForwardIfNot(x00)//What Happens if the player has at least 1 gilJumpForward(xFF)ForwardTarget(x00)//ELSE (i.e. What happens if the player has 0 gil)ForwardTarget(xFF)//Resume the rest of the event

Dialogue Selection (3 options)
 //Set Variable 0x0001 to the Selected Option in Dialog (0x0018)ZERO(x0001)ADDVar(x0001,x0018)//Set Variable 0x0000 to Option #1 (0x0000)ZERO(x0000)//Equal ComparisonEQ()JumpForwardIfNot(x00)//What happens if the first option was selectedJumpForward(xFF)ForwardTarget(x00)//Set Variable x0000 to Option #2//Note that 0x0000 will be 0x0000 anyway because of EQ() returning false, so we don't have to ZERO the variableADD(x0000,x0001)//Equal ComparisonEQ()JumpForwardIfNot(x01)//What happens if the second option was selectedJumpForward(xFF)ForwardTarget(x01)//ELSE (i.e. What happens if the third option was selected)ForwardTarget(xFF)//Resume the rest of the event

Page Selection (8 options)
 //Set Variable 0x0001 to the Selected Option in Dialog (0x0018)ZERO(x0001)ADDVar(x0001,x0018)//Set Variable 0x0000 to Option #1 (0x0000)ZERO(x0000)//Equal ComparisonEQ()JumpForwardIfNot(x00)//What happens if the first option was selectedJumpForward(xFF)ForwardTarget(x00)//Set Variable x0000 to Option #2//Note that 0x0000 will be 0x0000 anyway because of EQ() returning false, so we don't have to ZERO the variableADD(x0000,x0001)//Equal ComparisonEQ()JumpForwardIfNot(x01)//What happens if the second option was selectedJumpForward(xFF)ForwardTarget(x01)//Set Variable x0000 to Option #3ADD(x0000,x0002)//Equal ComparisonEQ()JumpForwardIfNot(x02)//What happens if the third option was selectedJumpForward(xFF)ForwardTarget(x02)//Set Variable x0000 to Option #4ADD(x0000,x0003)//Equal ComparisonEQ()JumpForwardIfNot(x03)//What happens if the fourth option was selectedJumpForward(xFF)ForwardTarget(x03)//Set Variable x0000 to Option #5ADD(x0000,x0004)//Equal ComparisonEQ()JumpForwardIfNot(x04)//What happens if the fifth option was selectedJumpForward(xFF)ForwardTarget(x04)//Set Variable x0000 to Option #6ADD(x0000,x0005)//Equal ComparisonEQ()JumpForwardIfNot(x05)//What happens if the sixth option was selectedJumpForward(xFF)ForwardTarget(x05)//Set Variable x0000 to Option #7ADD(x0000,x0006)//Equal ComparisonEQ()JumpForwardIfNot(x06)//What happens if the seventh option was selectedJumpForward(xFF)ForwardTarget(x06)//ELSE (i.e. What happens if the eighth option was selected)ForwardTarget(xFF)//Resume the rest of the event

Loop a Yes/No option dialogue 5 times
 //Set Variable 0x0002 to 5 (Loop Count)ZERO(x0002)ADD(x0002,x0005)//Reset Variables 0x0003 and 0x0004 as they will be used for our YES and NO countersZERO(0x0003)ZERO(0x0004)//Set Back TargetBackTarget(x00)//Display a Yes/No Dialogue (fill it yourself)DisplayMessage(x10,xDT,xMSG#,xID,x00,xPR,+XXXXX,+YYYYY,+ARPOS,xOT)WaitForInstruction(x01)//Set Variable 0x0001 to the Selected Option in Dialog (0x0018)ZERO(x0001)ADDVar(x0001,x0018)//Set Variable 0x0000 to Option #1 (0x0000)ZERO(x0000)//Equal ComparisonEQ()JumpForwardIfNot(x00)//Add +1 to the YES counterADD(x0003,x0001)JumpForward(xFF)ForwardTarget(x00)//Add +1 to the NO counterADD(x0004,x0001)ForwardTarget(xFF)//Reduce Loop Counter by 1SUB(x0002,x0001)//Set Variable 0x0000 to our Loop CounterZERO(x0000)ADDVar(x0000,x0002)//Set Variable 0x0001 to 0 for comparisonZERO(x0001)//Greater Than (Zero) ComparisonGT()//Jump Back if Loop Counter > 0; otherwise keep goingJumpForwardIfNot(xFE)//LoopJumpBack(x00)ForwardTarget(xFE)//Resume the rest of the event
« Last Edit: May 10, 2017, 08:42:26 PM by Xifanie »
• Modding version: PSX
•  Anything is possible as long as it is within the hardware's limits. (ie. disc space, RAM, Video RAM, processor, etc.)
<R999> My target market is not FFT mod players
<Raijinili> remember that? it was awful
Pages: