0 votes

So on one of my scenes, you can choose the order that different colored orbs have to be deposited.

Like so:
https://i.imgur.com/58mRrnv.png

If the player doesn't deposit the orbs in the correct order, it doesn't count towards the score.

At a different place, I am using a for loop like the one below:

for i in range(0, orbcolororder.size()):
    print (orbcolororder[i])
    print ("printed i")

I added the "printed i" line to make sure that there wasn't a random number being output somewhere, because when I run this loop, for the first value of the array, it prints 3, which is the position of "Blue" in the set of strings you can choose from in the dropdown above.

For the second value (and subsequent ones) of the array, it prints the string "Blue," or whatever the string value that the second position in the array is instead of the index.

I don't really care which way it prints, I can use either for what I'm doing, I just need it to be consistent.

Any help would be greatly appreciated.

in Engine by (46 points)
edited by

I don't quite follow. What's your question, exactly? Do you want the colors, along with their index number, to be printed?

I'm trying to access the color, either its string or its index. When I run the for loop, the first loop returns the first color, via its index, but then the second loop returns the second color via its string.

Trying to figure out why the first iteration of the loop returns an index number and all subsequent loops return a string.

The actual practical use of the loop is to tally the colors selected to define the color of a sprite, but the main issue here is that my for loop is returning a different type on the first loop than in subsequent loops, which is throwing an error.

From what I gather (at least from your screenshot), the array orbcolororder has a size of 2, meaning that the array may look like this:

orbcolororder = [ 0, "Red, Yellow, Green, Blue, Purple" ]

The first element could have the value of 0, while the rest of it looks like the string "Red, Yellow, Green, Blue, Purple". Of course, I could be misreading, and be completely off.

I don't believe that to be the case, but I appreciate the input.

Edit: For example, if I print my array, it's

[3, Red]

Which is Blue, Red, which I have the array set to right now. Just for whatever reason that first value is returning the index of the color instead of the string at that index.

The whole thing is weird, but I found a working solution.

I had to specify String() or int(), for the value I was grabbing from the first slot of the array, otherwise it wouldn't work in the situation I was using it in.

int(orbcolororder[i])

and

String(orbcolororder[i])

Both work correctly and return the correct value, so who knows.

1 Answer

0 votes
Best answer

I had to specify String() or int(), for the value I was grabbing from the first slot of the array, otherwise it wouldn't work in the situation I was using it in.

int(orbcolororder[i])

and

String(orbcolororder[i])

Both work correctly and return the correct value, so who knows.

by (46 points)
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.