How do I make only one instance of a word get replaced at a time?

1 favourites
  • 5 posts
From the Asset Store
Control your space ship in a weird space-time environment and destroy as many enemies as you can!
  • Basically I got the item thing sorted out except for major thing, in order for me to get rid of the word (like "Pie") I use the replace expression to replace that word with spaces, and that works fine, IF there is only one version of the word, but for me a bunch of the items are the same in terms of names, so when I replace the item (like S.Piece since it has three of them in the item text) if gets rid of ALL of them, and I want it so that it gets rid of only one. The main problem is that I don't know if I should use replace expression but instead of just the source being Itemtext.text it is something else like array variables or something, but I can't figure it out. I also don't know how regex works and if it would fix it but that's why I am asking if anyone can help

    TLDR: the replace expression for my items in a certain text sprite gets rid of all instances of the word instead of just the one word at a time, and the only thing different from the words are where they are and their array value, but I can't seem to apply it to the expression

    this is how I replaced the items (note there's only one instance of the pie and I.Noodles and I did a bit more spacing for the pie so it wouldn't also get rid of "pie" in "S.Piece", but the ones that do have multiple things are the L.Hero, which has two, and the S.Piece, which has three)Note: I am not showing the code for things like the snow piece because I did not make it yet and the image is just an example of what the code is like

    Again, I know I am probably showing too much information, but I just don't know how else I should describe it and what information is helpful or throws people off.

  • I am not sure if I understand what you are asking. But if you want to replace only one occurence of a sub-string in text, you can use expressions find, left, right and len

    construct.net/en/make-games/manuals/construct-3/system-reference/system-expressions

    Something like this, but I haven't tested it:

    Set s to left(s, find(s, "Pie")) & right(s, len(s)-find(s, "Pie")-len("Pie"))

  • Ok thanks, I will try it out and to avoid confusion in the future should I share a copy of my project?

    also in the code you wrote what is "s"?

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • You know what they say - "one demo project is worth a thousand words" :)

  • It works now, thanks!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)