0
焦点头条

【小雪】插件制作教学系列(一)《一切都从零开始》

2014-02-23 13:06| 查看: 13439 |作者: 小雪



实践与应用:我的第一个插件

学习他人的知识是进步的不二渠道,融汇与贯通后成为自己的东西再来应用,就算是学会了。在编写插件的过程中常常会需要小退来重载插件,各种的纠结。在思考着拿什么插件作为第一个例子的同时,我突然就想到了自己所面临的窘境:频繁的小退,手动导出错误日志。是不是能够有个像魔兽那样的重载插件界面并且导出错误日志的功能呢?抱着兴奋的心情去寻找游戏里面源文件后发现都是被编译的。好吧,于是Cube插件成为了调试错误的一个平台,但是由于没有高亮语法,排版也很辛苦,又不能将整段代码放进去(太长了),不过至少比小退来得好吧。嗯,虽然Lua文件不能重载,但是窗口文件却是可以重载的,这大大的节省了我们编辑界面插件的时间。第一个插件教学就以实用为主,如何实现重载窗口文件以及导出错误日志。

由于这是第一个插件的制作,所以以下内容将进行详细的解说,后续插件教学不会如此啰嗦。
编写插件的一些注意事项

1.大小写问题
插件文件是大小写敏感的,Ab、ab、aB、AB是完全不同的概念。

2.关闭语言块
很多时候由于健忘会忘记关闭语言块,比如说忘记关括号:{}、()、[],忘记放end,忘记放关引号等等,这些对于新手来说是很常见的事情,养成一个先写框架再写内容的习惯可以避免这类事情导致的时间浪费。

3.中文标点符号
Lua只接受英文标点符号,所以要非常注意编写过程中逗号、句号、引号、括号等等不要用中文的标点,建议切换到英文后编写。注:中文字符在lua文件中占两个字符,删除时请尤其注意。

4.空格
关于空格,这是个很致命的问题,不该空格的地方不要空格,因为有些时候空格是隐形的,这是因为中文字的空格占两个字符。

5.排版
很多人可能会觉得很奇怪,为什么代码要进行排版。代码都跟">"的形状差不多,难道是为了美观?这并不只是为了美观,主要是为了方便阅读以及差错。在每一个判断句式或者函数后,下一行比前一行靠右一个tab的位置,方便解决第二点的语句块问题,也使得看起来比较舒服,差错时不麻烦。在每一个语句块完成的时候,留一行空格作为分割线。

6.调试
有些时候我们的语法没有错误,Lua自带的漏洞检测查不出错误在哪里,但插件就是不加载。这样的问题通常是因为某些值在与系统交换的时候为空,或者是判断时直接被拒绝了,这时候用Output()这个万能导出的命令来查错。在你觉得可能出错的地方,导出一下,看看在哪一步出错。
比如说:
我们想写个类似开关的判断式,如果a等于0则a=1
local a
if a==0 then
a=1
else
a=0end

这样的句子在语法上是正确的,但是在执行上却达不到我们的要求,这是一个判断上的错误的,因为a值为空。

调试方式如下:
local a
Output(a)
if a==0 then
a=1
Output("a=1")
else
a=0
Output("a=0")
end
然后发现a值为空。

7.先后顺序
由于代码是从上往下执行的,所以先后顺序尤其重要。
例:
local a=0
a=1
a=0
a=1
a=0
if a==1 then
Output(a)
end
这样是没有打印结果的,因为最后一次给a赋值是0,所以判断式不成立。


收藏 分享 邀请

游客 2016-05-16 10:41
mi9VMU You produced  ...
引用
游客 2016-05-14 03:17
You have brought up  ...
引用
游客 2016-04-06 01:43
bYohsZ very couple o ...
引用
游客 2016-03-31 18:45
bjfls4 Wow, great ar ...
引用
游客 2016-01-31 02:30
AWZu3D ugg australia ...
引用
游客 2016-01-01 20:43
boQTg6
引用
游客 2015-02-26 22:14
RqaqJn  <a href="htt ...
引用
游客 2014-11-23 07:13
紫檀手串的价值也是很大的:在本草纲目上就有记载,紫檀能够止痛止血,还能够调节气血;紫檀木所散发出来的香气对人们的心脏肾脏肝脏有很好的调节保养作用;紫檀手串戴在身上,还能够稳定人的情绪,使人遇事平静、沉稳,还有助于睡眠和安神醒脑,长期佩戴能够促进新细胞再生,预防皱纹的出现;紫檀对肠胃也很好,有的人就是把紫檀屑放到枕芯里当抱枕睡觉,对肠胃有很好的舒缓作用;在蒙古族的医学上还有记载,紫檀能够消除关节肿痛,和 ...
引用
游客 2014-09-28 10:26
1、春天,山坡的朝阳处雪开始融化,慢慢地露出黄黑色的地皮;雪水滋润着泥土,浸湿了去年的草楂;被雪盖着过了冬眠的草根苏醒复活了,渐渐地倔强有力地推去陈旧的草楂烂叶,奋力地生长起来。与此同时,去年秋天随风摇落下来的草木种子,也被湿土裹住,在孳殖着根须,争取它们的生命。山的背阴处虽然还寒气凛凛,可是寒冷的威力已在渐渐衰弱。朝阳处的温暖雪水顺着斜谷流过来,融化了硬硬的雪层,开始冲开山涧溪水的冰面。巨大的冻 ...
引用
游客 2014-09-28 06:27
每到春天,红得如火的木棉花,粉得如霞的芍药花,白得如玉的月季花竞相开放。它们有的花蕾满枝,有的含苞初绽,有的昂首怒放。一阵阵沁人心肺的花香引来了许许多多的小蜜蜂,嗡嗡嗡地边歌边舞。 <br><br>盼望着,盼望着,(表现急切喜悦的心情)东风来了,春天的脚步近了。 <br><br>清晨,春姑娘穿着美丽的衣裳,舞着暖风,招展地笑着向我们走来,给大自然披上了新装,使万物显现出无限生机.一缕缕金黄色的阳光撒向刚披上新装的草地,阳 ...
引用
游客 2014-09-24 20:58
ahF8QM I have been absent for some time, but now I remember why I used to love this blog. Thanks , I'll try and check back more frequently. How frequently you update your site?
引用
游客 2014-08-26 06:10
A lot of thanks for each of your work on this web site. My mom really loves going through investigation and it is simple to grasp why. Many of us notice all relating to the dynamic ways you make invaluable information by means of this web blog and even cause response from others on the issue so our favorite princess is certainly studying a whole lot. Take advantage of the remaining portion of the  ...
引用
游客 2014-08-09 08:42
I have been exploring for a bit for any high quality articles or blog posts on this kind of area . Exploring in Yahoo I at last stumbled upon this site. Reading this information So i¡¦m happy to convey that I've a very just right uncanny feeling I discovered exactly what I needed. I most indisputably will make sure to don¡¦t overlook this website and provides it a glance regularly.
gebrauchte  ...
引用
游客 2014-08-08 21:10
What i don't understood is actually how you are no longer really a lot more smartly-liked than you might be right now. You're so intelligent. You already know therefore considerably in terms of this topic, produced me individually consider it from a lot of varied angles. Its like women and men are not involved unless it is one thing to accomplish with Lady gaga! Your own stuffs nice. All the time  ...
引用
游客 2014-08-08 20:06
Good ¡V I should certainly pronounce, impressed with your site. I had no trouble navigating through all the tabs and related info ended up being truly simple to do to access. I recently found what I hoped for before you know it at all. Quite unusual. Is likely to appreciate it for those who add forums or something, website theme . a tones way for your customer to communicate. Excellent task..
Che ...
引用
游客 2014-08-04 14:04
I would like to convey my gratitude for your generosity supporting men and women who really need help with your theme. Your personal commitment to passing the solution up and down ended up being amazingly interesting and have consistently empowered many people just like me to get to their aims. Your useful help signifies a whole lot to me and even more to my colleagues. Thanks a lot; from all of u ...
引用
n5012346 2014-07-05 11:49
: Well written. Who's number four? Lately Ive been following Damon Vickers, a finacial luminary from Seattle. If you havnt read his book The Day after t ...
oh ·····can you speak  Chinese?
引用
游客 2014-07-05 09:01
有剑网三pak v3的解包工具么?
引用
游客 2014-06-18 04:52
Well written. Who's number four? Lately Ive been following Damon Vickers, a finacial luminary from Seattle. If you havnt read his book The Day after the Dollar Crashes, you should get plan a trip to the bookstore. I feel that people dont really fathom the magnitude of the situation we face today. To have a great manager like Damon Vickers, who called the market plummet in both 2000 and 2008, publi ...
引用
游客 2014-04-14 15:47
请问一下有没有交流群?
引用

查看全部评论(20)

关注订阅号"剑网3PVE"
获取第一手剑三资讯

关闭
您当前使用的浏览器版本过低,网站部分功能可能失效,请更换合适的浏览器。了解更多
返回顶部