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

 找回密码
 新人加入
查看: 3337|回复: 8

问下在文本行里面规定的pos可以在template里面取得坐标么? [复制链接]

正式会员

Axcellurator

Rank: 4

发表于 2014-1-24 22:45:57 |显示全部楼层
本帖最后由 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


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

Rank: 4

发表于 2014-1-25 11:08:18 |显示全部楼层
写了个。

GetPos.zip

833 Bytes, 下载次数: 1118

正式会员

Axcellurator

Rank: 4

发表于 2014-1-25 11:14:22 |显示全部楼层
几年 发表于 2014-1-25 11:08
写了个。

膜拜大大!我先去研究一下

Rank: 4

发表于 2014-1-25 23:14:43 |显示全部楼层
原来这么容易

Rank: 4

发表于 2017-1-9 16:11:38 |显示全部楼层
为什么我现在运行会报错了?难道是aegisub版本问题?

Rank: 4

发表于 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()!

Rank: 4

发表于 2017-1-9 18:04:37 |显示全部楼层
去掉大括号那些就成功了。

Rank: 4

发表于 2017-1-9 18:51:05 |显示全部楼层
"{.+\\pos%((%-?%d+%.?%d*),(%-?%d+%.?%d*)%).+}"

Rank: 4

发表于 2017-1-9 19:52:06 |显示全部楼层
{.*\\pos%((%-?%d+%.?%d*),(%-?%d+%.?%d*)%).*}
您需要登录后才可以回帖 登录 | 新人加入

GitHub|TCAX 主页

GMT+8, 2024-3-29 02:03

Powered by Discuz! X2

© 2001-2011 Comsenz Inc.

回顶部
RealH