Thread Tools Display Modes
05/07/15, 05:07 AM   #1
Leju
AddOn Author - Click to view addons
Join Date: Apr 2015
Posts: 8
Lua - Get Directory xxx.lua

I am creating an addon and I'm stuck on one thing, when I use the following line in the Lua
local dir = debug.getinfo(1).source
it returns me the following result
@game:/EsoUI/lang/br_pregame.lua
and what I need to know and exactly the way it is "@game:" by chance would have the game function something that could help me?

Last edited by Leju : 05/07/15 at 05:25 AM.
  Reply With Quote
05/07/15, 05:45 AM   #2
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,989
Do you need to know the value "behind" @game (the directory of the game, like c:\programs\elder scrolls online\game), or do you just need the string @game: separated from the total string @game:/EsoUI/lang/br_pregame.lua
?
  Reply With Quote
05/07/15, 06:14 AM   #3
Leju
AddOn Author - Click to view addons
Join Date: Apr 2015
Posts: 8
I need this path
C:\Users\<<User Name>>\Documents\Elder Scrolls Online\live\AddOns
but it returns me just that damn @game: if it be fixed would be no problem but the user can change the default folder for documents elsewhere, which is why I'm behind a solution covering the maximum possible scenarios.
  Reply With Quote
05/07/15, 06:28 AM   #4
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,989
Ok. it looks for me that @game: is used internally the elder scrolls online as a "constant" for the correct game path.
Aren't you able to just use this @game: value too in your addon then?

Other question:
What do you need the path for? As far as I know the ESO lua codes do not support any I/O part of normal lua so I don't think there is any possibility to get the correct file path.

I'm not at my gaming pc at the moment so I cannot check this:
Maybe the path is saved somewhere in the C:\Users\<<User Name>>\Documents\Elder Scrolls Online\live<eu>\UserSettings.txt" file as a full string? Did you look into this file already?
There you would be able to read the settings information then to parse the string.

Check this thread how to read the settings:
http://www.esoui.com/forums/showthre...light=settings

EDIT:

Just found an example of usersettings.txt online and it seems it is using the same game:/ value there....
Code:
SET LanguageDirectory.2 "game:/EsoUI"
So parsing this won't help, too bad.
But I still think you could just use the same constant "game:/" in your addon too then.



Question:
What do you want to achieve? Maybe there is a nother way to do this by using your addons base path and using ../../ to go up some folders etc. ?

Last edited by Baertram : 05/07/15 at 06:33 AM.
  Reply With Quote
05/07/15, 07:03 AM   #5
Leju
AddOn Author - Click to view addons
Join Date: Apr 2015
Posts: 8
Okay let by XD

1 Agree with you on the part of "@game:" being a constant and used internally and has tried to use only "@game:," and it did not work!

2. Support for I/O is partially right, I found that if you run Lua codes while the game loads you fully supports the Lua commands, my intention and create a kind of eastereag in the game where you will see a splash screen with the name of the translator for PT-BR version (original game splash will be kept)

3. I checked for UserSettings.txt could be something to help me, but unfortunately found nothing!

4. I tried using the "@game:" direct or checking through various existing functions in ESO to return me something but all in vain!

5 I wanted to create a splash screen to show the employees to translate just about everything already iss ready so lacking copy the .bik video Addon folder for "The Elder Scrolls Online\depot\Video" discover what is ready below

Lua Code:
  1. function file_exists(name)
  2.    local f=io.open(name,"r")
  3.    if f~=nil then io.close(f) return true else return false end
  4. end
  5.  
  6. function PTBR_LoadMedia(event, name)
  7.     local dir_MidiaBR = "TraducaoPortuguesBR/Media/BR_logo.bik"
  8.     if file_exists(dir_MidiaBR) then
  9.         os.remove("../../depot/Video/BR_logo.bik")
  10.         os.rename(dir_MidiaBR, "../../depot/Video/BR_logo.bik")
  11.     end
  12.  
  13.     PlayVideo("Video/BR_logo.bik", false, 1)
  14.     os.remove("controlador.dat")
  15. end
  16.  
  17. GetEventManager():RegisterForEvent("TraducaoPortuguesBR", EVENT_ADD_ON_LOADED, PTBR_LoadMedia)

Just missing the place that is the video that will be placed in the variable "dir_MidiaBR" to put the full path
  • D:/Documentos/Elder Scrolls Online/live/AddOns/TraducaoPortuguesBR/Media/BR_logo.bik
It works just right
  Reply With Quote
05/07/15, 07:08 AM   #6
Leju
AddOn Author - Click to view addons
Join Date: Apr 2015
Posts: 8
because to use playVideo is required is within the video "The Elder Scrolls Online/depot/Video" already tried running other folders simply does not.
  Reply With Quote
05/07/15, 07:21 AM   #7
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,989
Oh, ok.
I think I can't help you here then as I don#t know any function or method to get the correct ESO game directory...

But another point:
EVENT_ADD_ON_LOADED is called for EVERY addon that a user got installed and activated! So your source code in function PTBR_LoadMedia(event, name) will be currently executed for EACH addon

You need to check the addon name at the beginning of the addon so it will only be called for YOUR addon.
YOUR addon is the name of the addon in the manifest TXT file. I think it is "TraducaoPortuguesBR" for your addon?

Lua Code:
  1. --Global variable in your addon
  2. local myAddon = {
  3.  "name" = "TraducaoPortuguesBR",
  4.  "version" = ...,
  5. "otherInfo" = ...,
  6. }
  7.  
  8. PTBR_LoadMedia(event, name)
  9. --Check for the own addon name and abort here if other addon is loaded
  10. if name ~= myAddon.name then return end
  11.  
  12. ...
  13. end
  Reply With Quote
05/07/15, 07:35 AM   #8
Leju
AddOn Author - Click to view addons
Join Date: Apr 2015
Posts: 8
Here it is a little different because it is an addon ESO that uses this .lua so I did a workaround to avoid this error, not only posted the code to workaround to become clean but below is the complete code.

Lua Code:
  1. function file_exists(name)
  2.    local f=io.open(name,"r")
  3.    if f~=nil then io.close(f) return true else return false end
  4. end
  5.  
  6. function PTBR_LoadMedia(event, name) -- Initialize Player group events
  7.     if file_exists("controlador.dat") then
  8.    
  9.         local dir_MidiaBR = "TraducaoPortuguesBR/Media/BR_logo.bik"
  10.         if file_exists(dir_MidiaBR) then
  11.             os.remove("../../depot/Video/BR_logo.bik")
  12.             os.rename(dir_MidiaBR, "../../depot/Video/BR_logo.bik")
  13.         end
  14.    
  15.         PlayVideo("Video/BR_logo.bik", false, 1)
  16.         os.remove("controlador.dat")
  17.     end
  18. end
  19.  
  20. if not file_exists("controlador.dat") then
  21.     GetEventManager():RegisterForEvent("TraducaoPortuguesBR", EVENT_ADD_ON_LOADED, PTBR_LoadMedia)
  22.    
  23.     arquivo = assert(io.open("controlador.dat", "w"), "ops one error!");
  24.     arquivo:write("Blocks Logo crazy Executions Translation\n");
  25.     arquivo:flush()
  26.     io.close(arquivo);
  27. end

Still thank all the help
  Reply With Quote
05/07/15, 10:03 AM   #9
Ayantir
 
Ayantir's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2014
Posts: 1,019
If you want to play your video, just remove one of zos bik files by yours.

http://wiki.esoui.com/API

Standard Lua libraries Included

basic library (only functions listed above)
string
math


Please note that the following libraries are NOT included :

Coroutine Manipulation
Input and Output (io)
Operating System (OS)

Debug







Lua Code:
  1. function file_exists(name)
  2.    local f=io.open(name,"r") -- nil error
  3.    if f~=nil then io.close(f) return true else return false end
  4. end
  5.  
  6. function PTBR_LoadMedia(event, name) -- Initialize Player group events
  7.     if file_exists("controlador.dat") then  -- nil error
  8.    
  9.         local dir_MidiaBR = "TraducaoPortuguesBR/Media/BR_logo.bik"
  10.         if file_exists(dir_MidiaBR) then -- nil error
  11.             os.remove("../../depot/Video/BR_logo.bik") -- nil error
  12.             os.rename(dir_MidiaBR, "../../depot/Video/BR_logo.bik") -- nil error
  13.         end
  14.    
  15.         PlayVideo("Video/BR_logo.bik", false, 1) -- does this function exists ?
  16.         os.remove("controlador.dat") -- nil error
  17.     end
  18. end
  19.  
  20. if not file_exists("controlador.dat") then -- nil error
  21.     GetEventManager():RegisterForEvent("TraducaoPortuguesBR", EVENT_ADD_ON_LOADED, PTBR_LoadMedia)
  22.    
  23.     arquivo = assert(io.open("controlador.dat", "w"), "ops one error!");  -- nil error
  24.     arquivo:write("Blocks Logo crazy Executions Translation\n"); -- nil error
  25.     arquivo:flush() -- nil error
  26.     io.close(arquivo); -- nil error
  27. end

Last edited by Ayantir : 05/07/15 at 10:08 AM.
  Reply With Quote
05/07/15, 10:12 AM   #10
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,989
f you want to play your video, just remove one of zos bik files by yours.
I guess:
The patching system will most likely detect a wrong CRC then and will update/download the .bik video file again then :-(
  Reply With Quote
05/07/15, 10:37 AM   #11
Ayantir
 
Ayantir's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2014
Posts: 1,019
Portuguese / Russian / Spanish / etc are accustomed to not using patcher. they only launch them tuesday , when patches goes live.
  Reply With Quote

ESOUI » Developer Discussions » Lua/XML Help » Lua - Get Directory xxx.lua


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