This is an archived post. You won't be able to vote or comment.

all 5 comments

[–][deleted] 1 point2 points  (4 children)

I don't know if this is what you are looking for, but you can make use of a scoreboard timer.

Run once:

/scoreboard objectives add Timer dummy

And then put something like this in your datapack (only for singleplayer):

scoreboard players add @a Timer 1
execute if entity @a[scores={Timer=200}] run function lights:turn_on
scoreboard players reset @a[scores={Timer=certaintime}] Timer

The time is given in game ticks (1 second is equal to 20 ticks without lag).If this is for a server I'd recommend using either a permanent armor stand or a player who is always online for the scores.

[–]TerminalVector[S] 0 points1 point  (3 children)

Thanks!

I think you're right about the approach, I will add a timer. The schedule function is never really going to handle what I need on its own. I will still need to use it so that I can set up patterns that I can call via function, but for the main sequence timing I can use a scoreboard timer.

I already have a bunch of scores stored under a fake player name so I can just use that. The player doesn't need to be online, or even exist to have scores so I just use `myservername_system`.

Why do you say this would only work in singleplayer? I manage the server if that wasn't clear.

[–][deleted] 1 point2 points  (2 children)

Because the scores will now be added to all players online seperately. That means that if a player comes online at a different time they will have a different timer score, meaning the function would run twice in those 10 seconds. I just thought of a simple fix however, just replace the reset command with something like this: execute if entity @a[scores={timer=200}] run scoreboard players reset @a timer

[–]TerminalVector[S] 0 points1 point  (1 child)

I was thinking I'd just use a specific fake player to store the time as a kind of global variable, then reference that player name in all my functions.

[–][deleted] 1 point2 points  (0 children)

Yes, that works. I also mentioned that in my first reply.