• Welcome to Final Fantasy Hacktics. Please login or sign up.
 

Event Branching Tutorial

Started by Xifanie, May 10, 2017, 03:06:01 pm

Xifanie

May 10, 2017, 03:06:01 pm Last Edit: May 10, 2017, 04:42:26 pm by Xifanie
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
[indent=2]
JumpForwardIfNot(xJF)
[indent=2]
Jumps to ForwardTarget if Variable 0x0000 is equal to 0. Otherwise simply keeps advancing.
Must be placed before ForwardTarget!
[/indent]
JumpForward(xJF)
[indent=2]
Jumps to ForwardTarget.
Must be placed before ForwardTarget!
[/indent]
ForwardTarget(xJF)
[indent=2]
Target Destination of JumpForwardIfNot/JumpForward.
Must be placed after JumpForwardIfNot/JumpForward!
[/indent]
[/indent]
Jumping Backward
[indent=2]
JumpBack(xJB)
[indent=2]
Jumps back to BackTarget.
Must be placed after BackTarget!
[/indent]
BackTarget(xJB)
[indent=2]
Target Destination of JumpBack.
Must be placed before JumpBack!
[/indent]
[/indent]

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
[indent=2]
EQ() Equal
[indent=2]Variable 0x0000 = If ( Variable 0x0000 == Variable 0x0001 ) [/indent]
NEQ() Not Equal
[indent=2]Variable 0x0000 = If ( Variable 0x0000 != Variable 0x0001 ) [/indent]
LT() Less Than
[indent=2]Variable 0x0000 = If ( Variable 0x0000 < Variable 0x0001 ) [/indent]
GT() Greater Than
[indent=2]Variable 0x0000 = If ( Variable 0x0000 > Variable 0x0001 )[/indent]
LTE() Less Than or Equal
[indent=2]Variable 0x0000 = If ( Variable 0x0000 <= Variable 0x0001 )[/indent]
GTE() Greater Than or Equal
[indent=2]Variable 0x0000 = If ( Variable 0x0000 >= Variable 0x0001 ) [/indent]
[/indent]

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.
[indent=2]
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 0x0001
ZERO(x0001)
ADD(x0001,x0001)

//Greater Than or Equal Comparison
GTE()
JumpForwardIfNot(x00)

//What Happens if the player has at least 1 gil

JumpForward(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 Comparison
EQ()
JumpForwardIfNot(x00)

//What happens if the first option was selected

JumpForward(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 variable
ADD(x0000,x0001)

//Equal Comparison
EQ()
JumpForwardIfNot(x01)

//What happens if the second option was selected

JumpForward(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 Comparison
EQ()
JumpForwardIfNot(x00)

//What happens if the first option was selected

JumpForward(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 variable
ADD(x0000,x0001)

//Equal Comparison
EQ()
JumpForwardIfNot(x01)

//What happens if the second option was selected

JumpForward(xFF)
ForwardTarget(x01)
//Set Variable x0000 to Option #3
ADD(x0000,x0002)

//Equal Comparison
EQ()
JumpForwardIfNot(x02)

//What happens if the third option was selected

JumpForward(xFF)
ForwardTarget(x02)
//Set Variable x0000 to Option #4
ADD(x0000,x0003)

//Equal Comparison
EQ()
JumpForwardIfNot(x03)

//What happens if the fourth option was selected

JumpForward(xFF)
ForwardTarget(x03)
//Set Variable x0000 to Option #5
ADD(x0000,x0004)
//Equal Comparison
EQ()
JumpForwardIfNot(x04)

//What happens if the fifth option was selected

JumpForward(xFF)
ForwardTarget(x04)
//Set Variable x0000 to Option #6
ADD(x0000,x0005)

//Equal Comparison
EQ()
JumpForwardIfNot(x05)

//What happens if the sixth option was selected

JumpForward(xFF)
ForwardTarget(x05)
//Set Variable x0000 to Option #7
ADD(x0000,x0006)

//Equal Comparison
EQ()
JumpForwardIfNot(x06)

//What happens if the seventh option was selected

JumpForward(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 counters
ZERO(0x0003)
ZERO(0x0004)

//Set Back Target
BackTarget(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 Comparison
EQ()

JumpForwardIfNot(x00)

//Add +1 to the YES counter
ADD(x0003,x0001)

JumpForward(xFF)
ForwardTarget(x00)

//Add +1 to the NO counter
ADD(x0004,x0001)

ForwardTarget(xFF)

//Reduce Loop Counter by 1
SUB(x0002,x0001)

//Set Variable 0x0000 to our Loop Counter
ZERO(x0000)
ADDVar(x0000,x0002)

//Set Variable 0x0001 to 0 for comparison
ZERO(x0001)

//Greater Than (Zero) Comparison
GT()
//Jump Back if Loop Counter > 0; otherwise keep going
JumpForwardIfNot(xFE)

//Loop
JumpBack(x00)

ForwardTarget(xFE)

//Resume the rest of the event

[/indent]
  • Modding version: PSX
Love what you're seeing? https://supportus.ffhacktics.com/ 💜 it's really appreciated

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