Modding Docs
  • 👋Welcome
  • 💡Getting Started
    • 🎩Persona 5 Royal (PC) Mod Support
      • 🚧Manually Installing PC Mods
    • 🎩Persona 5 Royal (Switch) Mod Support
      • 🎩P5R Mods on Switch Console (CFW)
      • 🎩P5R Switch Mods on PC Emulator (Yuzu/RyujiNX)
      • 🚧Manually Installing Switch Mods
    • 🎩Persona 5 Royal (PS4) Mod Support
    • 🎩Persona 5 (PS3) Mod Support
    • 📺Persona 4 Golden (PC) Mod Support
    • 📺Persona 4 Golden (PSVita) Mod Support
    • 📺Persona 4 (PS2) Mod Support
    • 🌘Persona 3 Portable (PSP) Mod Support
    • 🌘Persona 3 FES (PS2) Mod Support
  • 📄Scripting
    • Intro to Scripting
      • Resources
    • AtlusScriptCompiler
      • Run via Commandline
        • Decompile
        • Compile
        • Batch Dump .FLOW/.MSG
      • Run via GUI
    • Flowscript
      • Procedures
      • Variables
      • Scope
      • Arrays
      • Enums
      • Loops
      • Conditionals
      • Functions
      • Importing Files
      • Menus
    • Messagescript
      • Markup
      • Message Variables
    • Library Functions
      • Persona 5
      • Persona 5 EX
      • Persona 5 Royal
      • Persona 4
      • Persona 4 Golden
      • Persona 3
      • Persona 3 FES
      • Persona 3 Portable
      • SMT III: Nocturne
      • Digital Devil Saga
Powered by GitBook
On this page
  • Variable Scopes
  • Local
  • Global
  • Static
  • Const
  • Out Variables
  • Conclusion

Was this helpful?

  1. Scripting
  2. Flowscript

Scope

global var number = 24;

PreviousVariablesNextArrays

Last updated 3 years ago

Was this helpful?

A Scope is an area of a program where an object is recognized. Procedures have their own scope. To the rest of the script, any inside a do not exist.

For instance, if you declare a variable in , you will not be able to use it from any other . Also, unless you assign the value to a variable of greater scope, when the ends, the value will be discarded.

// variableName only exists within Main() since it's local
void Main() {
    var variableName = 25;
    // no other procedure will be able to recognize 'variableName'
    AnotherProcedure();
}

void AnotherProcedure(int variableTest ) {
    // This would cause an ERROR.
    var test = variableName;
}

However, can be given different scopes.

Variable Scopes

Name

Description

local

global

Persists across all scripts while the game is running.

static

const

Must be initialized with a value. Cannot be changed afterward.

Local

// variableName only exists within Main() since it's local
void Main() {
    var variableName = 25;
    // but since AnotherProcedure() takes an int... 
    AnotherProcedure( variableName );
}

// ... we can make a copy of its value with a different name
void AnotherProcedure(int variableTest ) {
    // This would create a new local variable equal to 25
    var test = variableTest;
}

Global

A practical use case would be keeping track of the last entered number after closing and re-opening a menu.

// globalTest exists for as long as the game is running, even after Main()
global int globalTest = 50;

void Main() {
    globalTest = globalTest + 30;
    AnotherProcedure();
}

void AnotherProcedure() {
    // This would create a new local variable equal to 80
    var test = globalTest;
}

Static

static int staticNumber;

void Main() {
    // the first static int will be 10 higher every time the script is run
    staticNumber = staticNumber + 10;
}

Const

const int constantNumber = 99;

void Main() {
    constantNumber = 0;
    // test would still equal 99
    var test = constantNumber;
}

Out Variables

void Main() {
    OutTest( out x, out y );
    var x + y; // result equaling 35
}

void OutTest( out int x, out int y )
{
    x = 5;
    y = 30;
}

If this seems confusing, don't worry about it for now. You will not have to do this very often.

Conclusion

Default scope for .

Value persists per while the script is running.

In the example above, the value of variableName cannot be accessed by OtherProcedure() since it only exists to , where it was defined.

However, you can still pass it by reference to use it for math or in another.

global are persist even after a script is done executing. They stay in memory while the game is running, but aren't saved to your save file.

static can be declared but not initialized outside of a . These keep their value between executions while the game is running, but aren't saved to your save file.

const are constant, so their value cannot be changed after they're initialized. This can be useful for referring to values you know in advance by a convenient name.

Aside from or using global, static or const, you can also use out variables to pass values between , even void. It would look like this:

As you can see, the were already in the parameters of OutTest() using the out keyword. After being initialized with a value, the x and y variables are then passed to Main(), once again using the out keyword.

Now you should have a grasp on how data is stored and handled by scripts. You're ready to learn more advanced usages of these techniques, such as and .

📄
variables
declared
procedure
Main()
procedure
procedure
variables
Main()
initializing a variable
procedure
variables
variables
procedure
variables
passing by reference
procedures
variables
declared
Arrays
Loops
Arrays
variables
procedure