Forum Discussion

StefanieKirs743's avatar
StefanieKirs743
Community Member
2 months ago

Input Numbers Into Field

Hi everyone,

I am working on a project that requires numbers to be put in fields using keypads. In the first two scenes where I have done this, the numbers go into the field when I click on them. I created a third scene that requires the same thing, and I am having problems getting the numbers to appear ONLY in this scene. 

In my experience (I've come here with problems with this same activity before) the issue is usually either the variables or the Javascript. I've played with both, and the numbers still won't appear when I click on the buttons. 

Can someone please look at this and see if they can figure out where the disconnect is? 

  • Consider pay extra attention to which var you are referring to, or have a more recognizable var names.

  • JesseWu's avatar
    JesseWu
    Community Member

    Consider pay extra attention to which var you are referring to, or have a more recognizable var names.

  • I checked all the variables. If I'm missing something please let me know - from where I'm sitting there isn't a single difference between this slide and the ones like this that work.

    • JesseWu's avatar
      JesseWu
      Community Member

      I touched only the 3 variables I mentioned, and blocked the Set inputField to value DriverIDInput_FI because I don't know what's it function. It works on my run.

      Also, please notice that for now your backspace funtion will delete 1 digit from all 3 variables at the same time. I didn't touch that part. It is another bug.

  • JesseWuhere's the backspace code I have as of now...what could be causing that? I've been playing with it for like an hour and a half now....changed variables, added variables, used three different backspace codes....nothing has worked.

    var player = GetPlayer();
    function removeLastCharacter(Tractor_DriverID) {
        var textEntry = player.GetVar(Tractor_DriverID);
        if (textEntry.length > 0) {
            var newTextEntry = textEntry.slice(0, -1);
            player.SetVar(Tractor_DriverID, newTextEntry);
        }
    }
    var variablesToProcess = ["Tractor_DriverID", "Trailer_Number", "DCCode"];
    for (var i = 0; i < variablesToProcess.length; i++) {
        removeLastCharacter(variablesToProcess[i]);
    }

    • JesseWu's avatar
      JesseWu
      Community Member

      Same pattern: You are calling undesired variables from previous pages.

      Attached for a quick demo. I cannot open 360 files out of my workplace

       

      // Get the player object, which allows us to interact with variables
      var player = GetPlayer();
      
      // Function to remove the last character from a given variable
      function removeLastCharacter(variableName) {
          // Get the current value of the variable
          var textEntry = player.GetVar(variableName);
          // Check if the variable has any characters
          if (textEntry.length > 0) {
              // Remove the last character and update the variable
              player.SetVar(variableName, textEntry.slice(0, -1));
          }
      }
      
      // Create a mapping of focus variables to their corresponding input fields
      var focusMap = {
          "isDCFocused": "DCIDInput_FI",
          "isDriverFocused": "DriverIDInput_FI",
          "isTractorFocused": "TractorNumInput_FI"
      };
      
      // Loop through each focus variable in the mapping
      for (var focusVar in focusMap) {
          // Check if the current focus variable is true (i.e., the input field is focused)
          if (player.GetVar(focusVar)) {
              // Remove the last character from the corresponding input field
              removeLastCharacter(focusMap[focusVar]);
          }
      }