# Scriptable Block Trigger

```lua
function yourEvent(user, block)

    log('block hit! ' .. block.id .. ' by ' .. user.displayName .. ' at block position: ' .. block.position.x .. ' ' .. block.position.y);
    
    local level = getBackground();
    log('current level is: ' .. level);
    
    if level == 'green_grass_background' then 
    --this would be whatever your background name is!
    
        local cd_ready = helper.checkCooldown('cd');
        local cd_timeLeft = helper.cooldownTimeLeft('cd');
        
        if cd_ready == false then
            log('cannot run yet for another ' .. cd_timeLeft .. ' seconds.');
            return;
        end
        
        
        if block.id == 1 then 
            --remember that this id is specific to the current background level,
            --so you might also want to check the level.
            user.runCommand('!jump' );
        end
        
        helper.setCooldown('cd'); 
        --reset the cooldown timer so we have to wait again!
    
    end
end
 
return function()
    addEvent('scriptableBlocks', 'yourEvent'); --attaches the event to yourEvent()
    
    --vv none of this is actually needed it's just showing what else is possible.
    cd = helper.createCooldown(15, true); --15 seconds, starts ready=true
    local level = getBackground();
    
    local scriptBlocks = getScriptableBlocks();
     --give a list of all blocks on the current level
     
    log('the list of blocks on ' .. level .. ' are:');
    for i,block in pairs(scriptBlocks) do
        log(block.id);
        log(block.position.x .. ' ' .. block.position.y);
    end
    
    --^^ none of this is actually needed it's just showing what else is possible.
    keepAlive(); --this is needed.
end
```

{% hint style="info" %}
Events are asynchronous coroutines.
{% 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://docs.streamavatars.com/lua-scripting-api/api-reference-and-tips/events/scriptable-block-trigger.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.
