admin管理员组文章数量:1384254
Godot - GDscript provides us with a callv
method:
Calls the method represented by this Callable. Unlike
call()
, this method expects all arguments to be contained inside thearguments
Array.
I'm trying to use implement some CONST's for my randf_range
call:
So instead off
rng.randf_range(0.1, 0.3)
I'm using:
const RANGE = [ .1, .3 ]
rng.randf_range.callv(RANGE)
However, this always results the TO value as you can see in this mre:
const RANGE = [ .1, .3 ]
var rng = RandomNumberGenerator.new()
rng.seed = hash("HuH")
for i in range(3):
print('%d -> %f' % [ i, rng.randf_range.callv(RANGE) ])
rng = RandomNumberGenerator.new()
rng.seed = hash("HuH")
for i in range(3):
print('%d -> %f' % [ i, rng.randf_range(RANGE[0], RANGE[1]) ])
Outputs:
0 -> 0.300000
1 -> 0.300000
2 -> 0.300000
0 -> 0.214059
1 -> 0.191159
2 -> 0.203312
Why is that?
GDScript Playground
Godot - GDscript provides us with a callv
method:
Calls the method represented by this Callable. Unlike
call()
, this method expects all arguments to be contained inside thearguments
Array.
I'm trying to use implement some CONST's for my randf_range
call:
So instead off
rng.randf_range(0.1, 0.3)
I'm using:
const RANGE = [ .1, .3 ]
rng.randf_range.callv(RANGE)
However, this always results the TO value as you can see in this mre:
const RANGE = [ .1, .3 ]
var rng = RandomNumberGenerator.new()
rng.seed = hash("HuH")
for i in range(3):
print('%d -> %f' % [ i, rng.randf_range.callv(RANGE) ])
rng = RandomNumberGenerator.new()
rng.seed = hash("HuH")
for i in range(3):
print('%d -> %f' % [ i, rng.randf_range(RANGE[0], RANGE[1]) ])
Outputs:
0 -> 0.300000
1 -> 0.300000
2 -> 0.300000
0 -> 0.214059
1 -> 0.191159
2 -> 0.203312
Why is that?
GDScript Playground
Share Improve this question edited Mar 18 at 17:11 0stone0 asked Mar 18 at 17:04 0stone00stone0 44.5k5 gold badges52 silver badges80 bronze badges1 Answer
Reset to default 1This is open Issue 93600:
Callable.callv()
will make call with wrong arguments if aconst
Array
is passed
The workaround is to make the array mutable or duplicate()
it when you use it. callv
will not make changes to it either way:
var RANGE = [ .1, .3 ]
# ^^^
or
const RANGE = [ .1, .3 ]
# ...
print('%d -> %f' % [ i, rng.randf_range.callv(RANGE.duplicate()) ])
# ^^^^^^^^^^^^
本文标签: godotrandfrange called with callv always returns upper limitStack Overflow
版权声明:本文标题:godot - randf_range called with callv always returns upper limit - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744500221a2609278.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论