Created
October 25, 2020 02:25
-
-
Save me2beats/9787a2278aa325e31edbd5b7ddabb719 to your computer and use it in GitHub Desktop.
test Godot custom iterators
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class_name NodeWalk | |
extends StackIterator | |
func _init(node).(node): | |
pass | |
func _iter_(current): | |
for i in current.get_children(): | |
stack.push_back(i) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class_name StackIterator | |
var stack = [] | |
var current | |
func _init(node:Node): | |
stack.append(node) | |
func _iter(): | |
current = stack.pop_back() | |
if current == null: | |
return false | |
_iter_(current) | |
return true | |
# override it | |
func _iter_(current): | |
pass | |
func _iter_init(_arg): | |
return _iter() | |
func _iter_next(_arg): | |
return _iter() | |
func _iter_get(_arg): | |
return current |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Questions:
answers: