In Lua, using a Boolean variable from another script in the same project ends with a null value error


This code is for a modding engine, Unitale base on Unity Written in Lua

So I am trying to use a Boolean Variable in my script poseur.lua, so when certain conditions are met so I can pass it to the other script encounter.lua, where a engine Predefined functions is being uses to make actions happens base on the occurring moment.

I tried to read the engine documentation multiple times, follow the exact syntax of Lua's fonction like GetVar(), SetVar(), SetGobal(),GetGlobal(). Searching and google thing about the Language, post on the subreddit and Game Exchange and tried to solve it by myself for hours... I just can't do it and I can't understand why ?

I will show parts of my codes for each.


    -- A basic monster script skeleton you can copy and modify for your own creations.

    comments = {"Smells like the work\rof an enemy stand.",
            "Nidhogg_Warrior is posing like his\rlife depends on it.",
            "Nidhogg_Warrior's limbs shouldn't\rbe moving in this way."}
    commands = {"GREET", "JUMP", "FLIRT", "CRINGE"}

    EndDialougue = {" ! !  !","ouiii"}

    sprite = "poseur" --Always PNG. Extension is added automatically.

    name = "Nidhogg_Warrior"

    hp = 99
    atk = 1
    def = 1
    check = "The Nidhogg_Warrior is\rsearching for the Nidhogg"
    dialogbubble = "rightlarge" -- See documentation for what bubbles you have available.
    canspare = false
    cancheck = true
    GreetCounter = 5
    Berserk = false


    -- A basic encounter script skeleton you can copy and modify for your own creations.

    encountertext = "Nidhogg_Warrior is\rrunning frantically"
    nextwaves = {"bullettest_chaserorb"}
    wavetimer = 5.0
    arenasize = {155, 130}
    music = "musAncientGuardian"
    enemies = {"poseur"}
    enemypositions = {{0, 0}}

    -- A custom list with attacks to choose from.
    -- Actual selection happens in EnemyDialogueEnding().
    -- Put here in case you want to use it.
    possible_attacks = {"bullettest_bouncy", "bullettest_chaserorb", "bullettest_touhou"}

    function EncounterStarting()
        -- If you want to change the game state immediately, this is the place. = 20
        Player.hp = 99 = "Teemies"

Thank you for reading.

The answer to my problem was to use SetGobal(), GetGobal().

For some reasons my previous attempt to simply use SetGobal()Resulted in nil value despite writing it like that SetGobal("Berserk",true) gave me a nill value error, as soon as I launch the game.

But I still used them wrong. First I needed to put it SetGobal() at the end of the condition instead of at the start of the the poseur.lua script because the change of value... for some reasons was being overwritten by it first installment.

And to test the variable in the function in my encounter.lua, I needed to write it like that

       function EnemyDialogueStarting()
            -- Good location for setting monster dialogue depending on how the battle is going.

        if GetGlobal("Jimmies") == true then


Also any tips an suggestions are still welcome !