Lauriel Posted December 24, 2019 Share Posted December 24, 2019 (edited) I am trying to set up a TP2 file for a mod I'm working on. The first thing I need to do is replace a block of code from an area script file. I'm trying to use REPLACE_BCS_BLOCK, but nothing happens except I get the can't-find-block error at the end. Here's what the TP2 file looks like so far: Spoiler BACKUP ~my_mod/backup~ AUTHOR ~me@url.com~ BEGIN ~My Mod V0.1~ COPY_EXISTING ~BGareafile.BCS~ ~my_mod/wip/BGareafile.BCS~ DECOMPILE_AND_PATCH BEGIN REPLACE_BCS_BLOCK ~my_mod/wip/Old_blockcode.baf~ ~my_mod/wip/New_blockcode.baf~ ON_MISMATCH PATCH_FAIL ~Couldn't find block to replace~ END END BUT_ONLY_IF_IT_CHANGES NOTE: I'm playing with the file in a separate WIP folder instead of the normal override folder because I don't want to mess up my game. Contents of decompiled BGareafile.BAF Spoiler <some code block> IF Dead("targetnpc") // ~target npc~ Global("some global I don't care about","GLOBAL",0) THEN RESPONSE #100 do something I want to stop do something else I want to skip and a whole list of things I want to skip END <many other code blocks> Contents 0f Old_blockcode.baf: Spoiler IF Dead("targetnpc") // ~target npc~ Global("some global I don't care about","GLOBAL",0) THEN RESPONSE #100 do something I want to stop do something else I want to skip and a whole list of things I want to skip END Contents of New_codeblock.baf Spoiler IF Dead("targetnpc") // ~target npc~ Global("some new global","GLOBAL",0) THEN RESPONSE #100 SetGlobal("some new global","GLOBAL",1) END Anyway, am I not using REPLACE_BCS_BLOCK correctly? Edited December 24, 2019 by Lauriel Added pseudo code of code block files Quote Link to comment
jastey Posted December 24, 2019 Share Posted December 24, 2019 This is tricky as the installer is very sensitive (e.g. formatting, missing spaces etcpp). With REPLACE_TEXTUALLY you have a finer handling of what exactly you want to replace. (If necessary, whole blocks can be deaxtivated by putting a False() as a trigger). It's also better compatibility wise than replacing a whole block. I'll post examples soon or you could have a look into my Imoen4Ever mod (for which I stole it from eet). Quote Link to comment
jastey Posted December 24, 2019 Share Posted December 24, 2019 Hm, in your example maybe just placing another block of code in front of the original one would work, too. You'd need to set the original variable, too, to deactivate the original code block. If that's possible without triggering / preventing other events. Quote Link to comment
Guest Lauriel Posted December 24, 2019 Share Posted December 24, 2019 I see what you're saying. Instead of trying to replace the block, insert one in ahead of it and break the old one. It grates against my pedantic programming sensibilities, but I see the benefit. It would certainly make it easier to undo the change in the future. It would almost like commenting out the offending block, which is something I miss. Thank you for the out-of-the-box solution. I like it! Quote Link to comment
Lauriel Posted December 24, 2019 Author Share Posted December 24, 2019 Not 'out-of-the-box', should be 'outside-the-box'. LOL So funny. Sorry! Quote Link to comment
jastey Posted December 25, 2019 Share Posted December 25, 2019 I'M ESL so I didn't even notice. 12 hours ago, Guest Lauriel said: Instead of trying to replace the block, insert one in ahead of it and break the old one. It grates against my pedantic programming sensibilities, but I see the benefit. As I said, it depends on what you want to do (and whether you can change the original variable without causeing any unwanted changes), but seeing your script blocks I had the impression you more or less wanted to get rid of a whole block in the original game, so this is also the more stable way of achieving it. (EDIT: stable in the meaning of REPLACE_xx might fail in the player's game). One note, though: if you do EXTEND_TOP to scripts, always add an Continue() at the end of your code block - because it might be there is an OnCreation() one already there (or added by a mod). This is advice from the depth of the modding community from painful experience why area scripts don't do what they are supposed to be.. Quote Link to comment
Luke Posted December 27, 2019 Share Posted December 27, 2019 Moreover, you might want to look at these functions... Quote Link to comment
Lauriel Posted January 3, 2020 Author Share Posted January 3, 2020 Thank you, @Luke! Those look like they'd absolutely do the trick. Although in this instance I'll use @jastey's suggestion, I'll certainly keep these other beauties in mind. Thanks again! Quote Link to comment
Lauriel Posted January 11, 2020 Author Share Posted January 11, 2020 Ok, I reevaluated my plan of attack. @Luke, those functions are a thing of beauty. Thank you so much for pointing them out. Quote Link to comment
Lauriel Posted January 11, 2020 Author Share Posted January 11, 2020 Well, I'd like to use them, but I'm such a newb that I can't seem to figure out how. Here's what I have and I get a parsing error Spoiler BACKUP ~transitions/backup~ AUTHOR ~lzenner@live.com~ VERSION ~0.1~ README ~transitions/readme.transitions.%LANGUAGE%.txt~ ~transitions/readme.transitions.english.txt~ AUTO_TRA ~transitions/languages/%s~ ALWAYS ACTION_IF NOT GAME_IS ~eet~ BEGIN FAIL @1 END ACTION_DEFINE_ARRAY Transitions_noconvert BEGIN setup END ACTION_DEFINE_ARRAY Transitions_reload BEGIN game dialogues END LAF HANDLE_CHARSETS INT_VAR infer_charset = 1 STR_VAR tra_path = EVAL ~transitions/language~ noconvert_array = Transitions_noconvert reload_array = Transitions_reload END // CamDawgs CD_STATE_NOTVALID APPEND ~STATE.IDS~ ~0x80101FEF CD_STATE_NOTVALID~ UNLESS ~CD_STATE_NOTVALID~ INCLUDE ~transitions/lib/alter_script.tpa~ <========== This is how I included the library - is this not correct? END LANGUAGE ~American English~ ~english~ ~transitions/languages/english/setup.tra~ ~transitions/languages/english/game.tra~ //////////////////////////////////////////////////////////////////// // MAIN COMPONENT: ALLOW CONTINUED PLAY AFTER SAREVOK IS DEFEATED // //////////////////////////////////////////////////////////////////// BEGIN @3 // This option removes the movie from the end of the fight // so it can be used in a dream sequence later on FORCED_SUBCOMPONENT @2 INSTALL_BY_DEFAULT COPY_EXISTING ~BG0125.BCS~ ~override~ DECOMPILE_AND_PATCH BEGIN COUNT_REGEXP_INSTANCES ~Global("C#st_BG1End","GLOBAL",0)~ endlessPatchInstalled PATCH_IF (endlessPatchInstalled > 0) BEGIN // Don't play the movie after the fight LAF REPLACE_SCRIPT_BLOCK <============= This gives the parsing error - is this not how you use these? INT_VAR only_once = 1 STR_VAR script = BG0125 <============= the examples didn't have the script file inside tildes ... assume this is ok match = ~C#st_BG1End~ insert = ~transitions/scripts/New0125a.baf~ END // Replace the block where jastey spawns her flaming fist healers LAF REPLACE_SCRIPT_BLOCK INT_VAR only_once = 1 STR_VAR script = ~BG0125~ match = ~C#st_FFHealerSpawn","GLOBAL",0)~ insert = ~transitions/scripts/New0125c.baf~ END END ELSE BEGIN LAF REPLACE_SCRIPT_BLOCK INT_VAR only_once = 1 STR_VAR script = ~BG0125~ match = ~Dead("Sarevok")~ insert = ~transitions/scripts/New0125a.baf~ END APPEND_FILE TEXT ~transitions/scripts/New0125c.baf~ END END BUT_ONLY_IF_IT_CHANGES Quote Link to comment
Lauriel Posted January 11, 2020 Author Share Posted January 11, 2020 Nevermind once again - I figured it out. Quote Link to comment
Recommended Posts
Join the conversation
You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.