local variable and global variable works for any players
the difference is, global variables can be used in any function, in any trigger
local variables on the other hand can only work within the function they are in.
Example:
JASS:
//this is vJass addition to the trigger editor, if you dont have JNGP you cant do this
globals
unit u = null
endglobals
function AA takes nothing returns nothing
set u = gg_unit_Hmkg_0001 // mountain king, only works if he is first unit placed on the map
endfunction
function AB takes nothing returns nothing
call KillUnit(u)
endfunction
will work properly. However doing
JASS:
function AA takes nothing returns nothing
set locint = 1
endfunction
function AB takes nothing returns nothing
local integer locint = 0
endfunction
will pop up error, undeclared variable locint
Basically you can only use locals within that instance but they are far more used then globals because if you do this
JASS:
globals
integer int = 0
endglobals
function AA takes nothing returns nothing
set int = int + 1
call BJDebugMsg(I2S(int))
call TriggerSleepAction(1.0) //Wait 1.00 seconds in GUI
set int = int + 1
call BJDebugMsg(I2S(int))
endfunction
//the below INITa is just to make this work
function INITa takes nothing returns nothing
local trigger t = CreateTrigger()
call TriggerRegisterTimerEvent(t, 0.5, true)
call TriggerAddAction(t, function AA)
set t = null
endfunction
what this does is on init it creates Timer - Every 0.5 seconds and registers it to the function and that function runs every 0.5 seconds(hope you understand so far)
now what this does, is set the integer to +1 every time it runs and additionally after 1 second. But this is not MUI, thats why you need in GUI unit indexing to make spells MUI.
On the other hand, locals are not only within the function but is like array, you can have how many globals with same name working at the same time, they are bound to the thread meaning that when you run it it initializes those values and then takes values of current thread
The example above will display 1, 2, 3, 4, 5, 6, 7... or something but what if you want to end on 2 everytime. You do
JASS:
function AA takes nothing returns nothing
local integer i = 0
set i = i+1
call BJDebugMsg(I2S(i))
call TriggerSleepAction(1.0)
set i = i+1
call BJDebugMsg(I2S(i))
endfunction
//and the second function or anything else
this will however display 1, 2, 1, 2, 1, 2, 1, 2, or something like that
However remember that if you have global with name i(if you do it trough the Variable Editor it will automatically have prefix udg_variableName) and you have local with i then if you do set i = i + 1 you will work with the local not global
Hope you understand, if not let me know Ill try to describe it slower