Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

There is no example of using bsearch_custom in the documentation #4564

Closed
Arnklit opened this issue Jan 20, 2021 · 3 comments
Closed

There is no example of using bsearch_custom in the documentation #4564

Arnklit opened this issue Jan 20, 2021 · 3 comments
Labels
area:class reference Issues and PRs about the class reference, which should be addressed on the Godot engine repository enhancement

Comments

@Arnklit
Copy link
Contributor

Arnklit commented Jan 20, 2021

Your Godot version:
3.2.3.Stable

Issue description:
There is no example of using bsearch_custom in the documentation. You need to pass it a custom function, but without an explanation of what parameters and return values it expects I haven't been able to get it to work. I assume it's very similar to sort_custom which does have an example, but what I've tried doesn't work.

URL to the documentation page (if already existing):
https://docs.godotengine.org/en/3.2/classes/class_array.html#class-array-method-bsearch-custom

@Calinou Calinou added the area:class reference Issues and PRs about the class reference, which should be addressed on the Godot engine repository label Jan 20, 2021
@hungrymonkey
Copy link
Contributor

hungrymonkey commented Feb 19, 2021

I will write it. The object thing is quite odd but i figured it out

extends Node

# Declare member variables here. Examples:
# var a = 2
# var b = "text"

var custom = preload("Custom.gd")
# Called when the node enters the scene tree for the first time.
func compare(a,b):
	return a.getV() < b.getV()

func _ready():
	print("start")
	var p = custom.new()

	p.setV(8)
	var c = [custom.new(), custom.new(), custom.new(), custom.new(), 
		custom.new(), custom.new(), custom.new(), custom.new(), custom.new(),
		custom.new(), custom.new(), custom.new(), custom.new(), custom.new(), custom.new()]
	for i in c.size():
		c[i].setV(i + 1)
	

	print(c.bsearch_custom(p, self, "compare", true))
	print("done")
extends Object


var val = 0

func _ready():
	pass # Replace with function body.
	
func setV(a):
	val = a

func getV():
	return val
	
func _to_string():
	return String(val)
	
func compare(a, b):
	return a.getV() < b.getV()

hungrymonkey added a commit to hungrymonkey/godot-docs that referenced this issue Feb 19, 2021
bsearch_custom arguments

name - type - description
value - Variant - bisection search value
obj - Any object instance - Location of the 2 argument comparison function
func - String - Name of the function declared in obj
before - boolean - first and second resolver

This function is pr against the 3.x series because pr #45698 changed
the call signature to
bsearch_custom, sarray("value", "func", "before"), varray(true));

Closes godotengine#4564
hungrymonkey added a commit to hungrymonkey/godot that referenced this issue Feb 22, 2021
bsearch_custom arguments

name - type - description
value - Variant - bisection search value
obj - Any object instance - Location of the 2 argument comparison function
func - String - Name of the function declared in obj
before - boolean - first and second resolver

This function is pr against the 3.x series because pr#45698 changed
the call signature to
bsearch_custom, sarray("value", "func", "before"), varray(true));

godotengine/godot-docs#4564
hungrymonkey added a commit to hungrymonkey/godot that referenced this issue Feb 22, 2021
name - type - description
func - callable - compare function object
before - boolean - first and second resolver

godotengine/godot-docs#4564
hungrymonkey added a commit to hungrymonkey/godot that referenced this issue Feb 22, 2021
name - type - description
func - callable - compare function object
before - boolean - first and second resolver

godotengine/godot-docs#4564
@KoBeWi KoBeWi closed this as completed Feb 26, 2021
@donn-xx
Copy link

donn-xx commented Mar 8, 2024

FYI: In 4.3.dev there is still actual no example for bsearch_custom in the help.

@KoBeWi
Copy link
Member

KoBeWi commented Mar 8, 2024

The example was added in 3.x branch: godotengine/godot@1716423
Not sure why it wasn't ported to master (4.x), it might need some tweaks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:class reference Issues and PRs about the class reference, which should be addressed on the Godot engine repository enhancement
Projects
None yet
Development

No branches or pull requests

5 participants