Pocket Plane Group

Friends and Neighbors => Weimer Republic (WeiDU.org) => WeiDU => Topic started by: K4thos on May 09, 2016, 02:45:35 PM

Title: [Req] New command for replacing text in LUA and MENU files (like R_B_B)
Post by: K4thos on May 09, 2016, 02:45:35 PM
We need something similar to REPLACE_BCS_BLOCK but for LUA and MENU files format. Let's say I want to replace this code:

Code: [Select]
--This code is different if we're sod or BG
local lineCount = 1
local fullStr = Infinity_FetchString(entryId)
for line in string.gmatch(fullStr, "[^\r\n]+") do
if(lineCount == 1) then
--objective text is first line.
objective.text = line
if(lineCount > 1) then
--entry text is everything after first
entry.text = entry.text .. line .. "\n"
lineCount = lineCount + 1
if(lineCount == 2) then
--it looks like sometimes entries are just an unbroken paragraph
--in this case the entry should get the paragraph and the objective gets nothing
--note lineCount == 2 is a bit misleading, there's only one line in this case.
entry.text = objective.text
objective.text = Infinity_FetchString(quest.text)

Doing it with REPLACE_TEXTUALLY would be insane. And that's just a small portion of the file. Some GUI mods needs to replace hundreds of lines at once. Due to this problem all GUI mods are incompatible with one another because they always overwrites whole files rather than replacing part of text within these files. Perfectly the function should work exactly the same as R_B_B, so with ON_MISMATCH and ignoring blank lines and tabs when finding the match.
Title: Re: [Req] New command for replacing text in LUA and MENU files (like R_B_B)
Post by: Wisp on May 19, 2016, 01:09:18 PM
Scripts are not de facto well-defined bytecode, unlike BCS. The tools for editing scripts you are looking for are diff and patch. WeiDU has some undocumented diff/patch stuff targeted at BCS. I'm not familiar with the code. I try to look it over and get back to you.