0 votes

im trying to turn several comma seperated strings into arrays, then use those arrays in order to make many strings.
string output order does not matter.
EXAMPLE:
var Sep = ""
var Prefix="apple,banana"
var Name="good,bad"
var suffix="mine,yours"
OUTPUT:
apple
goodmine
apple
goodyours
apple
badmine
apple
badyours
banana
goodmine
banana
goodyours
banana
badmine
banana
bad_yours

After a lot of trying. my current code is below.
also sorry if i didnt add the sample correctly.

`onready var PREFIX = $V/H2/PREFIXEdit.text
onready var NAME = $V/H3/NAME
Edit.text
onready var SUFFIX = $V/H4/SUFFIX_Edit.text

onready var PreJson=tojson(PREFIX.split(","))
onready var NameJson=to
json(NAME.split(","))
onready var SuffixJson=to_json(SUFFIX.split(","))

onready var PreArray=parse_json(PreJson)

onready var NameArray=parse_json(NameJson)

onready var SuffixArray=parse_json(SuffixJson)

onready var AllNames:Array = []

func ready() -> void:
var Count = 0
var PreArray:Array=[PreJson]
var NameArray:Array=[NameJson]
var SuffixArray:Array=[SuffixJson]
for A in PreArray:
for B in NameArray:
for C in SuffixArray:
var NewName = str(PreArray[Count])+"
"+str(NameArray[Count])+"_"+str(SuffixArray[Count])
#AllNames.append(NewName)
print(NewName)
Count += 1`
enter code here

Godot version 3.5
in Engine by (58 points)

the 3 lines of big text were commented out. idk why they are so big now. i only just noticed that the paste messed up all the Tabbed code. if needed i can add a picture.

1 Answer

+1 vote

This ok for you?

var prefix = ["apple", "banana"]
var adjective = ["good", "bad"]
var suffix = ["mine", "yours"]

func make_string():
    for p in prefix:
        for a in adjective:
            for s in suffix:
                print(p+a+s)

OUTPUT:

applegoodmine
applegoodyours
applebadmine
applebadyours
bananagoodmine
bananagoodyours
bananabadmine
bananabadyours
by (1,789 points)

my problem still persists. ive made a video showing the issue im still having.
what my code looks like

please watch if you can. my code is still broken.

Oh, so cool you made a YouTube video! Thanks for that, cleared it up nicely (I hope!). Sorry for misunderstanding, the formatting made it hard to follow.

Not the prettiest / most efficient code I've ever written... I didn't want to spend more than a few mins on it, bit busy. Maybe someone kind can tidy up the csv_to_array method. Anyway, it works.

func csv_to_array(csv):
    var array = []
    var item = ""
    for i in csv:
        if i == " ":
            continue
        if i == ",":
            array.append(item)
            item = ""
        else:
            item += str(i)
    array.append(item)
    return array

func _ready():
    var prefix_csv = "apple, banana"
    var adjective_csv = "good, bad"
    var suffix_csv = "mine, yours"

    var prefix = csv_to_array(prefix_csv)
    var adjective = csv_to_array(adjective_csv)
    var suffix = csv_to_array(suffix_csv)

    for p in prefix:
        for a in adjective:
            for s in suffix:
                print(p+a+s)

Output as before.

Btw, the trick to formatting is highlighting the section of code you want to format and then clicking on the curly braces.

Thanks so much, it never occured to me to seperate the split function from the print function. and the csv code is still good. no need to pretty it up. i do have to change a couple things but it will work perfectly.

just tried it and it does work. thanks a million DM

Ah, delighted it did the job for you. Parsing is a bit of dark art, I should have used RegEx really but let's call it a win.

this project is just a learning experience to me. im learning to code and learning gd script with this project. i have a gold fishes memory (Accident when i was a young child) so its taking me forever to do basic things.

i said all that because idk what regex is. now i need to work on configs and saving many .json files.

i really enjoy making GUIS with godot. which is why im learning code with godot lol.

Ah, sounds good. I'm sure you'll be flying in no time. Regex is a tool for messing with strings - it's efficient and concise but you have to write gobbledygook like this \\w-(\\d+) - needless to say it's famous for giving even experienced coders a giant headache! Ignorance is definitely bliss when it comes to RegEx. :)

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 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 webmaster@godotengine.org with your username.