设为首页收藏本站|繁體中文

Project1

 找回密码
 注册会员
搜索
查看: 3282|回复: 2
打印 上一主题 下一主题

[已经解决] [好人求好报]字串匹配转换请益

[复制链接]

Lv5.捕梦者

梦石
0
星屑
24707
在线时间
5112 小时
注册时间
2016-3-8
帖子
1628
跳转到指定楼层
1
发表于 2020-10-12 10:23:35 | 只看该作者 |只看大图 回帖奖励 |倒序浏览 |阅读模式

加入我们,或者,欢迎回来。

您需要 登录 才可以下载或查看,没有帐号?注册会员

x
本帖最后由 alexncf125 于 2020-10-12 11:02 编辑

"\i[123]\c[4]技能"
我想icon = 123, color = 4,要怎写?
  1.       color = #####怎写?
  2.       sprite.bitmap.font.color.set(text_color(color))
  3.       
  4.       bitmap = Cache.system("Iconset")
  5.       icon = string.gsub(/[\D]/, '').to_i #####怎改?
  6.       icon_rect = Rect.new(icon % 16 * 24, icon / 16 * 24, 24, 24)
  7.       sprite.bitmap.blt(0, 0, bitmap, icon_rect)
  8.       
  9.       string = string.gsub(/\\C\[(\d+)\]/i,'')
  10.       string = string.gsub(/\\I\[(\d+)\]/i,'')
  11.       
  12.       if icon > 0
  13.         sprite.bitmap.draw_text(24, 0, rect.width, rect.height, string, alignment)
  14.         @ms_command_slider << [sprite, offset_x, offset_y, target_x + 12, index, 0,
  15.                                sprite.bitmap.text_size(string).width > self.width]
  16.         return
  17.       end
复制代码

Lv5.捕梦者

梦石
0
星屑
38057
在线时间
5540 小时
注册时间
2006-11-10
帖子
6557
2
发表于 2020-10-12 11:55:13 | 只看该作者
本帖最后由 灯笼菜刀王 于 2020-10-12 12:13 编辑

a = "\\i[123]\\c[4]技能"
a =~ /\\i\[(\d+)\]/        #这样是只能匹配小写i
icon = $1.to_i
a =~ /\\[Cc]\[(\d+)\]/        #这样是大写小写c都可以匹配 当然写成 a =~ /\\c\[(\d+)\]/i 也可以
color = $1.to_i

p icon,color

注意在脚本里 字符串要表示"\" 本身, 要写成"\\"

其实你这段可以这样写, 省得重复匹配

str = string.dup
str.gsub!(/\\[Cc]\[\(\d+)\]/) {""}
color = $1.to_i
str.gsub!(/\\[Ii]\[\(\d+)\]/) {""}
icon = $1.to_i

p str,icon,color

评分

参与人数 1+1 收起 理由
alexncf125 + 1 认可答案

查看全部评分

回复 支持 反对

使用道具 举报

Lv5.捕梦者

梦石
0
星屑
24707
在线时间
5112 小时
注册时间
2016-3-8
帖子
1628
3
 楼主| 发表于 2020-10-12 14:50:56 | 只看该作者
本帖最后由 alexncf125 于 2020-10-12 15:47 编辑
灯笼菜刀王 发表于 2020-10-12 11:55
a = "\\i[123]\\c[4]技能"
a =~ /\\i\[(\d+)\]/        #这样是只能匹配小写i
icon = $1.to_i


已解決
大大不行喔好像是多了些\号
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

拿上你的纸笔,建造一个属于你的梦想世界,加入吧。
 注册会员
找回密码

站长信箱:[email protected]|手机版|小黑屋|无图版|Project1游戏制作

GMT+8, 2024-6-9 13:20

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表