Meta Horizon Worlds, the immersive and creative virtual platform, continues redefining user-generated content possibilities. One of its standout features is Codeblocks scripting, which allows users to bring their virtual worlds to life with custom interactions, animations, and calculations. In this blog post, we’ll dive into the fascinating world of Codeblocks scripting and explore how to use it to extract the maximum value from an array of numbers.
The Scenario
Imagine you have an array of numbers: [3, 5, 1, 7], and you want to find the largest value within this array. While this may seem like a simple task, it’s a perfect opportunity to demonstrate the power and flexibility of Codeblocks scripting in Meta Horizon Worlds.
The Script Overview

Understanding the Script
- Variable Initialization: The script starts by declaring three variables:
values
: This variable holds the array of numbers [3, 5, 1, 7].maxValue
: Initially undefined, this variable will eventually store the maximum value from the array.i
: This variable serves as a counter to iterate through the array.
- Starting the Process: The script is triggered when the world is started.
- Sending the getMaxValue Signal: Inside the “When world is started” block, the script sends a signal called
getMaxValue
to itself, passing along thevalues
array. - Receiving the Signal: When the
getMaxValue
signal is received with thevalues
array as a parameter, the script enters a loop that will iterate through each element of the array. - Iterating Through the Array: The
while
loop continues as long asi
(the counter) is less than the length of thevalues
array. - Comparing Values: Inside the loop, there’s an
if
statement that compares the current item in the array, accessed usingget item i from values
, with themaxValue
variable. - Updating maxValue: If the current array item is greater than the current
maxValue
, the script updatesmaxValue
with the new, larger value. - Iteration Progress: After each iteration, the
i
counter is incremented by 1 usingset i to i + 1
, ensuring that the script moves on to the next item in the array.
The Result
In your example, the array [3, 5, 1, 7] is provided. The script efficiently iterates through the array, compares values, and updates maxValue
accordingly. At the end of the loop, maxValue
contains the maximum value from the array, which, in this case, is 7.
Conclusion
Codeblocks scripting in Meta Horizon Worlds empowers creators to craft dynamic and interactive experiences within their virtual realms. You can achieve a wide range of effects and functionalities by understanding how to manipulate variables, use conditional statements, and execute loops. In this example, we’ve seen how to extract the maximum value from an array, showcasing the versatility and potential of Codeblocks scripting in the Meta Horizon Worlds ecosystem. As you continue to explore this exciting platform, remember that the possibilities are limited only by your creativity and coding prowess. Happy scripting!
Was this content helpful?
If you found this information helpful, please consider supporting ShadalVR Creates by sending a small donation or becoming a subscribing member and getting unlimited access to assets from ShadalVR Creates.