Skip to content

Replace string

I've been looking through the weidu documentation up to the point that it nearly turned me crazy.
So let's say I have a string variable, i.e.
// when patching an item
READ_STRREF 0x54 identifiedDesc
How in the world do I replace all occurrences of a substring in identifiedDesc with another string?
For example, replace all "o" in "spoon" by "a" so identifiedDesc becomes "spaan".

The only command that seems remotely similar is the REPLACE command, but it's a patch action and thus modifies a file instead of updating a variable.

Comments

  • prophet1prophet1 Member Posts: 172
    It's fairly complicated to do such replacement. Basically, you'll need to 1. Copy the original string to a temporary file. 2. Make your replacements in that file's contents. 3. STRING_SET_EVALUATE the original strref to the new one from your temporary file.

    I think BG2Tweaks does item description updates in one of their components, or you could take a look at how Miloch does it with the Spears: Increased range and damage component in P5Tweaks mod.
  • AlkaluropsAlkalurops Member Posts: 269
    Yeah, I've created a macro that does exactly that in the meantime. Really stupid workaround though, hard to believe this is the most "elegant" way.
  • WispWisp Member Posts: 1,102
    INNER_PATCH_SAVE (used together with REPLACE_(TEXTUALLY|EVALUATE) or other patches) is hardly elegant, but may have your current solution beat. Just be aware of foreigners and their wacky languages when you do these sorts of things.
Sign In or Register to comment.