Reverse a string with blueprints?
I'm trying to figure out if there's currently a way to reverse a string using the blueprint system, I don't see anything obvious, but maybe someone has a method for this?
The reason I'd like to do this is to reverse floats (200 becomes .002, 50 becomes .05, etc) and use them as a vector lerp alpha for a system i'm building that involves picking up objects and having heavier objects take longer to move. In this case, the heavier object needs to be a smaller number, as smaller numbers will make the lerp slower, and larger ones will make the lerp faster.
In my head the only way I could think to do this would be to convert a float to a string, reverse it, and then convert it back to a float.
If anyone has any other suggestions on how to accomplish this, I'm all ears!
asked Mar 26 '14 at 11:48 AM in Blueprint Scripting
If you wanted a linear lerp between 0 and 1 for weights ranging between 0 and a max weight, try the following equation:
lerp = 1 - (1/(MaxWeight*ItemWeight);
This would give you a graph along the lines of: http://fooplot.com/plot/64evwewhi2
I've taken 200 to be your max weight here...
I know you got a workaround for your problem, but in case anyone is looking to reverse a string I have a solution.
Make a new function that has a string input and a string output. Make a local string variable as well.
The function takes in the string, converts it to a character array, then gets the last index of it. It then runs a For loop from zero until the last index and on each loop pass sets the local string variable to itself + a return string value. The return string value is returned like this: We take the current index on the for loop and subtract the last index of the character array (so if your index is 3, we return -1, essentially turning "Second-to-last" into "second") then gets the absolute value of that returned integer. Then we get the character at the index we just calculated and append it to our string variable.
When the loop is completed, we return the string variable (after appends) to the return node.
answered Aug 08 '14 at 06:18 PM
Follow this question
Once you sign in you will be able to subscribe for any updates here