Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6178881
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T00:32:32+00:00 2026-05-24T00:32:32+00:00

I am in the final stages of developing a mod for the Indie Game

  • 0

I am in the final stages of developing a mod for the Indie Game Dwarf Fortress. The last thing required before the mod is in working order is to go through and alter the Dwarf Fortress RAWs — two dozen or so text files that contain information about the hundreds of creatures populating the game.

What this amounts to from a technical perspective, is going through a directory of text files, and basically performing a “Find and Replace” operation to alter each line.

Most of my programming experiences are with object oriented languages – C# and Java, and some experience with Assembler and C. However, none of these languages seem optimal for this kind of task.

The one catch in what would otherwise be a very simple substituion, is that because of the way the Dwarf Fortress RAWs are written, I won’t know if I need to replace the line until further down the text file. Below is an abbreviated example scenario.

[CREATURE:WOLF]
    ...
    [Many irrelevant lines of tokens]
    ...
[BODY_DETAIL_PLAN:STANDARD_MATERIALS]
[BODY_DETAIL_PLAN:STANDARD_TISSUES]
    ...
    [Many more irrelevant lines of tokens]
    ...
[MULTIPLY_VALUE:2]

The program I wish to write needs to be able to read through to the [MULTIPLY_VALUE:X] line and then go back and replace the two lines containing [BODY_DETAIL_PLAN:Z] with [BODY_DETAIL_PLAN:Y], where Y changes depending on the read value of X.

I can guarantee two things:

  • At most one [MULTIPLY_VALUE:X] line will appear between [CREATURE:A] and [CREATURE:B] or [CREATURE:Z] and the end of the file.
  • The [MULTIPLY_VALUE:X] line will always come after the [BODY_DETAIL_PLAN:Z] line, if it is present on that creature.

Based on the coding experience I have, the closest thing I have to a viable idea is writing a C program to read the file, using pointers to ‘save’ the location of the read lines and change them when the file reader detects the start of a new RAW.

However, that strikes me as inelegant, and runs into the trouble of me having no experience in implementing a find/replace function in C (or any language) in the first place.

Is there some easier way to accomplish this otherwise monotonous task of going through each text file by hand? I am totally willing to learn a new programming language, but I don’t exactly know which language would be easiest to handle this situation.

Suggestions?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T00:32:34+00:00Added an answer on May 24, 2026 at 12:32 am

    Ok..the reason I was asking the questions before is I wanted to know if the context of the lines to be replaced was important. Since if the context is NOT important then the whole recursive replace thing will be mostly a one-liner program.

    Based on your answers I’m assuming that context needs to be taken into account. So with that here’s a simplified example in Ruby. Just as an example so you can see how it works. The code is a bit verbose to help you understand it better. You could use it as a base and work from there.

    The program works like this – let’s say you have a data file data.txt like so:

    [aaa]
    [bbb]
    [replace:a]
    [replace:b]
    
    [start_marker]
      [xxx]
      [replace:x]
      [replace:y]
      [yyy]
    [end_marker]
    
    [replace:c]
    [replace:d]
    [ccc]
    [ddd]
    

    You run the program:

    ruby replace.rb data.txt
    

    And you end up with data.txt.bak with the original data, and a replaced data.txt that looks like this:

    [aaa]
    [bbb]
    [replace:a]
    [replace:b]
    
    [start_marker]
      [xxx]
      [replace:x was replaced!]
      [replace:y was replaced!]
      [yyy]
    [end_marker]
    
    [replace:c]
    [replace:d]
    [ccc]
    [ddd]
    

    The program replace.rb:

    require 'rubygems'
    require 'ftools'         # File.move
    require 'extensions/io'  # File.writelines
    
    file  = ARGV.shift
    lines = File.open(file).readlines
    
    replace_these  = Array.new
    within_section = false
    
    # Loop until we hit start_marker, then store potential
    # lines until we hit end_marker, then fix the lines
    lines.each { |line|
      within_section = true if line.match /\[start_marker\]/
    
      if line.match /\[end_marker\]/
        within_section = false
    
        replace_these.each { |line|
          # Do something clever...
          line.gsub!(/:(\w+)/, ':\1 was replaced!')
        }
    
        replace_these = Array.new
      end
    
      next if !within_section
    
      # Store lines to be replaced for later processing
      replace_these << line if line.match /\[replace:.*\]/
    }
    
    # Make a backup of the original file
    File.move(file, "#{file}.bak")
    
    # Overwrite the original with the new data
    File.writelines(file, lines)
    

    Ruby is a fun language to program in, and a nice addition to have in your “tool belt”. So might be something you want to take a look at.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Background: I'm developing a bussiness application, and in the final stages we are encountering
I'm in the final stages of releasing my first game, and after running Instruments:Leaks
I'm in the final stages of going round trip through the entire Rails cycle:
I am currently in the final stages of testing my app before submitting to
I am in the final stage of developing an iPhone game and I am
I'm in the final stages of developing an app, and today my Galaxy Nexus
In the final stages of development and testing before an initial beta release. As
We're in the final stages of shipping our console game. On the Wii we're
I am in the final stages of making a Pacman game for Computer Science
So I'm in the final stages of designing a game for the iPhone using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.