Author Topic: Need help modifying certain lines on a file  (Read 955 times)

Code: [Select]
function LoadMap_Forest()
{
%MissionFile = "Add-Ons/Map_Forest/Map.mis";
%SimGroupName = "Map_Forest";

%file = new fileObject();
    %file.openForRead(%MissionFile);
    %file.readLine();
    if(%file.isEOF())
    {
%file2 = new fileObject();
%file2.openForWrite(%MissionFile);
while(!%file.isEOF())
{
%file2.writeLine(strReplace(%file.readLine(), "MissionGroup", %SimGroupName));
}
%file2.close();
%file2.delete();
    }
    %file.close();
    %file.delete();

//exec(%MissionFile);
}

The Map.mis file remains exactly the same. MissionGroup has not been replaced.

If at all possible, I also need the script to not load default mission stuff (Sky, Sun, fxPlane, SimGroup(PlayerDropPoints), fxDayCycle, and fxSunLight)



EDIT:
I've thought of an easier way to do it, but I don't know how.
Basically it should replace line 2 from new SimGroup(MissionGroup) { to new SimGroup(Map_Forest) {, an delete the contents of lines 4 to 293.

Here is the Map.mis:
Code: [Select]
//--- OBJECT WRITE BEGIN ---
new SimGroup(MissionGroup) {

   //Lines 4 to 293 are here, bunch of default mission stuff
   new TSStatic() {
      position = "-41.8661 -0.971407 0";
      rotation = "1 0 0 0";
      scale = "1 1 1";
      shapeName = "base/data/shapes/Sharp_Trees/Trees/Scrub_Pines/Sharp_ScrubPine09.dts";
   };
};
//--- OBJECT WRITE END ---
« Last Edit: July 08, 2013, 07:07:44 PM by Subpixel »

Upon trying to execute Map.mis, it tells me it's an invalid script file (the file drained of all its contents.)

Code: [Select]
function replaceMap(%file,%name)
{
    %file = new fileObject();
    %file.openForRead(%file);
    %outfile = new fileObject();
    %outfile.openForWrite("new" SPC %file);
    %linecounter = 0;
    while(!%file.isEOF())
    {
        %linecounter++;
        if(%linecounter == 2)
            %outfile.writeLine(strReplace(%file.readLine(),"MissionGroup",%name));
        else
            %outfile.writeLine(%file.readLine());
    }
    %file.close();
    %outfile.close();
}
replaceMap("Add-Ons/Map_Forest/Map.mis","Map_Forest");

Not tested and written in a rush without indentation.
But I was told the thing to replace is always on the second line, so I made that, hopefully it works.

Code: [Select]
function replaceMap(%file,%name)
{
    %file = new fileObject();
    %file.openForRead(%file);
    %outfile = new fileObject();
    %outfile.openForWrite("new" SPC %file);
    %linecounter = 0;
    while(!%file.isEOF())
    {
        %linecounter++;
        if(%linecounter == 2)
            %outfile.writeLine(strReplace(%file.readLine(),"MissionGroup",%name));
        else
            %outfile.writeLine(%file.readLine());
    }
    %file.close();
    %outfile.close();
}
replaceMap("Add-Ons/Map_Forest/Map.mis","Map_Forest");

Not tested and written in a rush without indentation.
But I was told the thing to replace is always on the second line, so I made that, hopefully it works.
the arguement and the object have the same variable
gg
« Last Edit: July 08, 2013, 07:25:48 PM by Subpixel »

Code: [Select]
function replaceMap(%file,%name)
{
    %file = new fileObject();
    %file.openForRead(%file);
    %outfile = new fileObject();
    %outfile.openForWrite("new" SPC %file);
    %linecounter = 0;
    while(!%file.isEOF())
    {
        %linecounter++;
        if(%linecounter == 2)
            %outfile.writeLine(strReplace(%file.readLine(),"MissionGroup",%name));
        else
            %outfile.writeLine(%file.readLine());
    }
    %file.close();
    %outfile.close();
}
replaceMap("Add-Ons/Map_Forest/Map.mis","Map_Forest");

Not tested and written in a rush without indentation.
But I was told the thing to replace is always on the second line, so I made that, hopefully it works.
.openFor___ doesn't require any arguments, just so you know.

.openFor___ doesn't require any arguments, just so you know.
?

then how does it know what file to ___?

?

then how does it know what file to ___?
nvm this i screwed up

just ignore that and move on
« Last Edit: July 08, 2013, 07:47:44 PM by Ipquarx »

I fixed it guys, it works fine and I added the removing part too.

the arguement and the object have the same variable
gg
I was about to go when Zapk messaged me.
 :cookieMonster: