WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   General Authoring Discussion (https://www.wowinterface.com/forums/forumdisplay.php?f=20)
-   -   Read in text file (https://www.wowinterface.com/forums/showthread.php?t=56147)

Christavious 04-12-18 07:08 PM

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? :cool:

Ammako 04-12-18 07:14 PM

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.

Kanegasi 04-12-18 07:17 PM

Quote:

Originally Posted by Ammako (Post 327507)
the changes aren't saved to file until the game is properly logged out

SavedVariable files are also written during /reload.

Christavious 04-12-18 07:17 PM

Hmm, I was going to write currently playing songs to text file... then display that. So that isn't possible?

Christavious 04-12-18 07:22 PM

No one would want to /reload after every song lol

Ammako 04-12-18 07:28 PM

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.

Christavious 04-12-18 07:41 PM

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.

Ammako 04-12-18 07:59 PM

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

Christavious 04-12-18 08:24 PM

Yea, that wouldn't work with spotify because the music is live, no file names... :(

Christavious 04-12-18 08:43 PM

Thank you for your help though :) I guess my addon project is a bust lol

myrroddin 04-13-18 02:18 AM

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.

Seerah 04-13-18 10:22 AM

For future reference...
http://www.wowinterface.com/forums/s...ad.php?t=42367


All times are GMT -6. The time now is 04:09 PM.

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