How to use global variables?

I have 2 functions which interacts with unit.

1 function is summoning. How can I store summoned unit into a global variable?

in the 2nd function i want to do some actions via global variables

possible?

Comments

  • edited July 2015 Posts: 1

    It is possible, of course. You need to declare them outside the function and assign them nil. Then, you can modify them in every event and its content will be kept. For instance:

    summon = nil
    function GameMode:OnSomethingHappens()
        summon = "A summoned unit (actually a string)"
    end
    DebugPrint(summon)
    

    This will print to the console A summoned unit (actually a string) if OnSomethingHappens is triggered.