廣告廣告
  加入我的最愛 設為首頁 風格修改
首頁 首尾
 手機版   訂閱   地圖  簡體 
您是第 12642 個閱讀者
 
<< 上頁  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 |
觀眾甲
個人頭像
個人文章 個人相簿 個人日記 個人地圖
特殊貢獻獎
小有名氣
級別: 小有名氣 該用戶目前不上站
推文 x318 鮮花 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 鮮花 x237
分享: 轉寄此文章 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.024949 second(s),query:16 Gzip disabled
本站由 瀛睿律師事務所 擔任常年法律顧問 | 免責聲明 | 本網站已依台灣網站內容分級規定處理 | 連絡我們 | 訪客留言