0 votes
func bit_and(x:Bitset) -> Bitset:
var ret = Bitset.new(max(bits, x.bits))
for i in range(min(bitmasks.size(), x.bitmasks.size())):
    ret.bitmasks[i] = bitmasks[i] & x.bitmasks[i]
return ret
func bit_or(x:Bitset) -> Bitset:
var ret = Bitset.new(max(bits, x.bits))
for i in range(min(bitmasks.size(), x.bitmasks.size())):
    ret.bitmasks[i] = bitmasks[i] | x.bitmasks[i]
return ret
func bit_xor(x:Bitset) -> Bitset:
var ret = Bitset.new(max(bits, x.bits))
for i in range(min(bitmasks.size(), x.bitmasks.size())):
    ret.bitmasks[i] = bitmasks[i] ^ x.bitmasks[i]
return ret
func setminus(x:Bitset) -> void:
for i in range(bitmasks.size()):
    bitmasks[i] = bitmasks[i] ^ (bitmasks[i] & x.bitmasks[i])

Here's the code I used. But obviously I am now facing the problem of cyclic reference. How can I solve this problem and realize the functions I want.

Godot version 3.5
in Engine by (19 points)

1 Answer

0 votes
Best answer

Unfortunately this is a limitation in gdscript. You can do references to other objects, but can't use static typing in this case. You can load a reference to the other script runtime and do checks. While it works, of course you won't get autocompletion from that class.

var Bitset = load("res://PATH-TO-bitset.gd")
...
if x is Bitset:
    # This check should work
...
var x : Bitset # This doesn't work

Second option is to use duck typing.

In Godot 4 this problem will be gone.

by (1,094 points)
selected by

Thank you for you help.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.