View Single Post
12-17-12, 12:08 AM   #1
gmarco
An Onyxian Warder
 
gmarco's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2009
Posts: 362
Calling a local function from another local funtion

Hi all,

I'd like to ask why a code like this will produce exit with an error like unable to find global b():

Lua Code:
  1. local function a()
  2. -- code
  3.  
  4. end
  5.  
  6.  
  7. local function b()
  8. -- code
  9.  
  10. end
  11.  
  12.  
  13. local function c()
  14. -- code
  15.  
  16. b()
  17.  
  18. end

This because if I change my functions to local: RemGank_Validate_DB, RemGank_Check_Player, RemGank_Add_Player and RemGank_Record_Player

this doesn't work anymore:


Lua Code:
  1. -- code
  2.  
  3. local function RemGank_Record_Player(name, note)   
  4.  
  5.     if note == nil or note == "" then  note = default_note end
  6.  
  7.     RemGank_Validate_DB(name)
  8.  
  9.     RemGankDB[name]["name"] = name:lower()
  10.     RemGankDB[name]["desc"] = string.sub(note,1,25)
  11.     RemGankDB[name]["lastloc"] = GetZoneText() .. "/" .. GetSubZoneText() .. " - " .. date("%d.%m.%Y %H:%M:%S")
  12.     RemGankDB[name]["nrkill"] = ( RemGankDB[name]["nrkill"] + 1 )  
  13.    
  14.     print(string_format("%s: adding %s [ %s ] [ kills: %i ] ", prgname, name, note, RemGankDB[name]["nrkill"]))
  15.    
  16. end
  17.  
  18. local function RemGank_Validate_DB(name)
  19.     RemGankDB[name] = RemGankDB[name] or {}
  20.     RemGankDB[name]["name"] = RemGankDB[name]["name"] or {}
  21.     RemGankDB[name]["desc"] = RemGankDB[name]["desc"] or {}
  22.     RemGankDB[name]["lastloc"] = RemGankDB[name]["lastloc"] or {}
  23.     RemGankDB[name]["nrkill"] = RemGankDB[name]["nrkill"] or 0
  24. end
  25.  
  26. -- code


If I declare them not local everything works.

I'll attach the full code if someone wants to check it.

As usual thanks in advance to everyone.
Attached Files
File Type: zip Remgank-v0.9.zip (4.2 KB, 360 views)
__________________
This is Unix-Land. In quiet nights, you can hear the Windows machines reboot.
  Reply With Quote