> ## Content Index
> Fetch the complete content index at: https://blog.arcweave.com/llms.txt
> Use this file to discover other available public pages before exploring further.

# Use Arcweave's visits function to check visited elements
- URL: https://blog.arcweave.com/check-visited-elements-in-arcweave-with-the-visits-function/
- Published: 2023-12-04T10:39:45.000Z
- Updated: 2026-09-19T06:37:38.000Z
- Description: Learn how to check visited elements in Arcweave using the visits() function. Relieve your global variables list and efficiently track player choices.
- Author: Giannis Georgiou
- Tags: tutorials, productivity

## You don't need to create a variable for every thing the player does.

To track whether the player has made specific choices or played specific parts of your story, one way is to store the information in a **global variable** and check its value when needed. For example, the value of the `met_Balrog` variable determines whether the player can see the Balrog in the camping description, as well as get the option to talk to them.

[![Arcweave screenshot: the value of a variable called "met Balrog" is checked in an element and a branch, offering the option to talk to the Balrog.](https://blog.arcweave.com/content/images/hubspot/8b9ecf27d766c3fb381299ae.png)](https://blog.arcweave.com/content/images/hubspot/8b9ecf27d766c3fb381299ae.png)

This works, but it can soon blow your list of global variables out of proportions. Imagine having tens of variables, one for every story or dialogue branch that needs to be checked later on.

To solve this issue, we implemented **visits()**, a function that checks if and how many times the player has visited a specific element. You should use visits() instead of a variable whenever you can, to avoid cluttering your variables list.

## Key takeaways

- Use visits() to check whether a player has reached an element instead of maintaining a separate flag for that visit.
- Reference another element to check its visit count, or call visits() without an argument to refer to the current element.
- Use the result in a condition or compare the count explicitly when repeated visits should change the story.

Let’s see the visits() function in action.

## Add a visits check to another element

Consider the story sample *Red Riding Hood’s Mum,* which you may have already seen in my older blog post [Write your interactive story with Arcweave](https://blog.arcweave.com/write-your-interactive-story-with-arcweave). To check whether the Wolf has come with us, we can actually use the `visits()` function, instead of the global variable `with_wolf`.

(If you haven't read that post, perhaps you'd like to give it a read first, so that you understand the changes we apply here.)

This is how it initially looks:

[![Arcweave screenshot of the Red Riding Hood's Mum, before applying the "visits" function.](https://blog.arcweave.com/content/images/hubspot/2cffff4a649b6ad408241699.png)](https://blog.arcweave.com/content/images/hubspot/2cffff4a649b6ad408241699.png)

We split the choice in 2 elements and adjust the contents accordingly: one where the Wolf follows and one where he stays put. Then, both branches rejoin the flow, as the player approaches the cottage.

[![Arcweave screenshot on the moment of asking the wolf to follow or stay: one element for each option.](https://blog.arcweave.com/content/images/hubspot/7201751b4d19804feb7242b7.png)](https://blog.arcweave.com/content/images/hubspot/7201751b4d19804feb7242b7.png)

This way, not only do we get a separate element for each option, content and all, but we can also check which of the two elements the player has visited.

From the cottage element, delete the branch’s “if” code and start typing: `if visits(@wolf..`. As soon as you type the ‘@’ character—just as with mentioning components or boards—a list of **element titles** will appear. Typing “wo…” narrows the list down.

[![Screenshot demonstrating how we type the argument of the "visits" function using the @ character and choosing from the list of element titles.](https://blog.arcweave.com/content/images/hubspot/68555bb9e5a1e26c340c7089.png)](https://blog.arcweave.com/content/images/hubspot/68555bb9e5a1e26c340c7089.png)

Select *Wolf joined.* Then, close the parentheses. Your branch now will look like this:

[![Screenshot of a branch using the visits function to check whether the player has visited the element "Wolf joined."](https://blog.arcweave.com/content/images/hubspot/198f15ede914096921c6367c.png)](https://blog.arcweave.com/content/images/hubspot/198f15ede914096921c6367c.png)

You can now delete the `met_wolf` variable from your Global Variables list. Make sure you're not using it anywhere else—otherwise, use the visits() function, there, too.

Congratulations, you've just eliminated an unused variable!

## The argument of visits

Notice that the element’s title *Wolf joined* gets converted to snake\_case (`wolf_joined`) and—similar to what happens with board & component mentions, the “@” character disappears.

Moreover, the function’s argument is now a **link to the source element**. Click it and you’ll teleport to the element it refers to.

Note: make sure you give your important elements a title, so you can easily mention them as arguments of the `visits()` function.

## Number or boolean returned?

By using `visits()` in the above syntax, it returns `false` (if the number of visits is `0`) or `true` (if greater).

In case we need to use the actual returned number of visits, we can apply a relevant syntax, as in this case:

[![Arcweave screenshot: a mini-game loop, where you drink cups of milk and the game counts them for you, using the "visits" function](https://blog.arcweave.com/content/images/hubspot/fa883629d57bc2563062ff40.png)](https://blog.arcweave.com/content/images/hubspot/fa883629d57bc2563062ff40.png)

In the first element, titled *Calculate milk* the `show()` function takes as argument the value returned by the `visits()` function, counting the visits to the *Drink milk* element. (Careful with all the parentheses!) Every time we visit the *Drink milk* element, the number rendered by `show()` increments.

---

You have drunk

`show(visits(drink_milk))`

cups of milk.

---

Of course, this produces "1 cups of milk," so you ideally want to add an if/else condition that saves your grammar:

---

You have drunk

`show(visits(drink_milk))`

`if visits(drink_milk) == 1`

cup

`else`

cups

`endif`

of milk.

---

## Call visits from within the same element

Here's one last trick: if we call `visits()` from inside an element and want to mention the element itself, we can do so by calling it **without an argument**.

---

You have visited this element

`show(visits())`

time(s).

---

## Video tutorial on visits

To study the `visits()` function in more detail and with more examples, watch Episode 21 from our YouTube tutorial series:

---

The `visits()` function is an easy way to check how many times the player has visited a specific element. Use it whenever you can, instead of creating variables for everything the player has done. Its intuitive mentioning of element titles makes it super easy to use—and it's definitely worth decluttering your Global Variables list!