Quantcast Read in text file - WoWInterface
Thread Tools Display Modes
04-12-18, 07:08 PM   #1
Christavious
A Murloc Raider
Join Date: Apr 2018
Posts: 6
Read in text file

Is there a way to set a variable from a text file?

local text = io.open("file.text", "r")
print(text)

Text file contents:
This is a test.

When I load the game, "This is a test." should show, but I get nothing. Any ideas?
  Reply With Quote
04-12-18, 07:14 PM   #2
Ammako
A Frostmaul Preserver
AddOn Author - Click to view addons
Join Date: Jun 2016
Posts: 256
You can't read or write from files beyond saved variables in WoW api.
You'll have to use saved variables and perhaps edit those externally before loading the game if that's your goal. They are in plain text and easily editable by other programs, as long as you respect the right syntax.

Note that saved variables cannot be edited and read in real time outside of the game itself performing actions on them, and the changes made by the game aren't saved to file until the game is properly exited or reloaded.
You won't be able to have an external program acting on them in real time during gameplay nor have the game respond to external changes made to a saved variables file. The most you can do is edit them before starting up the game, or parse them after the game is closed/reloaded.

Last edited by Ammako : 04-12-18 at 07:22 PM.
  Reply With Quote
04-12-18, 07:17 PM   #3
Kanegasi
A Frostmaul Preserver
 
Kanegasi's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2007
Posts: 292
Originally Posted by Ammako View Post
the changes aren't saved to file until the game is properly logged out
SavedVariable files are also written during /reload.
  Reply With Quote
04-12-18, 07:17 PM   #4
Christavious
A Murloc Raider
Join Date: Apr 2018
Posts: 6
Hmm, I was going to write currently playing songs to text file... then display that. So that isn't possible?
  Reply With Quote
04-12-18, 07:22 PM   #5
Christavious
A Murloc Raider
Join Date: Apr 2018
Posts: 6
No one would want to /reload after every song lol
  Reply With Quote
04-12-18, 07:28 PM   #6
Ammako
A Frostmaul Preserver
AddOn Author - Click to view addons
Join Date: Jun 2016
Posts: 256
What is it needed for?

At the worst it may be possible to write a music player addon that would read the music files (this is one of the few file i/o that the WoW api allows, albeit very limited and you'd need to hardcode a list of all music file paths + keep the music files inside AddOns folder.)
Then that would let you at most print the file name, because I don't think WoW api supports reading ID3 tags.

If you're just wanting this for streaming or youtube videos, you're much better off using a text source on your recording program to display the music file information and doing it this way.
  Reply With Quote
04-12-18, 07:41 PM   #7
Christavious
A Murloc Raider
Join Date: Apr 2018
Posts: 6
I was going to create an addon that displayed the current song your listening to, maybe even say it outloud in say from your character?

How would I set the filename to a string? That may work.
  Reply With Quote
04-12-18, 07:59 PM   #8
Ammako
A Frostmaul Preserver
AddOn Author - Click to view addons
Join Date: Jun 2016
Posts: 256
https://wow.gamepedia.com/API_PlayMusic

(Maybe PlaySoundFile too, idk)

You would have a table containing all the file names for your music files, and in your function which would pick out music to play, you would insert the file name into PlayMusic, and also process it separately to remove the extension and the leading folder names, so that you could display just the actual file's name w/o its extension.

All music would need to be copied into the addon's directory. You can't tell the game to blanket read all music files within the directory; all files need to have their file path added in the list in your addon's code.

(If you're going to output that in chat, I recommend you at least stick to custom emotes, unless you know that the people who will be around you while you use it won't mind it. Because a custom emote is less annoying than a /say message by default.)
  Reply With Quote
04-12-18, 08:24 PM   #9
Christavious
A Murloc Raider
Join Date: Apr 2018
Posts: 6
Yea, that wouldn't work with spotify because the music is live, no file names...
  Reply With Quote
04-12-18, 08:43 PM   #10
Christavious
A Murloc Raider
Join Date: Apr 2018
Posts: 6
Thank you for your help though I guess my addon project is a bust lol
  Reply With Quote
04-13-18, 02:18 AM   #11
myrroddin
A Molten Giant
 
myrroddin's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 950
WoW used to be able to access iTunes if you played on a Mac, but I seem to recall that got removed with either WoD or Legion.

If that is still possible, it was recording gameplay using QuickTime that was removed.

Either way, you needed a Mac.
  Reply With Quote
04-13-18, 10:22 AM   #12
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,557
For future reference...
http://www.wowinterface.com/forums/s...ad.php?t=42367
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote

WoWInterface » Developer Discussions » General Authoring Discussion » Read in text file

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