Return Array String from Function?

Blitz3D Forums/Blitz3D Programming/Return Array String from Function?

Guy Fawkes(Posted 2014) [#1]
Hi all. How can I make this code I made return an array string?



It SHOULD return:

"This"
"Sucks"

But instead, it returns:

"Sucks"

Which DOES suck! :P

Thank You so kindly! :)

Sincerely,

~GF


Yasha(Posted 2014) [#2]
That you made?

http://www.blitzbasic.com/codearcs/codearcs.php?code=188

Step 1 to getting actual help: if you don't understand someone else's code, do not claim you wrote it after making like two trivial modifications. That isn't going to help you get the answers you need, in this case because:

1) it's not possible to return an array from a function in Blitz3D

2) the person who originally wrote that code knew that and is already using the standard workaround for "returning" arrays from functions, which makes your question make no sense

(The workaround, incidentally, is to have an externally-designated Dim array for the function to use, in this case Word$(). The values will appear in that array. Blitz3D doesn't recognise "an array" as a single value you can do things to - at least, not the Dim-style arrays - so trying to DebugLog it makes no sense.)

What do you actually want to achieve here? (What is Split_Me supposed to do?) Splitting a string only to treat the resulting array as a single string seems somewhat redundant.


Guy Fawkes(Posted 2014) [#3]
Yes. PART of it is MY code.

Split_Me$() is MY code.

Q$() is MY code.



Now... If you're not going to be of any help, please leave this thread and don't come back.

And no it is NOT redundant. I want it to Split the string and return automatically. Not having to use a bunch of "Word$()" arrays.


Yasha(Posted 2014) [#4]
Did you even read past the first line of post #2?

Returning an array from a function is not possible. You must use a workaround. You have a few options here, and the one Chroma used originally is pretty much the best. What's wrong with doing that?

What are you even trying to do here? Your usage example in the OP doesn't make any sense. Your Q function does nothing relevant to the question, and your Split_Me function is so broken it's not clear what it's trying to do (all it does is return Q(Word(2))). And again, splitting a string into... one string... is a no-op. That's obviously not the goal.

Please, restate what it is you want from this code, having acknowledged that your original problem statement cannot be expressed in Blitz3D and needs to be reconsidered.


Guy Fawkes(Posted 2014) [#5]
I want this code to return every word with a separator as a list. I will then grab each word from the list and return it somehow. I need this for a texture name return function. Using return & not print or debuglog.


Yasha(Posted 2014) [#6]
I will then grab each word from the list and return it somehow


This is the bit that's tripping me up, because its meaning is not obvious. (I actually think I know what you mean, but let's be clear.)

"grab" = ?
"return" = ?
"it" = what structure of data?

Draw a data flow diagram (just type it in a code box) that describes the sequence of mutations you want to apply to the input string?

e.g.

"paris in the spring" --(split on space)--> {"paris", "in", "the", "spring"}

{"paris", "in", "the", "spring"} --(concatenate elements with newline)--> "paris\nin\nthe\nspring"



Guy Fawkes(Posted 2014) [#7]


Each texture is a separate texture.

Like that?


Yasha(Posted 2014) [#8]
So your original string is a list of names, and you want to split on ', ' to produce an array of names, and then you want to fold the array back into a single string but with newlines instead of commaspaces?

You're sure you want the result to be a single string? (I haven't been following your other threads, if this is something textures can actually use then sure, w/e)

In that case, why not just use Replace to switch the original separator for a newline?

See if your dataflow goes 'string -> (intermediate forms) -> string', that's entirely distinct from 'string -> array of strings'. Split is certainly one way to implement the first part of Replace (and B3D probably has an efficient implementation of Split internally), but making your question about it is rather like wanting to know about quaternion rotations and asking about multiplying two floats: it's not the actual problem you want to solve. And the terminology in the original question - referring to the final result type as an array - is incorrect and confusing.


Guy Fawkes(Posted 2014) [#9]
Well, in order to write each texture to a file of mine in code, the said "Split()" code must work WITHOUT repeats or loops as it gets stuck in an infinite loop if I do:



I'm trying to grab EACH texture name from a 3D model no matter what model that is in X Format, write it to a text file so it can be opened & read line by line, later.

Does that explain it a LITTLE better?


Yasha(Posted 2014) [#10]
What does read_texture_names_here represent? Since if the above forms an infinite loop it's fairly obvious that that's where the issue is.

OK, I get now what structure you want for the output. Now to address the input:

-- the above post implies that you have explored two options for reading texture names from an X file
-- you can grab them individually, which isn't working for some reason
-- you can grab them all in one go, but then have to break them apart separately

How are you doing that? Which is the initial format of the data being returned from your read operation?

Am I right? (NB I don't know anything about X files, except that it's a spec that seems to change every five minutes)


RemiD(Posted 2014) [#11]
Let's ignore the previous answers and repeat the same question :
http://www.blitzbasic.com/Community/posts.php?topic=101442


Guy Fawkes(Posted 2014) [#12]
Ok, my mistake Remi. Thank you for finding that topic for me. I couldn't for the life of me remember where it was.

Problem solved guys! :)

Tyvm!

Sincerely,

~GF