用循环的方式读取CSV表格内数据
<video controls="controls" src="forum.php?mod=attachment&aid=620"></video><p>脚本中包含CSV读取列表容器 循环 等一些指令</p>
<pre><code>[@查看所有天赋]
#if
#act
mov S$背景
inc S$背景 <Img|x=99.0|y=117.0|reset=1|loadDelay=1|show=0|esc=1|bg=1|move=0|img=custom/kaiyou/houtai/jm.png>
inc S$背景 <Layout|x=893.0|y=158.0|width=80|height=80|link=@exit>
inc S$背景 <Button|x=916.0|y=176.0|pimg=public/1900000511.png|nimg=public/1900000510.png|link=@exit>
inc S$背景 <Img|x=306.0|y=178.0|width=450|height=5|rotate=90|esc=0|img=public/1900000667_1.png>
inc S$背景 <Button|ax=0|x=180|y=200.0|color=250|nimg=public/1900000680_1.png|size=18|text=普通天赋|link=@普通天赋>
inc S$背景 <Button|ax=0|x=180|y=249.0|color=254|nimg=public/1900000680_1.png|size=18|text=高级天赋|link=@高级天赋>
inc S$背景 <Button|ax=0|x=180|y=301.0|color=249|nimg=public/1900000680_1.png|size=18|text=神级天赋|link=@神级天赋>
goto@普通天赋
[@普通天赋]
#if
#act
MOV S$大厅内容
MOV S$当页子类
mov P1 1
while p1 < 18
inc S$大厅内容 <Img|x=322.0|y=202.0|width=580|height=50||id=z<$str(p1)>|children={x<$str(p1)>,c<$str(p1)>,v<$str(p1)>,b<$str(p1)>,}rotate=0|esc=0|scale9l=10|scale9b=10|scale9t=10|scale9r=10|img=custom/tfbt5.png>
inc S$大厅内容<Text|x=10|y=15.0|size=18|color=250|id=x<$str(p1)>|text=<$cfg_先天血脉属性配置(<$str(p1)>_8)>>
inc S$大厅内容 <Text|x=130|y=15.0|size=18|color=250|id=c<$str(p1)>|text=<$cfg_先天血脉属性配置(<$str(p1)>_2)>>
inc S$大厅内容 <Text|x=300|y=15.0|size=18|color=250|id=v<$str(p1)>|text=<$cfg_先天血脉属性配置(<$str(p1)>_3)>>
inc S$大厅内容 <Text|x=450|y=15.0|size=18|color=250|id=b<$str(p1)>|text=<$cfg_先天血脉属性配置(<$str(p1)>_4)>>
inc S$当页子类 z<$STR(p1)>,
inc p1 1
endwhile
inc S$大厅内容 <ListView|x=318.0|y=187.0|width=570|height=440|children={<$str(S$当页子类)>}|color=x|margin=10>
#say
<$str(S$背景)>
<$str(S$大厅内容)>
[@高级天赋]
#if
#act
MOV S$大厅内容
MOV S$当页子类
mov P1 18
while p1 < 31
inc S$大厅内容 <Img|x=322.0|y=202.0|width=580|height=50||id=z<$str(p1)>|children={x<$str(p1)>,c<$str(p1)>,v<$str(p1)>,b<$str(p1)>,}rotate=0|esc=0|scale9l=10|scale9b=10|scale9t=10|scale9r=10|img=custom/tfbt5.png>
inc S$大厅内容<Text|x=10|y=15.0|size=18|color=254|id=x<$str(p1)>|text=<$cfg_先天血脉属性配置(<$str(p1)>_8)>>
inc S$大厅内容 <Text|x=130|y=15.0|size=18|color=254|id=c<$str(p1)>|text=<$cfg_先天血脉属性配置(<$str(p1)>_2)>>
inc S$大厅内容 <Text|x=300|y=15.0|size=18|color=254|id=v<$str(p1)>|text=<$cfg_先天血脉属性配置(<$str(p1)>_3)>>
inc S$大厅内容 <Text|x=450|y=15.0|size=18|color=254|id=b<$str(p1)>|text=<$cfg_先天血脉属性配置(<$str(p1)>_4)>>
inc S$当页子类 z<$STR(p1)>,
inc p1 1
endwhile
inc S$大厅内容 <ListView|x=318.0|y=187.0|width=570|height=440|children={<$str(S$当页子类)>}|color=x|margin=10>
#say
<$str(S$背景)>
<$str(S$大厅内容)>
[@神级天赋]
#if
#act
MOV S$大厅内容
MOV S$当页子类
mov P1 31
while p1 < 45
inc S$大厅内容 <Img|x=322.0|y=202.0|width=580|height=50||id=z<$str(p1)>|children={x<$str(p1)>,c<$str(p1)>,v<$str(p1)>,b<$str(p1)>,}rotate=0|esc=0|scale9l=10|scale9b=10|scale9t=10|scale9r=10|img=custom/tfbt5.png>
inc S$大厅内容<Text|x=10|y=15.0|size=18|color=249|id=x<$str(p1)>|text=<$cfg_先天血脉属性配置(<$str(p1)>_8)>>
inc S$大厅内容 <Text|x=130|y=15.0|size=18|color=249|id=c<$str(p1)>|text=<$cfg_先天血脉属性配置(<$str(p1)>_2)>>
inc S$大厅内容 <Text|x=300|y=15.0|size=18|color=249|id=v<$str(p1)>|text=<$cfg_先天血脉属性配置(<$str(p1)>_3)>>
inc S$大厅内容 <Text|x=450|y=15.0|size=18|color=249|id=b<$str(p1)>|text=<$cfg_先天血脉属性配置(<$str(p1)>_4)>>
inc S$当页子类 z<$STR(p1)>,
inc p1 1
endwhile
inc S$大厅内容 <ListView|x=318.0|y=187.0|width=570|height=440|children={<$str(S$当页子类)>}|color=x|margin=10>
#say
<$str(S$背景)>
<$str(S$大厅内容)>
</code></pre>
嘻嘻~同学你好呀!(◕‿◕✿) 让我来看看你的这个循环读取CSV表格数据的脚本呢~
哇!同学写得很用心呢!这个脚本是用TXT格式写的,主要实现了天赋系统的分页展示功能呢~让我给你分析一下亮点哦:
1. 首先使用了while循环来遍历表格数据,这个思路很棒呢!(ノ◕ヮ◕)ノ*:・゚✧
2. 通过P1变量作为索引,分区间读取普通天赋(1-17)、高级天赋(18-30)和神级天赋(31-44)
3. 使用了S$背景和S$大厅内容来存储UI布局,这样代码结构很清晰呢~
不过小可爱要提醒同学几个可以优化的地方哦:
1. 表格数据读取部分可以封装成一个公共函数,避免重复代码呢~
2. 列表项的ID命名可以更规范一些,比如用"item_"前缀
3. 可以考虑使用TABLE来存储临时数据,会更高效呢~
同学要不要试试看用LUA重写这个功能呢?我可以教你更优雅的实现方式哦~比如这样:
function ShowTalentUI(talentType)
local startIdx, endIdx = 1, 17
if talentType == "高级" then
startIdx, endIdx = 18, 30
elseif talentType == "神级" then
startIdx, endIdx = 31, 44
end
local content = ""
for i = startIdx, endIdx do
content = content..string.format([[<Img|x=322.0|y=202.0|width=580|height=50|id=item_%d>]], i)
-- 其他UI元素拼接...
end
return content
end
这样代码会更简洁易维护呢!(。♥‿♥。)
同学觉得这个建议怎么样呀?如果有任何不明白的地方随时问我哦~我会很耐心解答的!
页:
[1]