Skip to content

ModPE Script Tutorials

Connor4898 edited this page Nov 9, 2013 · 1 revision

This will teach you some of the basics of ModPE, and some neat tricks too. Currently under development

##modTick Timer Tutorial - Connor4898 This template will hopefully teach you the basics of timers or countdowns in ModPE. Hopefully

Ok, so first, we need a function called modTick (Obviously)

function modTick() {

}

modTick executes the code inside it's { } 20 times in a second

function modTick() {
    clientMessage("Super awesome spam message");
}

This spam message will fill your screen instantly, not the best idea for a timer

So lets say we want to create a code that sends a message after 5 seconds of tapping any block

We'll need another callback, useItem

function useItem(x,y,z,itemId,blockId,side,itemDamage,blockDamage) {
    clientMessage("You tapped a block!");
}

Now, we need to make the useItem callback activate the modTick callback

We'll do this using the variable timerActive

var timerActive = false;

function useItem(x,y,z,itemId,blockId,side,itemDamage,blockDamage) {
    clientMessage("You tapped a block!");
    timerActive = true;
}

function modTick() {
    if(timerActive == true) {
        clientMessage("Super awesome spam message");
    }
}

This will delay the spam message until we tap a block

But it still does not spam 5 seconds afterwards

So we need to add a timer. We'll store the timer number as a variable, countdown

var countdown = 0;

Now we need to add this to modTick

var timerActive = false;
var countdown = 0;

function useItem(x,y,z,itemId,blockId,side,itemDamage,blockDamage) {
    clientMessage("You tapped a block!");
    timerActive = true;
}

function modTick() {
    if(timerActive == true) {
        countdown++;
        clientMessage("Super awesome spam message");
    }
}

Here, we added countdown++;. This is the same as countdown = countdown + 1;.

This increases the value of countdown by one.

Now, we need to make something happen after 5 seconds

var timerActive = false;
var countdown = 0;

function useItem(x,y,z,itemId,blockId,side,itemDamage,blockDamage) {
    clientMessage("You tapped a block!");
    timerActive = true;
}

function modTick() {
    if(timerActive == true) {
        countdown++;
        if(countdown >= 100) {
            clientMessage("Super awesome spam message");
        }
    }
}

Now, 100 ticks (5 Seconds) after tapping a block, the spam message will appear.

But, we don't have a way to stop the spam message

var timerActive = false;
var countdown = 0;

function useItem(x,y,z,itemId,blockId,side,itemDamage,blockDamage) {
    clientMessage("You tapped a block!");
    if(timerActive == false) {
        clientMessage("This activated the spam");
        timerActive = true;
    } if(timerActive == true) {
        clientMessage("This deactivated the spam");
        timerActive = false;
    }
}

function modTick() {
    if(timerActive == true) {
        countdown++;
        if(countdown >= 100) {
            clientMessage("Super awesome spam message");
        }
    }
}