Minecraft functions time.sleep - minecraft

Is there a way to put a time.sleep in a minecraft function for Minecraft bedrock like in python?
For example:
/say this is a test!
time.sleep(5)
/say This is executed after the time.sleep

Please specify what a minecraft function is.
I assume you are using Minecraft: Java edition, to add delays in java you can use java.util.concurrent.TimeUnit
TimeUnit.SECONDS.sleep(1); Sleeps for one second.
TimeUnit.MINUTE.sleep(1); Sleeps for one minute.

You can make a sleep function but not how you tried to do it. I made a video for you to explain what I mean.
Give yourself a command block:
/give #s command_block
Place it and put your command into the window.
Place a command block next to it and put your second command in the window.
Change the presets to repeating always active and conditional.
Put the tick value in the last box. 20 ticks are equal to 1 second.

Use hopper clocks for timings, works as a charm

Related

How do I send output to an inactive window for better AFK? (AutoHotkey)

I'm trying to send the output of my code to an inactive application using Auto Hotkey on my computer so I don't have to be on the screen and can do other stuff. How would I go about implementing it?
F1::
stop := 0
Loop
{
Send, z
Sleep 500
}until Stop
return
F2::Stop := 1
This is the code I have down so far, any help?
ControlSending might work. It's basically a hit or miss. It'll work for some applications, and for some it wont.
It'll be worth a try for you though.
Also, you're going to want to use a timer as opposed to looping in a hotkey thread. Timer is intended just for something like this and what you were doing is kind of bad practice for various reasons.
;timer runs the user-defined function "SendZ" every 500ms
F1::SetTimer, SendZ, 500
F2::SetTimer, SendZ, Off
SendZ()
{
ControlSend, , z, % "ahk_exe notepad.exe"
}
As a bonus, we can even write a sweet one liner to toggle on/off that timer by using a ternary:
F1::SetTimer, SendZ, % (Toggle:=!Toggle) ? 500 : "Off"
If that doesn't make sense to you, and you're interested, you can read a lengthy previous explanation of mine about it here.

How to run CFRunLoop() for certain amount of time, then stop?

I currently have some code that requires running CFRunLoopRun().
This runs indefinitely. I would like to replace it with something that only runs for a set amount of time, say 30 seconds.
I tried CFRunLoopRunInMode(), but it exits immediately.
CFRunLoopRun(); // Works but never stops, I need to stop after 30s
CFStringRef mode = (__bridge CFStringRef)#"mode";
CFTimeInterval timeInterval = 10.0;
CFRunLoopRunInMode(mode, timeInterval, FALSE); // Doesn't work, syntax is wrong?, stops immediately
You are using a custom mode. It looks like you're just making it up for this one call. That would suggest that there are no input sources scheduled in that mode. All of the run-loop run functions exit immediately if there are no input sources.
CFRunLoopRunInMode() actually returns a value indicating why it exited. You should examine that.
The difference with CFRunLoopRun() is that it runs the run loop in the default mode (kCFRunLoopDefaultMode), not your custom mode. That mode almost certainly does have input sources scheduled (at least, assuming this is the main thread and thus the main run loop).
So, you could do this:
CFRunLoopRunInMode(kCFRunLoopDefaultMode, 10.0, FALSE);
All of that said, running the run loop for a fixed time period is rarely the right approach. What are you actually trying to achieve? What led you to conclude that you need to run the run loop for 10 seconds? Why not just return to the normal event loop and use a timer to do some work in 10 seconds?

Executing a regular task on Scilab

I'm currently working on the automation of a test bench (Subject of my work placement). It consists electronic loads (BK8610, BK8500), DC power supplies (BK9202, ETS60X14C) and multimeters (MetraEnergy).
I created a library of functions in Scilab to control all the devices at the same time (I can set paramaters and get measures using ethernet, serial ports and VISA interface). Now that every commands works fine, i'm trying to write a general script to do regular measures.
I thought of using tic() at the beginning of my script, then exec_time=toc() at the end an wait for 5s-exec_time before executing it again.
tic()
//My code
exec_time=toc()
//wait until the time is equal to 5s
//Repeat
Even if this could work, I wonder if Scilab has a function which would be equivalent to an asynchronous interruption timer (commonly used on ATmega, stm32 and so on) ? This would be much easier.
Hope this is clear. Thank you !
Maybe realtime & realtimeinit is a solution for you. Modified example from Scilab help:
clc;
clear;
realtimeinit(1/2);//sets time unit to half a second
realtime(0);//sets current date to 0
for k=1:10
realtime(k);
mprintf('\r\ncurrent time is %.1f sec',k/2);
end

Run loop in TCL shell background

I'm looking for a way to run a loop in TCL shell background (meaning - an infinite loop calling some function), but I can't find a way to do it.
The proc is a simple proc releasing all possible licenses from the user (we have a shortage of licenses here at work and we constantly fighting who's going to get them).
The loop itself is simple:
while {1} {
after 60000
clr_lic
}
But how can I make it run in the background so I'll be able to run other commands as well?
Are you running an event loop? If you are, you can do this with the every procedure:
proc every {ms script} {
after $ms [info level 0]
uplevel "#0" $script
# Double quotes just for syntax highlighting…
}
every 60000 clr_lic
Otherwise, things get awkward: you'd have to think about spinning up a thread or a subprocess and… well, it all gets a lot more awkward as then you're in a strongly segregated context and have to do a lot more work (well, usually).
When testing the code above, I used this:
every 500 {
puts "Hi there, world!"
}
vwait forever; # Conventional way to run the event loop in tclsh
And I got quite a lot of messages written out; it's flexible and easy.
Try appending an ampersand (&) when invoking your script. This will run it in background and you're be able to run any command you like.

Cancelling a setInterval delay while it is running in AS2

Is this possible?
I have a file in which a movie clip is launched when the user roles over another element. To make the user experience more pleasant this happens after a 3 second delay using setInterval. Is there a way of stopping and resetting this time if the user rolls off the element before the 3 seconds is up?
var xTimer = setInterval(wait, 3000);
function wait(){
show('all');
play('all');
clearInterval(xTimer);
}
Above is the code I have used to set the delay, and below is the code I had assumed would interrupt and reset the timer.
invisBtn.onRollOut = function(){
rollover_mc.gotoAndStop(1);
stop();
clearInterval(xTimer());
trace('off');
}
Any help on this would be massively appreciated.
First, the setInterval & clearInterval functions use a Number variable to work.
setInterval() returns a Number variable, and clearInterval() takes that Number in parameter to remove the previous started interval. Here you seem to keep the interval ID inside a function variable instead of a Number one.
Thus, clearInterval(xTimer()); should in reality be clearInterval(xTimer); (without the parenthesis after xTimer).
And secondly, so you can use it in the invisBtn.onRollOut function, just be sure that the xTimer variable is scoped correctly (not inside a function where the invisBtn.onRollOut isn't also), and not on different keyframes of the timeline (timeline keyframes in Flash tends to forget the code you've written on it as soon as the reading head passes onto a new keyframe of the layer which has the code on it).
Feel free to ask more details if you need !