Skip to content

Commit 1528262

Browse files
Limit to 20 ticks per a second
1 parent 5944f8a commit 1528262

File tree

4 files changed

+31
-26
lines changed

4 files changed

+31
-26
lines changed

.github/makecode/blocks.png

7.29 KB
Loading

.github/makecode/blocksdiff.png

-30 Bytes
Loading

main.blocks

Lines changed: 2 additions & 2 deletions
Large diffs are not rendered by default.

main.ts

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ spriteutils.createRenderable(0, function (screen2) {
297297
})
298298
spriteutils.createRenderable(0, function (screen2) {
299299
if (controller.B.isPressed()) {
300-
images.print(screen2, "Raw H/S: " + hash_per_sec, sprite_upgrades_button.left, sprite_upgrades_button.top - 15, 1)
300+
images.print(screen2, "T/S: " + ticks_per_second + "/" + max_ticks_per_second, sprite_upgrades_button.left, sprite_upgrades_button.top - 15, 1)
301301
} else {
302302
images.print(screen2, "H/S: " + average_hash_per_sec, sprite_upgrades_button.left, sprite_upgrades_button.top - 15, 1)
303303
}
@@ -503,11 +503,15 @@ let computer_price = 0
503503
let computer_count = 0
504504
let local_menu_options: string[] = []
505505
let average_hash_per_sec = 0
506-
let hash_per_sec = 0
506+
let ticks_per_second = 0
507+
let max_ticks_per_second = 0
507508
let debug = false
508509
debug = false
510+
max_ticks_per_second = 20
511+
let raw_tick_count = 0
512+
ticks_per_second = 0
509513
let hash_count_per_sec = 0
510-
hash_per_sec = 0
514+
let hash_per_sec = 0
511515
average_hash_per_sec = 0
512516
set_default_save()
513517
make_cursor()
@@ -526,27 +530,28 @@ game.onUpdateInterval(1000, function () {
526530
hash_count_per_sec = 0
527531
average_hash_per_sec += hash_per_sec
528532
average_hash_per_sec = spriteutils.roundWithPrecision(average_hash_per_sec / 2, 2)
533+
ticks_per_second = raw_tick_count
534+
raw_tick_count = 0
529535
})
530536
forever(function () {
531-
for (let index = 0; index <= autoclicker_count - 1; index++) {
532-
timer.throttle("autoclicker_click_" + index, autoclicker_speed, function () {
533-
computer_click()
534-
})
535-
}
536-
})
537-
forever(function () {
538-
for (let index = 0; index <= computer_count - 1; index++) {
539-
timer.throttle("computer_mine_" + index, computer_speed, function () {
540-
check_for_magic_number(randint(0, max_height))
541-
hash_count_per_sec += 1
542-
})
543-
}
544-
})
545-
forever(function () {
546-
for (let index = 0; index <= asic_count - 1; index++) {
547-
timer.throttle("asic_mine_" + index, asic_speed, function () {
548-
check_for_magic_number(randint(0, max_height))
549-
hash_count_per_sec += 1
550-
})
551-
}
537+
timer.throttle("tick", 1000 / max_ticks_per_second, function () {
538+
for (let index = 0; index <= autoclicker_count - 1; index++) {
539+
timer.throttle("autoclicker_click_" + index, autoclicker_speed, function () {
540+
computer_click()
541+
})
542+
}
543+
for (let index = 0; index <= computer_count - 1; index++) {
544+
timer.throttle("computer_mine_" + index, computer_speed, function () {
545+
check_for_magic_number(randint(0, max_height))
546+
hash_count_per_sec += 1
547+
})
548+
}
549+
for (let index = 0; index <= asic_count - 1; index++) {
550+
timer.throttle("asic_mine_" + index, asic_speed, function () {
551+
check_for_magic_number(randint(0, max_height))
552+
hash_count_per_sec += 1
553+
})
554+
}
555+
raw_tick_count += 1
556+
})
552557
})

0 commit comments

Comments
 (0)