9 Replies Latest reply on Sep 2, 2007 7:02 AM by kglad

    "pausing" a function

    Jimmathy Level 1
      how would i stop a function where it is and wait for the ENTER key to be pressed?
        • 1. Re: "pausing" a function
          kglad Adobe Community Professional & MVP
          you can't stop code at arbitrary spots unless you code for that, in advance.
          • 2. Re: "pausing" a function
            Jimmathy Level 1
            well thats what i mean. Like so when it reaches this point in the code it waits for for the enter key to continue on.
            • 3. Re: "pausing" a function
              Jimmathy Level 1
              well thats what i mean. Like so when it reaches this point in the code it waits for for the enter key to continue on.
              • 4. Re: "pausing" a function
                kglad Adobe Community Professional & MVP
                give an example of code that you want to break and the point at which you want it to break.
                • 5. Re: "pausing" a function
                  TimSymons Level 1
                  You could just break your function into multiple functions. Then call the first part and then call the second part after the user presses the enter key. When using the event listeners, make sure to remove them in the current function and then add them back at the end.

                  Kind of like this (this is just stub code...nothing here will actually compile)

                  myButton.addEventListener(MouseEvent.CLICK, part1);

                  function part1(e:Event):void {
                  myButton.removeEventListener(MouseEvent.CLICK, part1);
                  // put the code here that you want
                  myButton.addEventListener(MouseEvent.CLICK, part2); // wait for user to click to execute next part of function
                  }

                  function part2(e:Event):void {
                  myButton.removeEventListener(MouseEvent.CLICK, part2);
                  // put the code here that you want
                  }


                  Tim
                  • 6. Re: "pausing" a function
                    Jimmathy Level 1
                    oh jeeze, an example.... well heres the deal; ive been programming an RPG game that uses sharedobjects to save all sorts of variables like: -respect -good/evil -currentmap -landowned -rank -name etc. as you do stuff u get #s set for these variables.

                    Heres where my problem came in, im trying to code conversation but depending on ur "good/evil" and "respect" variable different conversations occur. So like if you are evil but low in respect the NPC will talk to you rudely.

                    so obviously this is goin to be a complex code, and i was trying to figure out an eisier way than i was originally coding it b/c its SOOO confusing i have to draw out a diagram to figure out where i missed a bracket.

                    there is an imput text box, lets call it response, that u type ur answers into.


                    so ill write an example code of what i want:


                    function manchat(){
                    if ( good>5){
                    text = " Hello" + title+ " " + name + ", how are you doing today?"
                    //HERE IS WHERE I WANT IT TO WAIT FOR ENTER TO MOVE ON
                    if(response==good){
                    text="That's good"
                    }
                    else{
                    text="Im sorry "+ title+ ", I dont speak jibberish"
                    }}
                    else if(good<5){
                    text="What do you want fram me, " + title + "!?!?"
                    //WAIT FOR ENTER i think you get the picture.
                    }
                    }

                    the function will be executed when you click on the NPC.
                    but the conversations may go in as many as 3 responses
                    So how would I make it wait for enter to move on like that if it is possible.
                    • 7. Re: &quot;pausing&quot; a function
                      kglad Adobe Community Professional & MVP
                      (use the attach code option to display code in this forum. your code will be much more readable:

                      • 8. Re: &quot;pausing&quot; a function
                        Jimmathy Level 1
                        okay.... that looks like it should work. But there appears to be something wrong with the second funtion u gave me.
                        something to do with object() will not resolve.. not sure what that means
                        • 9. Re: &quot;pausing&quot; a function
                          kglad Adobe Community Professional & MVP
                          oops, that should be: