Skip to content

Commit

Permalink
uhhh messy code
Browse files Browse the repository at this point in the history
  • Loading branch information
yetnt committed Apr 21, 2024
1 parent 5452990 commit 3844b6b
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 27 deletions.
2 changes: 1 addition & 1 deletion BP/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"version": [
0,
1,
6
7
]
},
"modules": [
Expand Down
68 changes: 42 additions & 26 deletions BP/scripts/funcs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@ function secondsToTicks(num: number): number {
return num * 20
}

let re;
const r = {
s: (func: () => void) => {
re = system.runInterval(func, secondsToTicks(4));
},
c: () => {
re = system.clearRun(re);
}
}

function doevery(p: Player, msg: string) {
const [, name, t] = msg.split(" ");
console.warn(t)
Expand Down Expand Up @@ -45,38 +55,44 @@ function doevery(p: Player, msg: string) {
let shouldStop = false;

// user took too long to respond, so remove event, maybe use [current < current + (timeout * 1000)] for calc
while (cont == false) {
if (run == undefined) {
run = system.runTimeout(() => {
error(p, "You took too long to respond. The command subscription has been canceled.");
shouldStop = true; // Set the flag variable to indicate that the function should stop.
cont = true;
return;
}, secondsToTicks(timeout));
}
}
r.s(() => {
if (cont == false) {
if (run == undefined) {
run = system.runTimeout(() => {
error(p, "You took too long to respond. The command subscription has been canceled.");
world.afterEvents.chatSend.unsubscribe(event);
shouldStop = true; // Set the flag variable to indicate that the function should stop.
cont = true;
return;
}, secondsToTicks(timeout));
}
} else {

world.afterEvents.chatSend.unsubscribe(event);
world.afterEvents.chatSend.unsubscribe(event);

if (shouldStop) return;

// Rest of doevery code, finally.
if (shouldStop) return;

ints[name] = system.runInterval(() => {
let count: number = 0;
try {
p.runCommand(executable)
} catch (err) {
count++
if (count > 5) {
delete ints[name]
error(p, `Task with the name (${name}) has failed more than 5 times. Execution has automatically been stopped and task has been cleared.`)
}
}
}, secondsToTicks(time))
// Rest of doevery code, finally.

ints[name] = system.runInterval(() => {
let count: number = 0;
try {
p.runCommand(executable)
} catch (err) {
count++
if (count > 5) {
delete ints[name]
error(p, `Task with the name (${name}) has failed more than 5 times. Execution has automatically been stopped and task has been cleared.`)
}
}
}, secondsToTicks(time))

p.sendMessage(`Task with the name (${name}) has been added!`)
r.c();

p.sendMessage(`Task with the name (${name}) has been added!`)
}
})
}

function stopevery(p: Player, msg: string) {
Expand Down

0 comments on commit 3844b6b

Please sign in to comment.