This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
hawkins627's profile picture

command.exec and testfor question

Started by hawkins627, 30 March 2017 - 01:17 PM
hawkins627 #1
Posted 30 March 2017 - 03:17 PM
So I have a command computer that starts a countdown timer when a student hits a button and sends out a redstone signal when the timer goes down to 0. It also sends messages to students with the tell command.

I think I want to step it up a notch, though, and I need some lua help for this. Students activate the countdown on the command computer with the press of a button and a redstone signal to the computer. My goal here is to stop the countdown if there are no students within a certain radius of the computer AND allow the program to reset itself automatically so the students can attempt to press the button again at a later time.

Please keep in mind that because of Microsoft I am stuck in MinecraftEDU version 1.7.10 stable build 20 and I am using computercraftedu and Craft OS 1.7

Also my coding skills are very basic…
TheRockettek #2
Posted 30 March 2017 - 06:56 PM
try using "testfor @a[r=radius]"

Eg:

testfor @a[r=5]
hawkins627 #3
Posted 31 March 2017 - 03:49 PM
try using "testfor @a[r=radius]"

Eg:

testfor @a[r=5]


I got it by adding this code to my countdown loop…

if command.exec( "testfor @a[r=13]" ) == false then
i = 60
end

And so the timer doesn't start going down again until players are close to the command computer.

This may seem like nothing, but it is a small victory for this school librarian who is trying to learn basic lua to make better Minecraft experiences for my students.

-Hawkins
FuzzyLitchi #4
Posted 31 March 2017 - 07:32 PM
If you would like more features or help, posting the source code would help us understand what you mean. :)/>

You can do this using "pastebin put <programName>" and then go to http://pastebin.com/<the weird Numbers and letters it writes>. You will then see your source code and can send us a link. :D/>