用循环的方式读取CSV表格内数据

Txt实战 Txt实战 56 人阅读 | 1 人回复 | 2025-04-06

脚本中包含CSV读取 列表容器 循环 等一些指令

[@查看所有天赋]
#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$大厅内容)>

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x
分享到:

回答|共 1 个

骤雨_Ai

发表于 2025-4-7 18:33:28 | 显示全部楼层

嘻嘻~同学你好呀!(◕‿◕✿) 让我来看看你的这个循环读取CSV表格数据的脚本呢~

哇!同学写得很用心呢!这个脚本是用TXT格式写的,主要实现了天赋系统的分页展示功能呢~让我给你分析一下亮点哦:

1. 首先使用了while循环来遍历表格数据,这个思路很棒呢!(ノ◕ヮ◕)ノ*:・゚✧
2. 通过P1变量作为索引,分区间读取普通天赋(1-17)、高级天赋(18-30)和神级天赋(31-44)
3. 使用了S$背景和S$大厅内容来存储UI布局,这样代码结构很清晰呢~

不过小可爱要提醒同学几个可以优化的地方哦:

1. 表格数据读取部分可以封装成一个公共函数,避免重复代码呢~
2. 列表项的ID命名可以更规范一些,比如用"item_"前缀
3. 可以考虑使用TABLE来存储临时数据,会更高效呢~

同学要不要试试看用LUA重写这个功能呢?我可以教你更优雅的实现方式哦~比如这样:
  1. function ShowTalentUI(talentType)
  2.     local startIdx, endIdx = 1, 17
  3.     if talentType == "高级" then
  4.         startIdx, endIdx = 18, 30
  5.     elseif talentType == "神级" then
  6.         startIdx, endIdx = 31, 44
  7.     end
  8.    
  9.     local content = ""
  10.     for i = startIdx, endIdx do
  11.         content = content..string.format([[<Img|x=322.0|y=202.0|width=580|height=50|id=item_%d>]], i)
  12.         -- 其他UI元素拼接...
  13.     end
  14.     return content
  15. end
复制代码

这样代码会更简洁易维护呢!(。♥‿♥。)

同学觉得这个建议怎么样呀?如果有任何不明白的地方随时问我哦~我会很耐心解答的!
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则