WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   AddOn Help/Support (https://www.wowinterface.com/forums/forumdisplay.php?f=3)
-   -   Can It be possible to edit namespace (https://www.wowinterface.com/forums/showthread.php?t=56657)

Gilsuk 09-11-18 12:08 AM

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...

Rilgamon 09-11-18 12:25 AM

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.

Fizzlemizz 09-11-18 01:18 AM

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.

MunkDev 09-11-18 10:25 AM

Quote:

Originally Posted by Gilsuk (Post 330055)
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.


All times are GMT -6. The time now is 08:45 AM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI