TCAX 字幕特效制作工具官方论坛 | ASS | TCAS | Python | Aegisub | Lua

标题: 问下在文本行里面规定的pos可以在template里面取得坐标么? [打印本页]

作者: Tsankou    时间: 2014-1-24 22:45:57     标题: 问下在文本行里面规定的pos可以在template里面取得坐标么?

本帖最后由 Tsankou 于 2014-1-25 09:52 编辑

比如有一行的文本是
{\pos(100,200)}测试测试
可以在写template的时候取得这时候定下的坐标么?



我的思路是写一个函数来取得坐标
就写了这么个玩意【好吧没有学过编程什么的 前面的空格什么的都是随意的……似乎Aeg娘不会计较这些
  1. function GetPosition()   
  2.     raw=line.text   
  3.     for i = 1,_G.unicode.len(raw)-3,1  do
  4.            while string.sub(raw,i,i+3)=="\pos"   do
  5.                      for j = i,j+1,1 do
  6.                            while string.sub(raw,j,j)==","  do
  7.                                      for k=j,k+1,1 do
  8.                                             while string.sub(raw,k,k)==")" do break end
  9.                                      end
  10.                            break
  11.                            end
  12.                      end
  13.            break
  14.            end
  15.     end   
  16.     if i == _G.unicode.len(raw)-3
  17.        then
  18.          xpos = line.center
  19.          ypos = line.middle
  20.          return ""  
  21.        else
  22.          xpos = tonumber(string.sub(raw,i+4,j-1))     
  23.          ypos = tonumber(string.sub(raw,j+1,k-1))   
  24.          return ""   
  25.     end         
  26. end
复制代码
然后这样执行自动化报错
QQ截图20140124224626.png

求问大大们有没有什么其他的方法解决这个问题
或者求指出一下脚本哪里错了……

图片附件: QQ截图20140124224626.png (2014-1-24 22:45:17, 11.05 KB) / 下载次数 374
http://tcax.org/forum.php?mod=attachment&aid=MTUzNXw0NjM1OWFhOHwxNzE0NjgzNzYxfDB8MA%3D%3D


作者: 几年    时间: 2014-1-25 11:08:18

写了个。

附件: GetPos.zip (2014-1-25 11:07:44, 833 Bytes) / 下载次数 1153
http://tcax.org/forum.php?mod=attachment&aid=MTUzN3xkMmZmYzg4YnwxNzE0NjgzNzYxfDB8MA%3D%3D
作者: Tsankou    时间: 2014-1-25 11:14:22

几年 发表于 2014-1-25 11:08
写了个。

膜拜大大!我先去研究一下
作者: 电脑迷    时间: 2014-1-25 23:14:43

原来这么容易
作者: gxnnsz    时间: 2017-1-9 16:11:38

为什么我现在运行会报错了?难道是aegisub版本问题?
作者: gxnnsz    时间: 2017-1-9 16:12:11

Failed to parse Lua code: [string "template code"]:1: invalid escape sequence near '"{.*'
Code that failed to parse: function GetPosition()  x,y=string.match(line.raw,"{.*\pos%((%-?%d+%.?%d*),(%-?%d+%.?%d*)%).*}")  return x.." "..y end

Runtime error in template expression: [string "return (GetPosition())"]:1: attempt to call global 'GetPosition' (a nil value)
Expression producing error: GetPosition()
Template with expression: !GetPosition()!
作者: gxnnsz    时间: 2017-1-9 18:04:37

去掉大括号那些就成功了。
作者: gxnnsz    时间: 2017-1-9 18:51:05

"{.+\\pos%((%-?%d+%.?%d*),(%-?%d+%.?%d*)%).+}"
作者: gxnnsz    时间: 2017-1-9 19:52:06

{.*\\pos%((%-?%d+%.?%d*),(%-?%d+%.?%d*)%).*}




欢迎光临 TCAX 字幕特效制作工具官方论坛 | ASS | TCAS | Python | Aegisub | Lua (http://tcax.org/) Powered by Discuz! X2