Skip to content

Weidu REPLACE_TEXTUALLY Scripting Question?

GreenerGreener Member Posts: 430
Hi, I'm trying to patch two lines from AR0125.BCS using REPLACE_TEXTUALLY

Global("bd_tazok_dead","AR0125",0) with Global("TazokDead","GLOBAL",0)

and

SetGlobalGlobal("TazokDead","GLOBAL",1) with SetGlobalGlobal("TazokDead","GLOBAL",1)

Can someone assist me in writing the script?

COPY_EXISTING_REGEXP GLOB ~AR0125.BCS~ ~override~

DECOMPILE_AND_PATCH BEGIN
REPLACE_TEXTUALLY...

Thank you in advance...

Comments

  • Dan_PDan_P Member Posts: 129
    You don't need to use COPY_EXISTING_REGEXP for just a single script.. This will work:
    COPY_EXISTING ~AR0125.BCS~  ~override~
      DECOMPILE_AND_PATCH BEGIN
        REPLACE_TEXTUALLY  ~bd_tazok_dead","AR0125~  ~TazokDead","GLOBAL~
      END
    BUT_ONLY
    


    REPLACE_TEXTUALLY's pretty simple like that. You can also use special characters, for example, this will also work:
    REPLACE_TEXTUALLY   ~bd_taz.+0125~  ~TazokDead","GLOBAL~
    
    Just make sure you're not replacing lines you don't want to replace, if you do use special characters.
  • GreenerGreener Member Posts: 430
    @Dan_P thank you.
  • jmerryjmerry Member Posts: 3,881
    edited November 2022
    If the strings you're trying to use in REPLACE_TEXTUALLY have any special characters in them, you need to escape them or otherwise set up a regexp for them.

    So, for your example with those " characters in the string? Those need to be escaped, because otherwise they would delimit the string. Both of the samples Dan_P provided would throw syntax errors.

    So, correcting that first one ...
    COPY_EXISTING ~AR0125.BCS~  ~override~
      DECOMPILE_AND_PATCH BEGIN
        REPLACE_TEXTUALLY  ~bd_tazok_dead\",\"AR0125~  ~TazokDead\",\"GLOBAL~
      END
    BUT_ONLY
    
    Well, I think only the quotes need to be escaped...
  • Dan_PDan_P Member Posts: 129
    edited November 2022
    @jmerry , this is kind of awkward but, what I posted works.

    Quotes aren't special characters for weidu. Now, if there were square brackets, those would need to be escaped, and only for the text that's being replaced. Special characters aren't used for the new text. I think the fixed example you have would actually fail to install because of the backslash after the comma in the new text.


    Edit: GraionDilach corrected one part of this. Quotes are special characters, but they don't need to be escaped when inside tildes. Also, I meant that regexp isn't used in the new text, not "special characters" in general.
    Post edited by Dan_P on
  • GraionDilachGraionDilach Member Posts: 589
    Quotes(") are special characters in WeiDU and can be used for variable definition as tildes (~) can. The reason tildes are more common is because one doesn't need to escape the inner quotes that way. Similarly, WeiDU also allows to use five tildes(~~~~~) for variable definition to provide an option where one doesn't need to escape the inner tildes.
  • Dan_PDan_P Member Posts: 129
    edited November 2022
    @GraionDilach , TIL then, thanks for the explanation. I was just going by the weidu readme, which doesn't include quotes in the special characters section (I'm not an expert with this stuff by any means). Edit: meant regular expressions section, not "special characters".

    Regardless, the method in my original reply works since, like you said, the quotes don't need to be escaped if inside tildes.
  • jmerryjmerry Member Posts: 3,881
    Quotes(") are special characters in WeiDU and can be used for variable definition as tildes (~) can. The reason tildes are more common is because one doesn't need to escape the inner quotes that way. Similarly, WeiDU also allows to use five tildes(~~~~~) for variable definition to provide an option where one doesn't need to escape the inner tildes.

    Good to know. That's not an interaction I'd ever considered before.
Sign In or Register to comment.