# Code

Sometimes you might not want to store an item, or you may need to modify it before using it. This is where written code can help; you can write a command or function that defines an item, then gives it to a player, or uses it elsewhere, like in a GUI.

Examples:

{% code overflow="wrap" lineNumbers="true" %}

```python
command customSword:
  trigger:
    set {_item} to (1 of diamond sword)
    set ({_item}'s name) to "Super cool item"
    give player {_item}
```

{% endcode %}

{% code overflow="wrap" lineNumbers="true" %}

```python
function getTicket() :: item:
  set {_ticket} to (1 of paper)
  set ({_ticket}'s name) to "Ticket"
  set (line 1 of (lore of {_ticket})) to "Please wait patiently"
  set (line 2 of (lore of {_ticket})) to "until your number is called."
  
  add 1 to {tickets::count}
  set (line 3 of (lore of {_ticket})) to "Ticket number: %{tickets::count}%"
  
  return {_ticket}
  
on right-click on sign:
  give player getTicket()
  send "You have entered the queue, please wait until your ticket number is called." to player
```

{% endcode %}

It might also be a good idea to set-up a memory variable to do the bulk of the work only once:

{% code overflow="wrap" lineNumbers="true" %}

```python
on load:
  set {-ticket} to (1 of paper)
  set ({-ticket}'s name) to "Ticket"
  set (line 1 of (lore of {-ticket})) to "Please wait patiently"
  set (line 2 of (lore of {-ticket})) to "until your number is called."
  set (line 3 of (lore of {-ticket})) to "Ticket number: N/A"

function getTicket() :: item:
  set {_ticket} to {-ticket}

  add 1 to {tickets::count}
  set (line 3 of (lore of {_ticket})) to "Ticket number: %{tickets::count}%"

  return {_ticket}
  
on right-click on sign:
  give player getTicket()
  send "You have entered the queue, please wait until your ticket number is called." to player
```

{% endcode %}

{% hint style="info" %}
Not sure how a command, function, or memory variable works? Check out the following page(s):

* [Functions page](/syntask/fundamentals/structures/functions.md)
* [Commands page](/syntask/fundamentals/structures/commands.md)
* [Variables page](/syntask/storage/variables.md)
  {% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://x8ight.gitbook.io/syntask/storage/code.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
