View Single Post
  #5  
Old 10-11-2011, 09:06 AM
xXziroXx xXziroXx is offline
Master of Puppets
xXziroXx's Avatar
Join Date: May 2004
Location: Sweden
Posts: 5,288
xXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant future
Send a message via AIM to xXziroXx Send a message via MSN to xXziroXx
I don't like looking back and seeing my Code Library entries being really outdated and some not even working anymore, so I'll start updating them I suppose!

To start off, I've made this function more reliable in it's behaviour. The old code tended to randomly skip text to replace.

PHP Code:
function replaceTxt(prepast)
{
  
temp.header "mal_"// Anti never ending while (...) loop
  
temp.allowedExt = { ".nw" }; // Will skip all files but these
  
temp.folderPath "levels/levels/"// Base folder
  
temp.checkSubs true// Scan through subfolders too?
  
  
temp.folder.loadFolder(temp.folderPath "*"temp.checkSubs);
  echo(
"Starting scan on" SPC temp.folder.size() SPC "files...");
  
  
temp.totalLevelChanges NULL;
  for (
temp.filetemp.folder) {
    if (!(
extractfileext(temp.filein temp.allowedExt))
      continue;
    
    
temp.file findfiles(extractfilename(temp.file), true)[0];
    
temp.lines "";
    
temp.lines.loadString(temp.file);
    
    
// Times replaced this level
    
temp.currentLevelChanges NULL;
    while (
temp.lines.pos(pre) > -1) {
      
temp.pos temp.lines.pos(pre);
      if (
temp.lines.substring(temp.pos temp.header.length(), temp.header.length()) == temp.header)
        break;
            
      
temp.lines temp.lines.substring(0temp.pos) @ past temp.lines.substring(temp.pos pre.length());
      
temp.currentLevelChanges ++;
      
temp.totalLevelChanges ++;
    }
    
    if (
temp.currentLevelChanges != NULL) {
      echo(
"Replaced text" SPC temp.currentLevelChanges SPC "times in" SPC temp.file "!");
      
temp.lines.savestring(temp.filefalse);
    }
  }
  echo(
"Done! Replaced text a total of" SPC temp.totalLevelChanges SPC "times!");

If a mod would be so kind to update the first post... <3
__________________

"A delayed game is eventually good, but a rushed game is forever bad." - Shigeru Miyamoto
Reply With Quote