Click here to Skip to main content
16,012,025 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello !

I want to write every data at each frame :

C#
    void FixedUpdate() {

        // To associate names_markers to avatar_joints :
        if (frame < nv_data [0].positions.Length) {

            for (int k = 0; k < body.Length; ++k) {

                                if (body [k] != null) { 

           body[k].transform.localPosition = nv_data[k].positions [frame] / 1000;
                                } else
                                        continue;
                        }

            if (frame < forces_dup.Length) {

                if (frame > 1) {

StreamWriter writer = new StreamWriter ("1_forces_reelles_virtuelles.txt");

                        using (writer) {

writer.WriteLine ((40 * nv_data [55].positions [frame] - nv_data [55].positions [frame - 1]).magnitude / (1000 * Time.deltaTime));
writer.WriteLine (forces_dup [frame].magnitude / 1000);

                    }
                }
            }

        frame++;

    }

}


And in the text file, it appears only the last datas of :
- (40 * nv_data [55].positions [frame] - nv_data [55].positions [frame - 1]).magnitude / (1000 * Time.deltaTime)
- forces_dup [frame].magnitude / 1000

When I use "Debug.Log" to show datas, all appear in the console.
I assume that the other lines are erased at each frame.

How can I save every line of datas ?

I try to do it in void Update (but it's the same result) :

C#
// Update is called once per frame
void Update() {

    string forces_virtuelles;
    string forces_reelles;

    if (frame < forces_dup.Length) {

        if (frame > 1) {

            forces_virtuelles = ((40 * nv_data [55].positions [frame] - nv_data [55].positions [frame - 1]).magnitude / (1000 * Time.deltaTime)).ToString();
            forces_reelles = (forces_dup[frame].magnitude/1000).ToString();

StreamWriter writer = new StreamWriter ("1_forces_reelles_virtuelles.txt");

            using (writer) {

                writer.WriteLine (forces_virtuelles + "\n");
                writer.WriteLine (forces_reelles + "\n");

            }

        }

    }

}



The first part runs well, even with the second part :

C#
    void FixedUpdate() {

        // To associate names_markers to avatar_joints :
        if (frame < nv_data [0].positions.Length) {

            for (int k = 0; k < body.Length; ++k) {

                                if (body [k] != null) { 

           body[k].transform.localPosition = nv_data[k].positions [frame] / 1000;
                                } else
                                        continue;
                        }

            }

        frame++;

    }

}


Can you help me please ?
Posted

1 solution

You should append data to the file, replace
Quote:
new StreamWriter ("1_forces_reelles_virtuelles.txt");
with
C#
new StreamWriter ("1_forces_reelles_virtuelles.txt", true);


see "StreamWriter Constructor (String, Boolean)"[^].
 
Share this answer
 
Comments
Coralie B 18-Mar-15 5:08am    
Thank you very much ! :D
CPallini 18-Mar-15 5:45am    
You are welcome.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900