Forum Discussion
Input Numbers Into Field
- 2 months ago
Consider pay extra attention to which var you are referring to, or have a more recognizable var names.
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]);
}
- JesseWu2 months agoCommunity 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]); } }