找回密码
 点一下
查看: 1791|回复: 6

[已解决]这个函数为什么没用

[复制链接]
发表于 2008-10-29 14:12:16 | 显示全部楼层 |阅读模式
只是这个移动函数为什么没有用,很让我困惑
调用没反应啊,郁闷ing,哪位达人告诉下
[codes=jass]
//转型函数
function H2I takes handle h returns integer
           return h
           return 0
endfunction
function I2H takes integer h returns handle
           return h
           return null
endfunction
function H2S takes handle h returns string
           return I2S(H2I(h))
           return null
endfunction
//释放缓存
function FlushTable takes handle lable returns nothing
           call FlushStoredMission(udg_GC,H2S(lable))
//返回两个单位的角度(非弧度)
function GetUnitAngle takes unit a,unit b returns real
           local real dx = GetUnitX(a) - GetUnitX(b)
           local real dy = GetUnitY(a) - GetUnitY(b)
           local real anger
           if (GetUnitX(a) > GetUnitX(b)) then
                 set anger = (Atan(dy/dx)*bj_RADTODEG) + 180
           else
                 set anger = Atan(dy/dx)*bj_RADTODEG
                 endif  
           return  anger
endfunction
//技能模板
//hg_skillmode1(GetTriggerUnit(),GetSpellTargetUnit(),速度,行动效果,行动中的伤害系数)
function  hg_skillmode1_action takes nothing returns nothing
       local timer tm = GetExpiredTimer()
       local unit u1 = I2U(GetStoredInteger(udg_GC,H2S(tm),"u1"))
       local unit u2 = I2U(GetStoredInteger(udg_GC,H2S(tm),"u2"))
       local real dis = GetStoredReal(udg_GC,H2S(tm),"dis")
       local real xy = GetStoredReal(udg_GC,H2S(tm),"xy")
       local string ef = GetStoredString(udg_GC,H2S(tm),"ef")
       local integer abi = GetStoredInteger(udg_GC,H2S(tm),"ability")
       local real an = GetUnitAngle(u1,u2)
       local effect eff
       if (GetUnitX(u1)+dis*Cos(an))<GetRectMaxX(bj_mapInitialPlayableArea)     then
               if   (GetUnitX(u1)+dis*Cos(an))>GetRectMinX(bj_mapInitialPlayableArea)   then
                         call SetUnitX(u1,GetUnitX(u1)+dis*Cos(an))
                         endif
               endif
       if (GetUnitY(u1)+dis*Sin(an))<GetRectMaxY(bj_mapInitialPlayableArea) and (GetUnitY(u1)+dis*Sin(an))>GetRectMinY(bj_mapInitialPlayableArea)       then
               call SetUnitY(u1,GetUnitY(u1)+dis*Sin(an))
               endif
       if ef != null then
               set eff=AddSpecialEffect(ef,GetUnitX(u1),GetUnitY(u1))
               call DestroyEffect(eff)
               set eff = null
               endif
//这是伤害部分,掠过先       call FullDamageRange(u1,GetUnitX(u1),GetUnitY(u1),200,abi,xy,2)
       if ( 40000.00 >= ( Pow( (GetUnitX(u1) - GetUnitX(u2)), 2.00) + Pow(( GetUnitY(u1) - GetUnitY(u2) ), 2.00) ) ) then
               call FlushTable(tm)
               call PauseTimer(tm)
               call DestroyTimer(tm)
              
       endif
       set tm = null
       set u1 = null
       set u2 = null
       set eff = null
endfunction
function  hg_skillmode1 takes unit u1,unit u2,real speed,string ef,real xs returns nothing
       local timer tm = CreateTimer()
       local real tim = 0.02
       local real dis = speed*tim
       local real xy = xs*speed/1000
       local real time = GetUnitDistance(u1,u2)/speed
       call StoreInteger(udg_GC,H2S(tm),"u1",H2I(u1))
       call StoreInteger(udg_GC,H2S(tm),"u2",H2I(u2))  
       call StoreReal(udg_GC,H2S(tm),"dis",dis)
       call StoreReal(udg_GC,H2S(tm),"xy",xy)
       call StoreString(udg_GC,H2S(tm),"ef",ef)
       call StoreInteger(udg_GC,H2S(tm),"ability",GetSpellAbilityId())  
       call TimerStart(tm,0.02,true,function hg_skillmode1_action)
//       call FlushTable(tm)
//       call PauseTimer(tm)
//       call DestroyTimer(tm)
       set tm=null  
endfunction
[/codes]
发表于 2008-10-29 14:42:53 | 显示全部楼层
游戏缓存是否建立了...
还有
//             call FlushTable(tm)
//             call PauseTimer(tm)
//             call DestroyTimer(tm)
这里这里明确不用...
不然计时器就没有了...
虽然你打了//

还有就是 看看公式里是否有问题..
会不会出现除数为0的情况

不过你这个移位函数 似乎写的有点太复杂了..
我记得这个东西没这么烦啊
回复

使用道具 举报

 楼主| 发表于 2008-10-29 15:11:20 | 显示全部楼层
我的原函数里就打了这个东西//
而且第一次做在
//             call FlushTable(tm)
//             call PauseTimer(tm)
//             call DestroyTimer(tm)
前还有个等待函数的
等待时间是(time)
游戏里有缓存的,是udg_GC
除数为0的情况不存在,
移位函数 似乎写的有点太复杂了..的原因是因为这是技能模板啊,不只是移动函数。所以参数比较多呵
回复

使用道具 举报

发表于 2008-10-29 15:17:34 | 显示全部楼层
我说建立缓存了么...
不是是否建立变量了

就这么说把...
新建缓存(XXXXXXXX)
设置udg_GC=最后创造的缓存

你有做么

还有通过....本人的实践发现...
做模块并不是什么好办法...

过多的模块只是同过牺牲效率的办法来 换取 有限的方便和不多的储存空间....
而且很多时候 模块书写很烦杂 实现的功能却很难满足多种需要.

试想一下 你什么东西都用模块函数实现的话...
那你将陷入 函数套函数的无限循环中....
效率自然也下降了
回复

使用道具 举报

 楼主| 发表于 2008-10-29 15:35:04 | 显示全部楼层
这个倒是真的忘了,谢谢啊。不过你去看看VC++的MFC就知道什么叫做模块调用了,但并没有牺牲很多效率。反而让很多东西方便的多
回复

使用道具 举报

发表于 2008-10-29 15:40:16 | 显示全部楼层
.反正我认为模块用的越多...
东西就越来越傻瓜...
(为什么有些东西叫做傻瓜机...原因就是 你要用的一切 人家都通过模块的方式给你做好了....你能很方便的使用....但是你不能改变什么....)
限制就越来越多....
越是底层的东西开放性越大...
回复

使用道具 举报

 楼主| 发表于 2008-10-29 15:51:51 | 显示全部楼层
修改原代码啊,就可以让功能强大了。对每一个要用的函数先复制下来,再根据需要修改,就很方便了。而且别人做的代码可能比自己做的好的,比如在算法啦,精简啦,一些方面
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 点一下

本版积分规则

Archiver|移动端|小黑屋|地精研究院

GMT+8, 2024-5-2 09:25 , Processed in 0.126636 second(s), 18 queries .

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表