[jass]
globals
gamecache GC = null
endglobals
//缓存创建
function CacheValue takes nothing returns gamecache
if GC == null then
call FlushGameCache(InitGameCache("WOW8.w3v"))
set GC = InitGameCache("WOW8.w3v")
endif
return GC
endfunction
//句柄转换
function H2I takes handle h returns integer
return h
return 0
endfunction
function I2H takes integer i returns handle
return i
return null
endfunction
function I2U takes integer i returns unit
return i
return null
endfunction
//缓存操作
function FlushCache takes integer i, string s returns nothing
call FlushStoredInteger(CacheValue(),I2S(i),s) //清除缓存
endfunction
function setint takes handle i, string s, integer int returns nothing
call StoreInteger(CacheValue(),I2S(H2I(i)),s,int) //保存整数
endfunction
function setunit takes handle i, string s, unit u returns nothing
call StoreInteger(CacheValue(),I2S(H2I(i)),s,H2I(u)) //保存单位
endfunction
function getint takes handle i, string s returns integer
return GetStoredInteger(CacheValue(),I2S(H2I(i)),s) //获取缓存内的整数
endfunction
function getunit takes handle i, string s returns unit
call DisplayTextToPlayer(Player(0),0,0,"1")
return I2U(GetStoredInteger(CacheValue(),I2S(H2I(i)),s)) //获取缓存内的单位
endfunction
function DT takes nothing returns nothing
local location p
local unit u
set p = GetRectCenter(GetPlayableMapRect()) //获取地图中心点
//在地图中心给玩家1创建一个农民,面对默认角度
set u = CreateUnitAtLoc(Player(0),'hfoo',p,bj_UNIT_FACING) //设置u为最后创建的单位
set p = null //清除点p
call setunit(u,"aa",u)
call DisplayTextToPlayer(Player(0),0,0,UnitId2StringBJ(GetUnitTypeId(getunit(u,"aa"))))//对玩家显示单位的名字
call DisplayTextToPlayer(Player(0),0,0,"hello world")
set u = null //清除单位变量u
endfunction
function InitTrig_display takes nothing returns nothing
set gg_trg_display = CreateTrigger() //创建触发器
call TriggerRegisterPlayerChatEvent(gg_trg_display,Player(0),"display",true) //创建玩家输入匹配事件
call TriggerAddAction(gg_trg_display,function DT)
endfunction
[/jass]
最终代码- -...解决了- -
原来
set u = LastCreateUnit()
无法获取啊- -
set u = CreateUnitAtLoc()
才可以啊...终于结束了这个问题- -
从中学到- -
globals 里 声明变量
导出 .j 脚本查看运行原理
set u = CreateUnitAtLoc()
是无法获取的- -
变量赋初始值会导致跳出运行如
[jass]
globals
gamecache CG
endglobals
function test takes nothing returns noting
if CG == null then
.....
endif
endfunction
[/jass]
在 if CG == null 处 出错 |