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

Join method for PackedStringArray is not exists #38526

Closed
toby3d opened this issue May 7, 2020 · 1 comment · Fixed by #38548
Closed

Join method for PackedStringArray is not exists #38526

toby3d opened this issue May 7, 2020 · 1 comment · Fixed by #38548

Comments

@toby3d
Copy link
Contributor

toby3d commented May 7, 2020

Godot version: 112884d
OS/device including version: Linux 5.6.7-1-MANJARO
Issue description: After renaming class PoolStringArray (Godot 3.0+) to PackedStringArray (Godot 4.0+), the join method was lost.
Minimal reproduction project:

const uppercase: String = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
const lowercase: String = "abcdefghijklmnopqrstuvwxyz"
const alphabetic: String = uppercase + lowercase
const numeric: String = "0123456789"
const alphanumeric: String = alphabetic + numeric

# Generate fixed-sized string with charset symbols
func string(length: int, charset: String = alphanumeric) -> String:
	randomize()

	var output: PackedStringArray

	while output.size() < length:
		output.append(charset[randi() % charset.length()])

	return output.join("") # The method "join" isn't declared on base "PackedStringArray"
@kuruk-mm
Copy link
Contributor

kuruk-mm commented May 7, 2020

As you said, this issue is from the rename of PoolStringArray to PacketStringArray, when reduz changed PoolVector to Vector on #36311

I read #36311 and see the changed syntax on the Engine for the joins on the code is:
String(delimiter).join(parts)

e.g in your case: String("").join(output)

So I made a PR with this change to give the ability to join a PacketStringArray to String

Tested code:

extends Node2D

const uppercase: String = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
const lowercase: String = "abcdefghijklmnopqrstuvwxyz"
const alphabetic: String = uppercase + lowercase
const numeric: String = "0123456789"
const alphanumeric: String = alphabetic + numeric

func _ready() :
	print(string(10))
	

# Generate fixed-sized string with charset symbols
func string(length: int, charset: String = alphanumeric) -> String:
	randomize()

	var output: PackedStringArray

	while output.size() < length:
		output.append(charset[randi() % charset.length()])

	return String("").join(output)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants