Discord
Login
Community
DARK THEME

Advanced help

How do i make it so you can get a element from an index in a list and output the value from the element,for my other programming language

Good question if you are using microScript then should look something like this:

getValueFromCustomList = function(target_list, custom_index)
  if custom_index >= 0 and custom_index < target_list.length then
    local result = target_list[custom_index]
    print("Custom Output: " + result) 
    return result
  else
    print("Error: Index out of bounds!")
    return 0
  end
end

// Example usage inside your language manager:
// Suppose your language has a list stored in an object:
variables = object
  user_list = [10, 20, 30, 40]
end

// If the user runs your custom command "GET user_list 2"
getValueFromCustomList(variables.user_list, 2) // Outputs: Custom Output: 30

Or use JavaScript which would be better but more complicated for microStudio, here is the same example but translated in JavaScript:

function getValueFromCustomList(targetList, customIndex) {
  if (customIndex >= 0 && customIndex < targetList.length) {
    let result = targetList[customIndex];
    console.log("Custom Output: " + result); 
    return result;
  } else {
    console.log("Error: Index out of bounds!");
    return null;
  }
}

// Example usage inside your language variables object:
let variables = {
  userList: [10, 20, 30]
};

// If a user runs your custom language command to get the 3rd item (index 2)
getValueFromCustomList(variables.userList, 2); // Outputs: Custom Output: 30

Or you could check out TiberScipt 1.1 in python or TiberScript 1.0 (python for 1.1 and microScript for 1.0) if you want to see it yourself, I hope that helped! :)

Yea,there’s just one problem,the elements are variables

Oh I am so sorry if your list elements are variables, then you just need to do a quick lookup. Store the variable names as strings in your list, then use that string to pull the actual value from your main variables object.

// 1. Grab the variable name (as a string) from your list
// 2. Use that name to look up the actual value in your variables object!
let actualValue = variables[ targetList[customIndex] ];

Hope this helps! :)

I need an example

Post a reply

Progress

Status

Preview
Cancel
Post
Validate your e-mail address to participate in the community