x


Pause, Play and Rewind buttons for a function

Hello,

I have written a function and in my Project's GUI i got buttons with the names :

Pause, Play, Rewind.

It's all good until now, but when i capsule the buttons into each other (first play gets pressed, then rewind, pause, play etc)

It starts my function Multiple times and this isn't what i'm looking for.

Linking the functions OnGUI() and Dashboard()

 function Dashboard()
{
    var lines = Source.text.Split("\n"[0]);
    for(i = counter; i < lines.Length; i++)
    {

        DrehungSpeed_alt = DrehungSpeed;
        DrehungRpm_alt = DrehungRpm;
        DrehungHitze_alt = DrehungHitze;
        var values = lines[i].Split(";"[0]);
        DrehungSpeed = int.Parse(values[4]);
        DrehungRpm = int.Parse(values[8]);
        DigitalSpeed = int.Parse(values[4]);
        zeilennr = i;
        //DrehungHitze = int.Parse(values[XXXX]);
        DrehungSpeed = Mathf.Clamp(DrehungSpeed/300.0 * 180.0,0.0,180.0);
        DrehungRpm = Mathf.Clamp(DrehungRpm/8000.0 * 240.0,0.0,240.0);

        DigitalRPM = int.Parse(values[8]);
       yield WaitForSeconds(0.5);
       counter = i;
       if(Paused == true) 
       { 
         Rewinding = false;
         ErsterWert = false;
         LetzterWert = false;
         break;


       }

       if(Rewinding == true)
       {
             Paused = false;
             ErsterWert = false;
             LetzterWert = false;
             for(i = counter; i > 4; i--)
           {

        values = lines[i].Split(";"[0]);
        DrehungSpeed_alt = DrehungSpeed;
        DrehungRpm_alt = DrehungRpm;
        DrehungHitze_alt = DrehungHitze;

        DrehungSpeed = int.Parse(values[4]);
        DrehungRpm = int.Parse(values[8]);
        DigitalSpeed = int.Parse(values[4]);

        //DrehungHitze = int.Parse(values[XXXX]);
        DrehungSpeed = Mathf.Clamp(DrehungSpeed/300.0 * 180.0,0.0,180.0);
        DrehungRpm = Mathf.Clamp(DrehungRpm/8000.0 * 240.0,0.0,240.0);

        DigitalRPM = int.Parse(values[8]);
       yield WaitForSeconds(0.5);
       counter = i;



           }

    } 

        if(ErsterWert == true)
        {
           Paused = false;
           Rewinding = false;
           LetzterWert = false;


           values = lines[4].Split(";"[0]);
           DrehungSpeed = int.Parse(values[4]);
            DrehungRpm = int.Parse(values[8]);
            DigitalSpeed = int.Parse(values[4]);
            //DrehungHitze = int.Parse(values[XXXX]);

            DrehungSpeed = Mathf.Clamp(DrehungSpeed/300.0 * 180.0,0.0,180.0);
            DrehungRpm = Mathf.Clamp(DrehungRpm/8000.0 * 240.0,0.0,240.0);

            DigitalRPM = int.Parse(values[8]);
         yield WaitForSeconds(0.5);
        }

        if(LetzterWert == true)
        {
           Paused = false;
           Rewinding = false;
           ErsterWert = false;

           var endwert = lines.length - 1.0;

           values = lines[endwert].Split(";"[0]);
           DrehungSpeed = int.Parse(values[4]);
            DrehungRpm = int.Parse(values[8]);
            DigitalSpeed = int.Parse(values[4]);
            //DrehungHitze = int.Parse(values[XXXX]);

            DrehungSpeed = Mathf.Clamp(DrehungSpeed/300.0 * 180.0,0.0,180.0);
            DrehungRpm = Mathf.Clamp(DrehungRpm/8000.0 * 240.0,0.0,240.0);

            DigitalRPM = int.Parse(values[8]);
         yield WaitForSeconds(0.5);

        }

}
}function OnGUI(){


    if(GUI.Button(Rect(10,10,50,50),"Play")) 

    {  
       Dashboard();       
    }










    if(GUI.Button(Rect(10,130,70,50),"Rewind")) 
    {
       Rewinding = true;
    }


    if(GUI.Button(Rect(10,190,100,50),"Erster Wert"))
    {
       ErsterWert = true;
    }


    if(GUI.Button(Rect(10,250,100,50),"Letzter Wert"))
    {
       LetzterWert = true;
    }

    if(GUI.Button(Rect(10,310,100,50),"Close"))
    {
       Application.Quit();
    }

    GUI.Box(Rect(0,1080,Screen.width,Screen.height/4.0),"Zeilennummer : " + i + "\n" + "Geschwindigkeit : " + DigitalSpeed + "\n" + "Umdrehungen Pro Minute : " + DigitalRPM + "\n");
more ▼

asked Jul 12 '11 at 10:44 AM

biohazard gravatar image

biohazard
288 36 42 46

The German variable names I can manage, but your formatting makes it unreadable regardless. Please fix.

Jul 12 '11 at 01:06 PM Waz

Formatting doesn't matter at all...

Jul 12 '11 at 01:15 PM biohazard

It does to people who you want to read that mess. We aren't compilers.

Jul 12 '11 at 01:29 PM Waz

short from of the code : i'm reading a file with racing values like velocity and engine rotation and rotating a dashboard's needles with them. now i want play, pause and rewind buttons.

Jul 12 '11 at 01:33 PM biohazard
(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

It's starting Dashboard multiple times, because that's what your code tells it to do (eg. whenever you toggle Pause). Start it once, then control it through the variables, otherwise you're just going to get into a big mess.

more ▼

answered Jul 12 '11 at 01:42 PM

Waz gravatar image

Waz
6.4k 22 33 70

oh i forgot to update the script. 1 sec

Jul 12 '11 at 01:43 PM biohazard

@Warwick Allison script updated

Jul 12 '11 at 01:45 PM biohazard

I think you need to restructure that code to have a single loop. For example, how are you going to pause or play while rewinding?

Jul 12 '11 at 02:10 PM Waz

that exactly is the problem i keep running into

Jul 12 '11 at 02:11 PM biohazard

So learn, and stop contradicting. "Formatting doesn't matter at all" is about the most ignorant comment I've ever seen on this site.

Jul 12 '11 at 03:00 PM Waz
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3723
x3676
x260
x224
x20

asked: Jul 12 '11 at 10:44 AM

Seen: 911 times

Last Updated: Jul 12 '11 at 03:00 PM