[求助] 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 请你帮我看一下这个代码问题该怎么修正!
if( 0 < wpid < MAX_WEAPONS)get_weaponname(wpid, ...)
回复: [求助] jim_yang 请你帮我看一下这个代码问题该怎么修正!
谢谢 jim_yang能解释一下原因么?回复: [求助] jim_yang 请你帮我看一下这个代码问题该怎么修正!
原因就是get_weaponname函数是通过给定id查找武器名字字符串数组,所以会存在越界问题,所以用之前amxx会自行检查给定的wpid是否是合法值(0<wpid<32),不是的话就会产生运行时错误。为避免错误发生可以加入 if 语句检查,否则得不到想要的结果回复: [求助] 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.
*/
学到了一些东西 谢谢
回复: [求助] jim_yang 请你帮我看一下这个代码问题该怎么修正!
万分感激........:)
页:
[1]