When I use the find node with my array of texts and search for something that is inside, it fails. I know it has something to do with my array being converted from string to text and it only happens in a standalone game. In editor this doesn’t occur.
Here is a picture of what it looks like when it succeeds:
Here is a picture of when it fails:
Converting the text to string before searching for it seems to be a fix for now. Can anyone help me understand why this happens. Does it have something to do with the lossy conversion between string and text?
I don’t know the exact reason in this instance but conversion is not “lossless” so it makes a bit of sense. Text type variables have extra encoding for localization and formatting that may not be readily apparent over-the-hood. This is why to match your “strings converted to text” in random2 you need to convert your text to string in the find “This is fun”.
Also Text type is really for localization/UI so if you just need String then go with that and convert it last minute if it is needed in UI.
Is this purely an exercise or would you like recommendations for how to make something work?
I don’t know much about localization with text. I’m just trying to keep everything as manageable as possible so that if I need to go back later and fix some things it won’t give me trouble. I thought that converting string to text last minute is discouraged because it won’t end up being able to be translated later which makes using text pointless. With this example I do need the string part. I might try and find another workaround so that I won’t need to convert back and forth too much.
With this example it appears you are starting with Strings (Random) and then storing them all as text (Random2) with no alteration. You could just skip the Random2 part and compare the converted literal Text to the string array.
If you need something auto-localized then it needs to start as Text instead of strings. If you are localizing it in some other way (custom ini or such) then you can use Strings as you are now and change your “This is fun” comparison to a string.
It’s a bit rare case to need to compare localized text which is why i asked if you wanted recommendations. Depending on the purpose of the function you may want to use a struct with an ID, the index, etc.
I think the big issue with my method is that I’m using data tables to get the string in random. My data table items have underscores and I’m using those items to set the text required in random 2.
It goes like this:
- Get item from data table
- Convert from name to string
- Convert underscores to spaces
- Add to array random
- Convert random to random2
- Find index in random 2
- Return text at index if the index = what is in “This is fun.”.
That’s just a short rundown of what I’m actually doing. Sorry I have no power over where I live right now due to a giant blackout. I’d send some more pictures otherwise.