Now, the actual thing this script does is line.effect="test". You can, however, create multiple undo points, like for every function in your script, but it's usually only confusing and not very practical. You can name those things anything you want, for example just l and t, which may be good for a short script, but again, line and text are commonly used by most of us, so it keeps things clear.Īt_undo_point(script_name) sets the undo point, and should be at the end of the main function, though I think Aegisub does it automatically anyway. Also, it could also say text=line.text since line is already defined at that point. The purpose is to use something that's short instead of typing subs.text all the time. You see the same with text, even though in this case I don't need it, but usually you work with text the most. line is something you created, subs is the actual line in the subtitles, so you need the subs=line at the end. Then you work with line, and for it to be of any use, you have to put the line back in subs at the end. You could read it as "line is now subs" (when i is 25). Note that single = does not mean "equals". line=subs means that you create element line and put subs into it. So, the iterator i is going from 1 to 200, so when it's let's say 25, subs is subs, or the 25th line in the ASS file. You only want to apply this to dialogue lines, not to styles or headers, so you have to specify this condition: If the ASS file has 200 lines, the for cycle will run 200 times. #subs is how many lines there are in subs (including headers and all). The purple part is the actual specific function. The green part is what you'll usually have for every script that runs on all lines. Here's an example of a simple function that runs on the whole script: The "stuff goes here" part is where the actual function will be written. If you select one line and use sel, it's pretty much the same as using act. You can use it for functions that are supposed to run on only one line or read some info from the active line. You can have function test(subs).Īct is the active line, and you probably won't need it very often. Sel is selected lines, and if you want your function applied to all lines, you don't have to use this. In simple terms, it's like a table of all lines in the ASS script, including headers, styles, etc. It's probably best to use these even just because of the fact that others do it too, which makes it easier to make sense of each others' scripts. I tend to keep everything short, though I'm sure I'm not the only one who uses subs/sel/act. The 3 parts - subtitles, selected lines, and active line - give you 3 things you can work with. Since this function is referenced by register_macro, it's the main function of the script, and as such is by default given the Subtitles object to work with. I probably wrote at least 20 scripts before I actually understood what this is. Let's look at function test(subs, sel, act). Script_author and script_version aren't really important, but I'm sure you get the idea. The 3rd part means that running this script will run a function called "test". You can see description in the Automation Manager. The name will appear in the menu and as an undo entry when you run the script. 2 of them are defined at the beginning - script_name and script_description. The last line puts an entry in your automation menu. Once you understand how a script that adds blur works, adding more complex functions will be easy because that's just maths.Īegisub.register_macro(script_name, script_description, test) The goal is to explain how to write a basic automation script in as simple terms as possible. This is explained in the Aegisub manual, but since that may be confusing for beginners, I'll provide some specific practical examples. What I want to talk about the most is how to work with the Subtitles object, which is not really a matter of Lua, but rather of Aegisub and the ASS format. That, again, is something you can learn in an hour. It's mostly just if/then/end, the for cycle, gsub, and a few other things.Ī large part of what you need is regular expressions, or rather Lua's simplified pattern matching. You can learn all the Lua stuff you need in an hour. Rather than explaining lua itself, I'll explain more about scripts for Aegisub specifically. You should read lyger's guide first, because I'm not gonna explain the same things again, but I want to provide some more practical tips. I keep hearing people say "I need to learn some Lua" or "I need to learn to write automation scripts", and not many seem to really have gotten into it.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |