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

一个关于UnionBug-H2I function的想法……

[复制链接]
发表于 2009-3-31 16:43:16 | 显示全部楼层 |阅读模式
(被自己忍无可忍的和谐掉了)

最近看到橙子(如果我没记错的话)的《UnionBug之忽略大小写》~~

发现貌似这个特点可以减少代码量~~
改进后的用UnionBug的函数:
[codes=jass]globals
    handle H = null
endglobals

function Afunciton takes handle The_Handle, ... returns ...
    local handle H = The_Handle
    local integer h
    ...
endfunction[/codes]
然后又做了个UnionBug-H2I:
[codes=jass]globals
    handle H = null
endglobals

constant function H2I takes handle H returns integer
    local integer h
    return h
endfunction[/codes]
(恩~很神奇吧~居然能加constant…………)
(被自己忍无可忍的和谐掉了)
 楼主| 发表于 2009-3-31 16:51:18 | 显示全部楼层
当然不知道takes handle H能不能奏效……所以第一个更好吧~~~
回复

使用道具 举报

发表于 2009-3-31 18:00:45 | 显示全部楼层
很明显,两个都是错的...

橙子当时没有提及类型转换的情况,所以有些东西你可能不知道.
[jass]
globals
    integer I
    handle H
endglobals

function Func01 takes integer i returns integer
    local handle H=CreateTimer()
    return i
endfunction

function Func02 takes nothing returns integer
    local integer I
    local integer i
    local handle H=CreateTimer()
    return i
endfunction

function Func03 takes integer i, integert I returns integer
    return i
endfunction

function Func04 takes integer h, handle H returns integer
    return h
endfunction
[/jass]
调用Func01会返回那个传入的i值;
调用Func02会返回那个Timer的Handle值;
调用Func03会返回I的值(这就是橙子得出的结果);
Func04加入地图中会进不去游戏,意味着只用一个全局变量来转换数据是不可能的.

看你写的函数,说明你对Union Bug还不是很熟悉.你这样写是先对H变量赋值,再创建h变量,这里integer类型的h是不会存储有Handle类型的H的值的.
回复

使用道具 举报

发表于 2009-3-31 18:36:20 | 显示全部楼层
如果楼主看过我导航帖中关于Union Bug的帖子的话

就不会发这贴了~~
[jass]
globals
       handle H = null
       integer I=0
endglobals

function U2I takes integer I, handle H returns integer
return I
endfunction
[/jass]
回复

使用道具 举报

发表于 2009-3-31 22:54:23 | 显示全部楼层
忽略大小写的 前提是..先已经出现union bug
=_=
回复

使用道具 举报

 楼主| 发表于 2009-4-2 17:07:34 | 显示全部楼层
(被自己忍无可忍的和谐掉了)
不过UnionBug的原理是什么呢?
回复

使用道具 举报

发表于 2009-4-2 20:03:20 | 显示全部楼层
头目有个帖子
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-5-2 14:01 , Processed in 0.090700 second(s), 18 queries .

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

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