Click here to Skip to main content
15,888,521 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
The counter frame doesn't incremente.
I try to move the increment in or out curly braces, at different places, and it doesn't run:

C#
void FixedUpdate() {

    delta_time += Time.deltaTime;

    if (frame < nv_data [0].positions.Length) {

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

            if (Ensemble [k] != null) { 

                Ensemble[k].transform.localPosition = nv_data[k].positions[frame];

            } else

                continue;

        }

        Debug.Log (frame); // I have always 0

        if (frame < forces_dup.Length) {

            if (frame >= 1) {

                double delta_x = ((nv_data [12].positions [frame] - nv_data [12].positions [frame - 1]).x);
                vitesse = delta_x / Time.deltaTime;
                acceleration = (vitesse-ancienne_vitesse)/Time.deltaTime;
                ancienne_vitesse = vitesse;

                StreamWriter writer = new StreamWriter ("Accelerations_5Hz.txt", true);

                using (writer) {

                    writer.WriteLine(Time.time + "\t" + (86*acceleration) + "\t" + forces_dup[frame].z);
                }

            }

        }

        frame++;

    }

}
Posted
Updated 26-May-15 23:43pm
v2
Comments
Leo Chapiro 27-May-15 5:43am    
I don't see where you increment "frame"? Is it initialiazed like: int frame = 0; ?

There are too many unknowns in your code for us to possibly know what is going on. Where is "frame" defined and what is its initial value? What is nv_data? How many items are in it? What is "posisionts" and how many "positions" are in nv_data[0]? What is Ensemble and what is its length? What is transform etc etc etc. We can't debug your code remotely, get familiar with stepping through your code using the debugger, inspecting variables etc and you should be able to work out what is happening.

Mastering Debugging in Visual Studio 2010 - A Beginner's Guide[^]
 
Share this answer
 
Comments
Andy Lanng 27-May-15 5:48am    
I agree 80%. There is one unknown and that is 'frame'. It is set only once in the method. What else affects this var?
Everything else is pretty irreverent to the issue as it doesn't directly impact 'frame'
80% is still 4* ^_^
F-ES Sitecore 27-May-15 5:52am    
Look at the very bottom of the code, it has frame++
Andy Lanng 27-May-15 6:06am    
Yes. Like I said: "It is set only once in the method". That is the one time.

I mocked up the code, got rid of the stuff that wasn't relevant and all I was left with was
void FixedUpdate() {
frame++;
}

It must be set elsewhere OR! ooh - just had an idea!
Coralie B 27-May-15 7:44am    
Frame is defined at the very bottom of the code, before void start "int frame;". Its initial value is 0, I declared "frame=0;" at the bottom of void start.

nv_data[i] corresponds to names of markers, and nv_data[i].positions corresponds to data corresponding to the positions of markers. These data come from a text file. nv_data[0].positions.Length = nv_data[i].positions.Length = 41.

Ensemble corresponds to GameObjects what I created in my project. Ensemble[0] corresponds to nv_data[0] etc. If I do it, it's to see the movement of each part through my GameObject Ensemble. Ensemble.Length = 13
F-ES Sitecore 27-May-15 7:55am    
We still can't step through your code, look at the link I posted and step through analysing what is happening.
As per my comment, this was my idea:

(We need to see the whole class to confirm this btw)

is frame a class int? like this:

C#
class myclass{
 int frame;
...
}


and is the class instantiated as new each time like:
C#
var myvar = new myclass();


if that is the case then frame will be zero every time you instantiate the class. If you want the value to persist and still use myclass this way then you need static int frame.

Did I miss the mark on that one? This is mostly guess work without seeing the whole class you have written.
 
Share this answer
 

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