Thanks for your reply Sheeo.
My level of LUA is somewhere low...but how to deal with global variable in lua between files ?
I made a simple test to explain myself :
imagine I want to store the incremential unit damage hits in a global variable then link the variable to the name of the unit info windows.This the variable _G.Damagehits = 0 declaration in unit.lua. I use the _G prefix in lua to force the same environnements between lua files.
- Code: Select all
#****************************************************************************
#**
#** File : /lua/unit.lua
#** Author(s): John Comes, David Tomandl, Gordon Duclos
#**
#** Summary : The Unit lua module
#**
#** Copyright © 2005 Gas Powered Games, Inc. All rights reserved.
#****************************************************************************
local Entity = import('/lua/sim/Entity.lua').Entity
local explosion = import('/lua/defaultexplosions.lua')
local EffectTemplate = import('/lua/EffectTemplates.lua')
local EffectUtilities = import('/lua/EffectUtilities.lua')
local Game = import('/lua/game.lua')
local utilities = import('/lua/utilities.lua')
local Shield = import('/lua/shield.lua').Shield
local UnitShield = import('/lua/shield.lua').UnitShield
local AntiArtilleryShield = import('/lua/shield.lua').AntiArtilleryShield
local Buff = import('/lua/sim/buff.lua')
local AIUtils = import('/lua/ai/aiutilities.lua')
local Blueprints = import('/lua/system/blueprints.lua')
-- my code
_G.damagehits = 0
-- end of my code
Then i go to the DoTakeDamage function still in unit.lua to increment the variable. I put a log to watch the variable content during execution.
- Code: Select all
DoTakeDamage = function(self, instigator, amount, vector, damageType)
local preAdjHealth = self:GetHealth()
-- my code
_G.Damagehits = _G.Damagehits + 1
LOG('_G.Damagehits variable in function DOTAKEDAMAGE :', _G.Damagehits)
-- end of my code
self:AdjustHealth(instigator, -amount)
Then i go to unitview.lua file. I link the _G.Damagehits variable to the unit name.
- Code: Select all
if info.customName then
-- my code
controls.name:SetText(LOCF('%d: %s', _G.Damagehits, description))
-- end of my code
elseif bp.General.UnitName then
controls.name:SetText(LOCF('%s: %s', bp.General.UnitName, description))
else
controls.name:SetText(LOCF('%s', description))
end
I run the mod. I run the F9 debug windows. I start a ACU battle. And i watch the results
The ACU unitview windows name stay at 0 during all the test, just the _G.damagehits declaration value.
In the unit DOtakeDamage LOG test, it says that the _G.Damagehits increments well.
So my question is :
Why did the _G.Damagehits global variable increment in the function DoTakeDamage in unit.lua but says at the defaut value of 0 in unitview.lua ?Each time i select my ACU the view function refresh but the _G.Damagehits stays at '0'.
Why this variable doesn't refresh between lua files ? What i am missing ? Any Idea ?