Variables are a powerful feature in FancyMenu that let you store and reuse information throughout your menu customizations. They work like containers where you can put different types of data, give each container a name, and then access that data later using the variable name. Variables open up a world of possibilities for creating dynamic menus that change based on conditions you define.
To create a variable in FancyMenu:
That's it! Your variable is ready to use. You can see it listed in the "Manage Variables" screen.
An empty variable isn't very useful on its own. To make variables work for you, you need to put data into them. In FancyMenu, this is called "setting the variable value."
There are two main ways to set a variable's value:
In the "Manage Variables" screen, find the variable in the list, click it, and then click Set Value. Type in the data you want to store.
While customizing your menu, use the Set Variable action on a Button, Slider or Ticker element. With this action, you specify the variable name and the value to store in it. When someone, for example, clicks a button with this action, the variable will update with the new value.
For example, let's say you create a variable named clicks
to count how many times a button is pressed. You would add the Set Variable action to the button, and use a placeholder in the action's value to increment the click count each time, like this:
clicks:{"placeholder":"calc","values":{"expression":"{"placeholder":"getvariable","values":{"name":"clicks"}} + 1"}}
Here's how this works:
clicks
variable.clicks
variable using the Set Variable action.So each time the button is clicked, the clicks
variable will increment by 1, effectively counting the total number of clicks.
Now that you have variables holding data, you can use that data in different parts of your menu customization:
Loading Requirements: You can check a variable's value in a loading requirement to control when certain menu elements appear. For example, you could make an element only show up if the clicks
variable is greater than 5 by using a combination of the Is Number requirement and the Get Stored Variable placeholder.
Placeholders: Variables can be inserted into text using the Get Stored Variable placeholder. If you have a text element, you could use {"placeholder":"getvariable","values":{"name":"clicks"}}
to display the current value of the "clicks" variable.
Nested Placeholders: You can even use variables inside other placeholders! The click counting example above demonstrated this by using the Get Stored Variable placeholder inside the Calculator placeholder.
Actions: Variables can be used in actions to create dynamic behavior based on variable values. Here are a few examples:
Here are a few examples to inspire your own variable usage:
High Score: Create a highscore
variable and a button that sets it to the player's current score if it's higher than the existing value. Display the high score on the menu using the Get Stored Variable placeholder.
Difficulty Selector: Make variables for different game difficulties, like easy
, medium
, and hard
. Use buttons to set the difficulty variable, and show/hide elements based on the selected difficulty.
Tutorial Progress: Add variables to track the player's progress through a tutorial, like tutorial_step
. Increment the variable as they complete each step, and use loading requirements to gradually reveal more of the menu.
Variables combined with FancyMenu's other features give you incredible flexibility to create menus that are tailored to each player's actions and preferences. Experiment with different variable setups to unlock the full potential of your menu customizations!