Executing if text reads 1 or more / Removing one from a number that is stored as text

Hi all, I want to create a condition where a text box contains a number of items collected. The condition is to execute the function IF the number in this text box is 1 or more. I then want to remove one from that number after the function has executed. Is this how I would do this?


Hey @JasonDiesALot!

You should be able to just use that code above and work it into the “X” pressed.

Let us know if we can help further! :slight_smile:

A much better way to do this, is to store the number of items collected as an integer, and convert to string only for display.

1 Like

So, this is how I’m deriving the number in the text box - I’m just not sure how to get it from this calculation to a number I can use in the example. There are probably much better ways of doing this, but this is my workaround as no inventory tutorials I tried worked for what I was trying to do.

Thank you - could you possibly elaborate?

Also, while this works, I need to have two items before it works, AND I have to press X twice as well, which makes no sense to me.

Hey, @JasonDiesALot, Sorry for the late reply.

Okay you’ve made some good moves here. We need to know the rest of the code to figure out why one is not removed, though. There’s no code shown for that.

But I will say that with the current setup of your “Get Apple Count Text” you’re never going to see it go down with the code you have. It only actively uses THAT total, no matter what you do to it, because it is bound to “Total items minus items left.” The only way I could see this being added to would be "Health Boost Total Items - Health Boost Items Left - Health Boost Items Used and then have a third variable for that on the game mode, which you would then “++” on the heal code.

You can also just remove those variables and have an integer for “Apples” that goes “++” when you pick one up and “-1” when you use one. Whatever you change it to, the HUD should update. :slight_smile:

Thanks for coming back to me. I’ve tried a few things and I’m not sure exactly how to do this. I can see why the way I’m deriving the count isn’t going to work. Duh.

I tried creating a variable that would hold the value of the items as an integer, but I don’t think I’ve done it right, as I can pick it up, but it doesn’t count up on the HUD.




So, I figured out how to make most of it work after a bit of head scratching. The only issue I have left now is that when I add a condition ‘if holding 1 or more’, I get an error that says I’m holding none, even though I’m holding several. This is how I’m setting the variables in the game mode, but I’m getting errors saying ‘accessed none’ on each of these variables I’ve created.

I then get an error on the character blueprint for the gamemode ref itself. Will keep working on this, but if anyone has any thoughts, appreciate it.

Okay, solved that too. It’s probably a messy af solution, but cast to the game instance for the condition and it all now works as expected. :slight_smile:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.