Thread Tools Display Modes
09-11-18, 12:08 AM   #1
Gilsuk
A Murloc Raider
Join Date: Sep 2018
Posts: 4
Can It be possible to edit namespace

example.toc
Code:
## Title: example
## Interface: 80000
## blah~

exp1.lua
exp2.lua
exp1.lua
Lua Code:
  1. local _, ns = ...
  2. ns["player"].name = UnitName("Player")

exp2.lua
Lua Code:
  1. local _, ns = ...
  2. print(ns["player"].name) -- It works!
  3. ns["player"].name = "Wrynn" -- It also works!
  4. ns["player"].class = "WARRIOR" -- It doesn't work. It fires nil value error

exp2.lua can access and edit the value that was already defined in exp1.lua.
but exp2.lua can't define a new variable into the table 'ns'

Other addons can do this like It was nothing. so I don't know what are the problems with my codes...
  Reply With Quote
09-11-18, 12:25 AM   #2
Rilgamon
Premium Member
 
Rilgamon's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Sep 2009
Posts: 822
Without your actual not working code it's difficult to guess.
Perhaps the value you try to store is not yet available at the time you try to store it. Delay it until player enters the world event.
__________________
The cataclysm broke the world ... and the pandas could not fix it!
  Reply With Quote
09-11-18, 01:18 AM   #3
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,871
You need to create the "player" entry as a table

Lua Code:
  1. local _, ns = ...
  2. ns["player"] = {}
  3. ns["player"].name = UnitName("player")
Then in exp2.lua
Lua Code:
  1. ns["player"].class = "WARRIOR"

You can also get rid of the [""]
Lua Code:
  1. ns.player = {}
  2. ns.player.name = UnitName("player")

Then again, I could be about to learn something new.
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 09-11-18 at 01:26 AM.
  Reply With Quote
09-11-18, 10:25 AM   #4
MunkDev
A Scalebane Royal Guard
 
MunkDev's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2015
Posts: 431
Originally Posted by Gilsuk View Post
Other addons can do this like It was nothing. so I don't know what are the problems with my codes...
Show your actual code, not this hypothetical nonsense where you missed the part that causes your problems.
__________________
  Reply With Quote

WoWInterface » AddOns, Compilations, Macros » AddOn Help/Support » Can It be possible to edit namespace

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off