广告广告
  加入我的最爱 设为首页 风格修改
首页 首尾
 手机版   订阅   地图  繁体 
您是第 13597 个阅读者
 
<< 上页  1   2   3  下页 >>(共 3 页)
发表文章 发表投票 回覆文章
  可列印版   加为IE收藏   收藏主题   上一主题 | 下一主题   
++HAUN 手机
个人头像
个人文章 个人相簿 个人日记 个人地图
小有名气
级别: 小有名气 该用户目前不上站
推文 x55 鲜花 x410
分享: 转寄此文章 Facebook Plurk Twitter 复制连结到剪贴簿 转换为繁体 转换为简体 载入图片
动态阵列
Dynamic Arrays
Dynamic arrays are arrays which don't have a hardcoded size. For example:
Function1(size){   new array[size];    /* Code */}[/pre]Dynamic arrays can have any expression as their size as long as the expression evaluates to a number larger than 0. Like normal arrays, SourcePawn does not know the array size after it is created; you have to save it if you want it later.
Dynamic arrays are only valid at the local scope level, since code cannot exist globally.


あーう~あーう~あーう~あーう~あーう~
献花 x0 回到顶端 [10 楼] From:台湾中华电信股份有限公司 | Posted:2013-04-07 14:46 |
++HAUN 手机
个人头像
个人文章 个人相簿 个人日记 个人地图
小有名气
级别: 小有名气 该用户目前不上站
推文 x55 鲜花 x410
分享: 转寄此文章 Facebook Plurk Twitter 复制连结到剪贴簿 转换为繁体 转换为简体 载入图片
扩展变数宣告
Extended Variable Declarations
Variables can be declared in more ways than simply new.
decl
Purpose
By default, all variables in Pawn are initialized to zero. If there is an explicit initializer, the variable is initialized to the expression after the = token. At a local scope, this can be a run-time expense. The decl keyword (which is only valid at local scope) was introduced to let users decide if they want variables initialized or not.
Note: decl should not be used on single cell variables. There is almost never any benefit.
Explanation
For example:
new c = 5;new d;new String:blah[512]Format(blah, sizeof(blah), "%d %d", c, d);[/pre]In this code, c is equal to 5 and d is equal to 0. The run-time expense of this initialization is negligible. However, blah is a large array, and the expense of initializing the entire array to 0s could be detrimental in certain situations.
Note that blah does not need to be zeroed. In between being declared with new and stored with Format(), blah is never loaded or read. Thus this code would be more efficiently written as:
new c = 5;new d;decl String:blah[512]Format(blah, sizeof(blah), "%d %d", c, d);[/pre] Caveats
The downside to decl is that it means its variables will start with "garbage" contents. For example, if we were to use:
new c = 5;new d;decl String:blah[512]; PrintToServer("%s", blah)Format(blah, sizeof(blah), "%d %d", c, d);[/pre]This code may crash the server, because blah may be completely corrupt (strings require a terminator, and that may not be present). Similarly, if we did:
new c = 5;decl d;decl String:blah[512]Format(blah, sizeof(blah), "%d %d", c, d);[/pre]The value of d is now undefined. It could be any value, negative or positive.
Note that it is easy to efficiently make strings safe. The example below shows how to terminate a garbage string:
decl String:blah[512]; blah[0] = '\0';[/pre] Golden Rules
  • Only use decl if in between declaring and loading/reading the value, you are absolutely sure there is at least one store/set operation that gives the variable valid data.
  • Do not prematurely optimize. Likewise, there is no need to use decl on non-arrays, because there is no added expense for initializing a single cell value.
Notes
This example is NOT as efficient as a decl:
new String:blah[512] = "a";[/pre]Even though the string is only one character, the new operator guarantees the rest of the array will be zeroed as well.
Also note, it is valid to explicitly initialize a decl ONLY with strings:
decl String:blah[512] = "a";[/pre]However, any other tag will fail to compile, because the purpose of decl is to avoid any initialization:
decl Float:blah[512] = {1.0};[/pre] static
The static keyword is available at global and local scope. It has different meanings in each.
Global static
A global static variable can only be accessed from within the same file. For example:
//file1.incstatic Float:g_value1 = 0.15f; //file2.incstatic Float:g_value2 = 0.15f;[/pre]If a plugin includes both of these files, it will not be able to use either g_value1 or g_value2. This is a simple information hiding mechanism, and is similar to declaring member variables as private in languages like C++, Java, or C#.
Local static
A local static variable is a global variable that is only visible from its local lexical scope. For example:
MyFunction(inc){   static counter = -1;    counter += inc;    return counter;}[/pre]In this example, counter is technically a global variable -- it is initialized once to -1 and is never initialized again. It does not exist on the stack. That means each time MyFunction runs, the counter variable and its storage in memory is the same.
Take this example:
MyFunction(5);MyFunction(6);MyFunction(10);[/pre]In this example, counter will be -1 + 5 + 6 + 10, or 20, because it persists beyond the frame of the function. Note this may pose problems for recursive functions: if your function may be recursive, then static is usually not a good idea unless your code is re-entrant.
The benefit of a local static variable is that you don't have to clutter your script with global variables. As long as the variable doesn't need to be read by another function, you can squirrel it inside the function and its persistence will be guaranteed.
Note that statics can exist in any local scope:
MyFunction(inc){   if (inc > 0)   {     static counter;     return (counter += inc);   }   return -1;}[/pre]


あーう~あーう~あーう~あーう~あーう~
献花 x0 回到顶端 [11 楼] From:台湾中华电信股份有限公司 | Posted:2013-04-07 14:48 |
G.M.I
个人头像
个人文章 个人相簿 个人日记 个人地图
初露锋芒
级别: 初露锋芒 该用户目前不上站
推文 x94 鲜花 x163
分享: 转寄此文章 Facebook Plurk Twitter 复制连结到剪贴簿 转换为繁体 转换为简体 载入图片

这样翻译感觉会非常辛苦
建议楼主自写一个教学会比较好


献花 x0 回到顶端 [12 楼] From:美国ATT用户 | Posted:2013-04-10 16:40 |
sot86217
个人文章 个人相簿 个人日记 个人地图
小人物
级别: 小人物 该用户目前不上站
推文 x0 鲜花 x5
分享: 转寄此文章 Facebook Plurk Twitter 复制连结到剪贴簿 转换为繁体 转换为简体 载入图片

应该分开写,大部分的人没耐心一次看完吧...
不过内容真是丰富...


献花 x0 回到顶端 [13 楼] From:台湾中华电信股份有限公司 | Posted:2013-04-10 20:47 |
观众甲
个人头像
个人文章 个人相簿 个人日记 个人地图
特殊贡献奖
小有名气
级别: 小有名气 该用户目前不上站
推文 x319 鲜花 x963
分享: 转寄此文章 Facebook Plurk Twitter 复制连结到剪贴簿 转换为繁体 转换为简体 载入图片

看着标题一脸兴奋
结果看到2楼,3楼,直接按了X


献花 x0 回到顶端 [14 楼] From:IANA | Posted:2013-04-27 00:52 |
qiaoqiao520
个人文章 个人相簿 个人日记 个人地图
小人物
级别: 小人物 该用户目前不上站
推文 x0 鲜花 x0
分享: 转寄此文章 Facebook Plurk Twitter 复制连结到剪贴簿 转换为繁体 转换为简体 载入图片

学过C语言的很好理解,


献花 x0 回到顶端 [15 楼] From:未知地址 | Posted:2013-05-20 20:17 |
kenny199465
个人文章 个人相簿 个人日记 个人地图
路人甲
级别: 路人甲 该用户目前不上站
推文 x0 鲜花 x0
分享: 转寄此文章 Facebook Plurk Twitter 复制连结到剪贴簿 转换为繁体 转换为简体 载入图片

哦~~~好强大啊!!!!

虽然看不明白 表情


太密了- -'''


献花 x0 回到顶端 [16 楼] From:IANA保留地址 | Posted:2013-05-21 21:34 |
弑血
个人头像
个人文章 个人相簿 个人日记 个人地图
社区建设奖 特殊贡献奖 创作大师奖
小有名气
级别: 小有名气 该用户目前不上站
推文 x108 鲜花 x240
分享: 转寄此文章 Facebook Plurk Twitter 复制连结到剪贴簿 转换为繁体 转换为简体 载入图片

这篇对写插件 有极大帮助

这都是C的基础

不会的人 可以 快点学^^ 推荐



目前传授教学&有兴趣者可以问我
BOT瞄准攻击NPC&模仿事件触发计算出场&新增地图重生位置等等
已修复entity的attachment错误问题,开始尝试写出各种npc_boss成品
按这里检视影片,登入论坛可以直接观看
按这里检视影片,登入论坛可以直接观看
按这里检视影片,登入论坛可以直接观看
按这里检视影片,登入论坛可以直接观看
献花 x0 回到顶端 [17 楼] From:台湾中华电信股份有限公司 | Posted:2013-07-07 16:38 |
eric512
个人文章 个人相簿 个人日记 个人地图
小人物
级别: 小人物 该用户目前不上站
推文 x1 鲜花 x87
分享: 转寄此文章 Facebook Plurk Twitter 复制连结到剪贴簿 转换为繁体 转换为简体 载入图片

哇,好难,我睇吾明 表情


献花 x0 回到顶端 [18 楼] From:未知地址 | Posted:2013-07-08 15:24 |
Veterans
个人文章 个人相簿 个人日记 个人地图
路人甲
级别: 路人甲 该用户目前不上站
推文 x0 鲜花 x1
分享: 转寄此文章 Facebook Plurk Twitter 复制连结到剪贴簿 转换为繁体 转换为简体 载入图片

密密麻麻的编码 楼主花不少时间吧><
辛苦你啰


献花 x0 回到顶端 [19 楼] From:未知地址 | Posted:2013-07-12 17:57 |

<< 上页  1   2   3  下页 >>(共 3 页)
首页  发表文章 发表投票 回覆文章
Powered by PHPWind v1.3.6
Copyright © 2003-04 PHPWind
Processed in 0.110986 second(s),query:16 Gzip disabled
本站由 瀛睿律师事务所 担任常年法律顾问 | 免责声明 | 本网站已依台湾网站内容分级规定处理 | 连络我们 | 访客留言