找回密码
 点一下
楼主: 麦德三世B

[无聊]无聊的研究内容,对象的Handle数值占位

[复制链接]
发表于 2006-4-2 11:31:33 | 显示全部楼层
栈是后入先出的

而浮动文字可以随时删除 & 随时重复利用Handle
所以应该是数组

只不过它是从99递减而已
回复

使用道具 举报

发表于 2006-4-2 11:37:44 | 显示全部楼层
奇怪
为什么我测试的浮动文字的Handle最小能为0

[trigger]
Test
    事件
        Player - 玩家 1 (红色) skips a cinematic sequence
    环境
    动作
        Floating Text - Create floating text that reads (String(g_iCount)) above 血魔法师 0001 <gen> with Z offset 0.00, using font size 10.00, color (100.00%, 100.00%, 100.00%), and 0.00% transparency
        Custom script: set udg_iTemp = H2I(bj_lastCreatedTextTag)
        Game - Display to (All players) the text: ((([Test  + (String(g_iCount))) + ] ) + (String(iTemp)))
        -------- Next --------
        Set g_iCount = (g_iCount + 1)
[/trigger]

[ 本帖最后由 zyl910 于 2006-4-2 12:15 编辑 ]
回复

使用道具 举报

 楼主| 发表于 2006-4-2 11:39:40 | 显示全部楼层
0就是 null啊,空的handle显然不会有所代表的texttag阿
回复

使用道具 举报

发表于 2006-4-2 12:11:08 | 显示全部楼层
0号浮动文字也是有效的


[trigger]
Test2
    事件
        Player - 玩家 1 (红色) skips a cinematic sequence
    环境
    动作
        Set I = 0
        For each (Integer A) from 0 to 10, do (Actions)
            Loop - 动作
                For each (Integer B) from 0 to 9, do (Actions)
                    Loop - 动作
                        Set ptTemp = ((Position of 血魔法师 0001 <gen>) offset by ((0.00 + (128.00 * (Real((Integer B))))), (-128.00 - (64.00 * (Real((Integer A)))))))
                        Floating Text - Create floating text that reads (String(I)) at ptTemp with Z offset 0.00, using font size 10.00, color (100.00%, 100.00%, 100.00%), and 0.00% transparency
                        Custom script: set udg_iTemp = H2I(bj_lastCreatedTextTag)
                        Floating Text - Change text of (Last created floating text) to ((String(I)) + (( + ((String(iTemp)) + )))) using font size 10.00
                        Floating Text - Change (Last created floating text): 不允许 permanence
                        Floating Text - Change the lifespan of (Last created floating text) to 10.00 seconds
                        -------- Next --------
                        Set I = (I + 1)
[/trigger]
回复

使用道具 举报

发表于 2006-4-5 00:38:44 | 显示全部楼层
0和空不是一个概念。。。。
回复

使用道具 举报

 楼主| 发表于 2006-4-5 17:32:16 | 显示全部楼层
呃,貌似在jass的handle里,这两个东西多半是一样的……
回复

使用道具 举报

发表于 2006-4-5 18:16:48 | 显示全部楼层
我现在把Jass中的数据类型分成以下几类:
Base:基本数据类型。自动释放。就是这五个:boolean、integer、real、string、code
Enum:利用handle存放为常量。不需释放。如:playercolor
Index:利用handle存放某个内部数组中的项目索引。需要释放。由于可以为0,不需设为null。如:lightning、texttag
Object:对象的引用。需要释放,需要设为null,0就是null。如:timer、unit

[ 本帖最后由 zyl910 于 2006-4-5 18:17 编辑 ]
回复

使用道具 举报

发表于 2006-4-5 18:19:16 | 显示全部楼层
貌似我不知道怎么写那个\"H2I\"。郁闷。随便写写WE居然挂掉了。
不理了。去学校。
回复

使用道具 举报

发表于 2006-4-5 18:22:58 | 显示全部楼层
http://jass.sourceforge.net/doc/retbug.shtml
Type casting

Type casting is possible in JASS by making use of what is called the return bug.

The return bug

Warcraft 3\'s JASS compiler and the world editor\'s parser allow return values different from the last return value of a function to be of any type no matter the return type it is supposed to return.

A classic example of the return bug is the following:

function H2I takes handle h returns integer
    return h
    return 0
endfunction

As you should note, the return value of the function is integer, last return statement returns 0, but actually, the only return value the function will consider is return h , it will return the handle argument it just took.

This function will take a handle argument and return an integer that is the pointer to that handle.

function I2H takes integer i returns handle
    return i
    return null
endfunction

This function will do the opposite it will take an integer and return the handle that is at the memory position the integer is pointing. It is also possible to type cast a handle value into a value of a handle descendant type:

function Handle2Unit takes handle h returns unit
    return h
endfunction

Note that in this case, an extra return statement is not required.

As for the handle type, you can retrieve a handle descendant type value from an integer.

function I2Item takes integer i returns item
    return i
    return null
endfunction

You can also type cast between different handle derived types, even if they don\'t share the same descendace tree.

function Unit2Item takes unit u returns item
    return u
    return null
endfunction
There is no logic for doing this unless you want to save a value of certain handle derived type in a variable of another handle derived type. Doing this for the arguments of native functions is the same as giving them null values.

Type casting also works between native types, with some considerations.

function Real2Int takes real r returns integer
    return r
    return 0
endfunction

If you are familiar with JAVA, you would assume this opperation will trunc the real, but that\'s not the case. The return value is different from the argument, and you can retrieve the real back with the inverse of this function, but it will crash if you give it a wron value.

function String2Int takes string s returns integer
    return s
    return 0
endfunction

Will return the pointer to the given string. Be careful with this operation, it seems that strings are recycled when they are no longer used by variables, and it won\'t consider typecasted integers. The inverse function will crash if you give it a wrong value.

Type casting between boolean and integer, will represent 1 for true and 0 for false,

Also, consider that the function that performs the type casting does not have to follow the patern of the functions stated here to work. The only thing required is the return value bug abuse.

For example:

function GetArrayMemberAsUnit takes integer i returns unit
    return udg_IntegerArray[ i ]
    return null
endfunction

function GetDyingDestructable takes nothing returns destructable
    return GetTriggerWidget()
endfunction

Also take advantage of the return bug. As a matter of fact GetDyingDestructable is a function from blizzard.j.

[ 本帖最后由 zyl910 于 2006-4-5 18:24 编辑 ]
回复

使用道具 举报

发表于 2006-4-5 18:26:41 | 显示全部楼层
我刚刚是这样:
function H2I takes handle tmp_h returns integer
    return tmp_h
endfunction

然后就出错老。
回复

使用道具 举报

发表于 2006-4-5 18:30:06 | 显示全部楼层
呃。原来是。要加那个return 0才不会出错。嗯嗯。知道老。安心去上课。。
回复

使用道具 举报

发表于 2006-4-5 18:30:58 | 显示全部楼层
还要再写个return
[jass]function H2I takes handle tmp_h returns integer
    return tmp_h
    return 0
endfunction[/jass]



要不然怎么叫“return bug”呢
回复

使用道具 举报

发表于 2006-4-5 18:31:30 | 显示全部楼层
http://bbs.uuu9.com/viewthread.php?tid=228807
【重要】Jass中的已知bug(翻译完成)

声明:本文原文来自Wc3c,版权归该网站所有。
感谢onlyxuyang的大力帮助,翻译了大部分内容。

原文
这篇文章打算对我们目前所知的JASS的BUG做出一个列表。在这里将会列出在暴雪的解析器以及在本地函数(natives)出现的BUG,但是出现在Blizzard.j和用户自定义函数中的BUG就不会列出来了。WC3中的BUG也不会列出来。
注意:这个列表是为魔兽资料片(1.20)中的JASS写的。
这篇文章的主要意图是帮助大家,同时避免论坛被相同的问题塞满。它包括了对BUG的大体描述以及对这些BUG进行了详细描述的文章的链接。如果有工具可以解决这些问题,这些工具的链接也会同时给出来(在使用前请先阅读该工具的ReadME文件)。
如果你发现有的BUG没有列出来,请把它回复在下面或者给我发短消息让我来添加它。

一般BUG

因为缺少endif和endloop而导致程序崩溃
当你存储地图的时候如果存在没有结尾的循环和条件,WE将崩溃。
我推荐JassCraft:
JassCraft

在存储时错误的整型变量引起崩溃
错误的整型变量,例如rawrodes,会在存储地图的时候令WE崩溃。\'&AElig;?po\' 就是会引起崩溃的一个实例。

在文件名中使用单斜线(\\)在保存时将导致程序崩溃。
无论什么时候当你想在字符串中包含一个\"\\\"时请使用\"\\\\\",其中一个是用来当转义符的.在实际显示的以后只会显示一个.

应该有返回值的函数却没有返回一个值
如果你的函数应该有返回值但是你没有返回一个值,保存的时候程序将崩溃。

错误定位不准
WE识别不出来一些BUG,所以当WE报错时的位置不一定是错误真实的位置.这个问题没有办法解决,你只能在报错的时候检查错误附近的语句。这种错误一般是,举个例子,是由于你的endfunction拼写错误.

字符串限制
如果你的字符串超过了860个字符,在保存的时候系统会报错。解决的方法就是你不要过多的使用字符串的串联。
更多信息

返回值BUG
这是一个非常有用的BUG.WE只检测最后一个return语言返回的值的类型.所以你可以转换,举个例子来说,可以十分方便地把handle型转换成integer型.下面就是这个传奇般的函数:
JASS:
function H2I takes handle h returns integer
    return h
    return 0
endfunction

这个BUG被给予的赞美早已经使它不象是个BUG,因为它允许你将固定的类型存储在其他的变量中,它给了我们更多的自由。
想详细了解它的话请翻看有关文章。
更多信息
教程: 使用局部句柄变量函数
修复一个可能在使用返回值bug时出现的问题

同名变量的覆盖
这个bug非常烦人, 例如,你可以让参数和一个局部变量有同一个名字。最后声明的那个同名变量,也就是局部变量,将会保留它的引用(即有效),如果你不知道这点的话,这将会让你的脚本变得混乱
但是,同时这个bug可以用来让界面多实例化(仅仅在一定程度上)
更多信息

在特定的操作系统上自定义脚本有一些限制
自定义脚本在一些操作系统上会有些限制。主要是在windows98和ME上,其他的也许也有。
解决的办法是在编译其他的触发器前先创造一个触发器,所以你可以在这个触发器里面写你的自定义代码.有一个工具可以实现它,这样就允许了在使用混乱王座的时候也有地方写大量的触发器。
First Trigger Adder

有SP2补丁的XP和没有补丁的XP
Yes, this is true and probably the dumbest bug ever.
Several things acts different on computers with SP2 than on computers without. We have no good explanation for this. Thing is that this is so bad that it even can cause desyncs in some cases.
某些情况下游戏会不出声,但是是哪种情况下也没有说,而且也没有给出解决方法

单独的\"%\"在保存地图的时候将被从自定义代码中除去
单独的\"%\"在保存地图的时候会被从自定义代码中除去,但是它只发生在自定义代码中.解决的办法是,使用\"%%\"来代替,这样移除的时候只有第一个\"%\"会被除去。

本地函数相关 bug

IsUnitType 布尔表达式bug
当你在布尔表达式中使用IsUnitType(whichUnit, whichUnitType) 而不比较真或假时,会出现bug。
更多信息

游戏缓存限制
你可以有最多(实际是bug)256个游戏缓存, 所以,如果你的个人档案缓存(campaigns.w3v)中有256个缓存时,将会让你的地图变得很奇怪
更多信息

已销毁的定时器会过期
目前看来,在非过期函数(触发器)以外的函数(触发器)中销毁的定时器仍然会过期。解决方法是在销毁定时器之前先暂停它。
更多信息

SetUnitX 和 SetUnitY 会崩溃
如果你把坐标放在可用地图区域之外(即bj_mapInitialPlayableArea 的初始值之外),使用本地函数SetUnitX/SetUnitY 就会造成游戏崩溃。 解决方法是在调用这个函数之前检查坐标所在范围。

在可用地图区域之外创建单位会造成游戏崩溃
在可用地图区域之外创建单位 (即bj_mapInitialPlayableArea 的初始值之外) 会造成崩溃。解决方法是在调用这个函数之前检查坐标所在范围。

RestoreUnit 忽略类型保护
本地函数 RestoreUnit 似乎会对返回的单位忽视类型保护, 因此使用不正确的话会造成游戏崩溃(with typecasting(不知道怎么翻译,请知道的告诉我J)).
更多信息

GroupEnumUnitsInRectCounted 和 GroupEnumUnitsInRangeCounted
当使用在大量的单位上时,这两个本地会出现无规律的行为

ExecuteFunc限制
ExecuteFunc在搜索需要的脚本上时有一个愚蠢的错误, 当调用ExecuteFunc 的函数和被执行的函数之间的距离超过一定行数后,就会超时,然后什么都不做。
回复

使用道具 举报

发表于 2006-4-5 23:24:11 | 显示全部楼层
虽然汉化得不是很完美。不过基本看懂了。。嗯。3Q。
回复

使用道具 举报

发表于 2006-4-8 10:19:38 | 显示全部楼层
这个BUG是很有用的
回复

使用道具 举报

发表于 2006-5-22 16:18:55 | 显示全部楼层
好像偏题了
凑字凑字~
回复

使用道具 举报

发表于 2012-2-9 05:29:47 | 显示全部楼层
最近大家都沒有看後面的文章 精華文章 不能下沉...
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-5-2 20:30 , Processed in 0.112901 second(s), 17 queries .

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

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