KYO 发表于 2008-6-27 18:35:59

[求助] jim_yang 请你帮我看一下这个代码问题该怎么修正!

debug 模式运行显示以下 错误
L 06/27/2008 - 18:01:45: Run time error 10: native error (native "get_weaponname")
L 06/27/2008 - 18:01:45:     test.sma::MyLast (line 20)

jim_yang 发表于 2008-6-27 18:44:25

回复: [求助] jim_yang 请你帮我看一下这个代码问题该怎么修正!

if( 0 < wpid < MAX_WEAPONS)
   get_weaponname(wpid, ...)

KYO 发表于 2008-6-29 19:31:31

回复: [求助] jim_yang 请你帮我看一下这个代码问题该怎么修正!

谢谢 jim_yang能解释一下原因么?

jim_yang 发表于 2008-6-29 20:23:33

回复: [求助] jim_yang 请你帮我看一下这个代码问题该怎么修正!

原因就是get_weaponname函数是通过给定id查找武器名字字符串数组,所以会存在越界问题,所以用之前amxx会自行检查给定的wpid是否是合法值(0<wpid<32),不是的话就会产生运行时错误。为避免错误发生可以加入 if 语句检查,否则得不到想要的结果

无尽的劫 发表于 2008-6-29 20:36:45

回复: [求助] jim_yang 请你帮我看一下这个代码问题该怎么修正!

/* Returns all carried weapons as bit sum. Gets
* also theirs indexes.
* Note that num is incremental - if you pass 0, you get
* 32 weapons towards the total. Afterwards, num will
* will contain the number of weapons retrieved.
* However, subsequent calls to get_user_weapons() will
* return the next batch of weapons, in case the mod
* supports more than 32 weapons.
* This means to call get_user_weapons() on the same
* inputs twice, you must reset num to 0 to get the
* original output again.
*/


学到了一些东西 谢谢

KYO 发表于 2008-6-29 20:41:07

回复: [求助] jim_yang 请你帮我看一下这个代码问题该怎么修正!

万分感激........:)
页: [1]
查看完整版本: [求助] jim_yang 请你帮我看一下这个代码问题该怎么修正!