Hello. I have a simple item inspection system for my inventory. The pointer moves left and right in increments. When it is near to an instance of the icon, the animation for that icon changes to an ‘over’ version. All icons have two animations e.g. book and book_over.
I worked out an expression for switching to the over anim that using concatenation to add ‘_over’ to the default animation name. It works great. But… how do I do the reverse so I get the ‘book’ animation name back? I’m currently using a series of sub-events to change the icon animations back to their defaults when the pointer moves away, but is there a more concise way? Is there a way of chopping the ‘_over’ off an animation name if it’s present? Thanks in advance.
You are going to need to use a combination of the SubStr expression and the StrFindLast expresion. Since you know you are always looking for _book, your StrFindLast would be StrFindLast(AnimationNameStringHere,“_book”).
Your SubStr would start at 0, and then you would have SubStr(AnimationNameString,0,StrFindLast(AnimationNameString,“_book”)-1)
Should work mostly fine.
Thanks for the reply. Do I use those expressions in a condition or action and as part of what condition or action? I think I understand the expressions, but I don’t know where to put them. Thanks.
Or perhaps if anyone else is able to help, you are very welcome. Please assume I am a beginner.
It would be used as an action and I would test the string first and maybe use a trigger once. IDK, if you test the string then you wouldn’t need the trigger once.
This was harder to figure out than it should’ve been. You don’t need minus 1 because of the way things are numbered. The first character is zero and strFindLast returns the character location.
Say the animation is “abcd_OVER”
StrFindLast would return 4 (_OVER is the 5th character but since the 1st character is 0 everything is off by 1
SubStr uses the start position of 0 with the number of characters, in this case 4
So, it would return “abcd”
(note: if the string isn’t found StrFind would return -1 instead of the position)
Edit: be careful with the [inverted] conditions.
Apologies. I could have sworn the -1 was needed, but thats what I get for posting expressions at 4am.
I struggled too. The whole starting at zero for strings (and arrays) is annoying.
Thank you and @Silver-Streak very much for your help. I’m glad it’s not just me who found this tricky. Though, admittedly, I surely found it a lot trickier than either of you did! Me and expressions have a long way to go.
@Keith_1357 When you said ‘be careful with the [inverted] conditions’ what’s the reason for caution around using inverted conditions for this task, or was it a general note about making sure I inverted the correct conditions?
It was a general warning because of the different inverts. I just wanted to make sure you saw them. I would prefer to be able to change the condition or comparison function than invert conditions. It’s easy to miss that little symbol.