9 Replies Latest reply on Sep 4, 2013 2:30 PM by AMULI

    Point system? Help with variables.

    nshebroe

      Hello,

       

      I am creating a basic simulation game which features 3 different "teachers" presenting information at a conference. The user selects a teacher and is presented with a question to answer. They are given 3 choices and can score 0, 1, or 2 points depending on the correctness of their choice.

       

      I am working on displaying the scores on a results page. It should show the result for each of the 3 instructors and the total of their choices.

      e.g. the screen says:

       

       

       

      Reviewer Report:

      Alex: 0/2 reviewer points

      Bernice: 0/2 reviewer points

      Carla: 0/2 reviewer points

       

      Total score: 0/6


       

       

      The 0s would update based on the points received through the game.

       

      I have the variables displaying on the results page and will update as long as I hardcode in the variables so I know the code on the stage works, but I'm having trouble updating the variables based on the users progress through the game.

       

      This is the code on the stage at compositionReady:

       

       

       

      var alex_count = 0;

      var bernice_count = 0;

      var carla_count = 0;

      var FinalScoreHolder = carla_count + bernice_count + alex_count;

       

      sym.$("alex_count").html("ALEX: "+alex_count+"/2 reviewer points earned");

      sym.$("bernice_count").html("BERNICE: "+bernice_count+"/2 reviewer points earned");

      sym.$("carla_count").html("CARLA: "+carla_count+"/2 reviewer points earned");

      sym.$("grade").html("Total Score: "+FinalScoreHolder+"/6");

       

       

       

      Again, this part works and shows in textboxes on the screen in the report screen.

       

      This code is on each of my choice buttons. Basically, the variables should update to these numbers for the score depending on if a certain choice is selected and then it will go play the corresponding scene. It's the same code on all of the buttons, but this is just taken from one option. The variables are not being updated to the report page.

       

       

       

      if(currentLabel=="alex1"){

          sym.play("alex_ql");

          alex_count=0;

      }

       

      else if(currentLabel=="bernice1"){

          sym.play("bernice_ql");

          bernice_count=2;

      }

       

      else if(currentLabel=="carla1"){

          sym.play("carla_ql");

          carla_count=1;

      }

       

       

       

       

      Any suggestions or help would be appreciated. Thank you!

        • 1. Re: Point system? Help with variables.
          AMULI Level 4

          Hi nshebroe,

           

          Your description and snippets give only a few pieces of the whole puzzle

           

          var FinalScoreHolder = carla_count + bernice_count + alex_count;

          This should not be summed up in compositionReady but after navigating through the quizz ?

           

          Using the var keyword you declare local variables. Duplicating the code "on each of my [your] buttons", you duplicate local variables with the same name !

           

          I guess you need global variables, defined in the stage symbol, in the compositionReady event handler and may be assigned in other symbols.

           

          1) Look at the sym.setVariable() and sym.getVariable() methods in the API :

           

          http://www.adobe.com/devnet-docs//edgeanimate/api/current/index.html#symbolinstance

           

          2) Or use a JavaScript object, initialized in the compositionReady event handler :

           

          scores =

          {

            jim : 0,

            laura : 0,

            ben: 0

          };

           

          Then elsewhere (inside any symbol) : scores.laura += 5; to increase by 5 this score.

           

          Gil

          1 person found this helpful
          • 2. Re: Point system? Help with variables.
            AMULI Level 4

            More on global variables here (with an example to download) :

             

            http://forums.adobe.com/message/5512963#5512963

             

            Gil

            • 3. Re: Point system? Help with variables.
              nshebroe Level 1

              Hello,

               

              Thanks for your response.

               

              Perhaps you could help me a little more...

               

              sym.setVariable("alex_count", 0);

              sym.setVariable("bernice_count", 0);

              sym.setVariable("carla_count", 0);

               

              alex_count = sym.getVariable("alex_count");

              bernice_count = sym.getVariable("bernice_count");

              carla_count = sym.getVariable("carla_count");


              sym.setVariable("FinalScoreHolder", carla_count+alex_count+bernice_count);

              FinalScoreHolder = sym.getVariable("FinalScoreHolder");

               

              //alert(alex_count);

               

              sym.$("alex_count").html("ALEX: "+alex_count+"/2 reviewer points earned");

              sym.$("bernice_count").html("BERNICE: "+bernice_count+"/2 reviewer points earned");

              sym.$("carla_count").html("CARLA: "+carla_count+"/2 reviewer points earned");

              sym.$("grade").html("Total Score: "+FinalScoreHolder+"/6");

               

              This is my updated code on the stage. I want the variables and total to display 0 first as they have the option to click the button at any time, and could click it before having any updated scores, so it should reflect a 0 starting point. I  have tried to place the FinalScoreHolder variable on a trigger that occurs at the start of the results portion of the timeline, but it does not seem to affect the stage whatsoever and produces an error. It only displays the proper number when I place it at compositionReady. Do you have any thoughts?

               

              I have changed all of the variables to the method you suggested and as of right now, they all display on the results page as they are coded there, but I'm still having trouble with the updating through the button clicks. What is the proper way to update the variable when using the setVariable/getVariable methods?

               

              This is what I had tried.... just a typical variable declaration.

               

              if(currentLabel=="alex1"){

                  alex_count=91;

                  //alert(alex_count);

                  sym.play("alex_mix");

              }

               

              I alerted the number to check, and it is at 91. I also alerted the variable on the next screen, which also displayed 91. I placed an additional alert on the report screen which also showed 91 which is good... BUT I'm not sure what I'm doing wrong, as the number displayed on the report screen text is still 0... so obviously there is a discrepency between the variables and the button click is not updating the original variable.

               

              My issue is that the user is able to go through the simulation as many times as they would like, and the score should override itself. If the score was constantly updated +1 (or any other number), it would  exceed the 2 point max if the user went through it again and again. The score should replace itself, which is why I had just set the variable again on the buttons, and not used any counting/addition techniques.

               

              Thanks for your time again.

              • 4. Re: Point system? Help with variables.
                AMULI Level 4

                Sorry, nshebroe, but despite your detailled description, it's impossible for me to figure out what you have in your mind.

                 

                It's not only a matter of syntax, but also a matter of where you place those snippets of code, which are out of context in your post

                 

                I suggest you Save as a simplified (and commented) version of your project in another folder, zip that folder, upload the archive to a dropbox and send me the link where a can download.

                 

                Then I will look at your source file and provide feedback.

                 

                Gil

                • 5. Re: Point system? Help with variables.
                  nshebroe Level 1

                  Yeah, sorry about that!

                   

                  Thanks so much again... Here is my file for you to download: https://www.dropbox.com/s/itn1rvl1ah1db7a/unit3_help.zip

                   

                  The parts to pay attention to:

                  • The  code on the stage, with the snippets that I have already written above
                  • the code on the buttons that are labeled as "mix_btn" "qual_btn" and "quan_btn" - the code that I was working on changing is located in the "mix_btn" actions
                  • The final label on the timeline labeled "report" - which shows the animation/screen for the scores to come up

                  • The button in the lower right corner of the "home page" is the one to click to bring up the report
                  • Click on an instructor to start and then choose one of the 3 buttons
                  • Click the conference button in the lower left corner to return to the "home page"
                  • 6. Re: Point system? Help with variables.
                    AMULI Level 4

                    Nice and sophisticated composition

                     

                    I will dive into the source as soon as I find time to.

                     

                    Gil

                    • 7. Re: Point system? Help with variables.
                      AMULI Level 4

                      Hi nshebroe,

                       

                      Stage > counter.click :

                       

                      var counter = sym.getVariable("counter");

                      counter++;

                      sym.$("counter").html(counter);

                      sym.setVariable("counter", counter);

                       

                      Preceding counter with the var keyword, this variable is local to the event handler.

                       

                      Stage > mix_btn.click :

                       

                      if(currentLabel=="alex1")

                      {

                          alex_count=91;

                          sym.play("alex_mix");

                      }

                       

                      Without the var keyword, the alex_count is global, more precisely accessible anywhere in the symbol (Stage).

                       

                      sym.getVariable("alex_count", 12); is the statement to use to assign 12 to the variable alex_count, in case you want it to be accessible in another symbol.

                       

                      sym.setVariable ("currentLabel"); is a false statement,

                      as is alex_count = sym.getVariable("alex_count");.

                       

                      I suggest you read the following thread to clarify the methodology with global variables :

                       

                      http://forums.adobe.com/thread/1288441?tstart=0

                       

                      I did not get into the details of your timeline, which is fairly complex, but as far as I understand everything about counting happens inside the Stage symbol. So following this schema will fit :

                       

                      1) Stage.compositionReady event handler :

                      alex_count = 0;

                       

                      2) Stage.trigger at the end of a sequence when Alex makes points

                      alex_count += 10;

                       

                      3) Stage.trigger at label report

                      sym.$("total_alex").html( alex_count);

                       

                      Gil

                      • 8. Re: Point system? Help with variables.
                        nshebroe Level 1

                        My eternal gratitude as I have finally figured it out. Thanks so much for your time and help!

                        • 9. Re: Point system? Help with variables.
                          AMULI Level 4

                          Thank you for your gratitude. I am glad if it's now clear in your mind

                           

                          Gil