15 posts
Posted 27 February 2014 - 10:49 AM
Im building a vital part to my SDD, which i have the first part in a post. This part is to run the main clock and im getting the error bios:338: [string "clock.lua"]:18: 'then' expected!
This is the code…
y = 1
x = 0
– 0 state - off state
– 1 state - 10Hz
– 2 state - 50Hz
– 3 state - 200Hz
– 4 state - 500Hz
– 5 state - 1KHz
while y == 1 do
if redstone.input("left", true) and x >= 1 then
x = x - 1
end
if redstone.input("left", true) and x == 0 then
x = 5
end
if redstone.input("left", false)
if x == 1 then
redstone.output("right", true)
sleep(0.05)
redstone.output("right", false)
end
if x == 2 then
redstone.output("right", true)
sleep(0.01)
redstone.output("right", false)
end
if x == 3 then
redstone.output("right", true)
sleep(0.0025)
redstone.output("right", false)
end
if x == 4 then
redstone.output("right", true)
sleep(0.001)
redstone.output("right", false)
end
if x == 5 then
redstone.output("right", true)
sleep(0.0005)
redstone.output("right", false)
end
if x == 0 then
redstone.output("right", false)
end
end
end
This is the code!
1281 posts
Posted 27 February 2014 - 11:05 AM
This belongs in Ask a pro.
Anyways, you're obviously missing a "then" here…
if redstone.input("left", false)
Also, does this even work at all?
The correct functions are redstone.setOutput and redstone.getInput.
Edited on 27 February 2014 - 03:14 PM
8543 posts
Posted 27 February 2014 - 03:54 PM
It won't work anyway, since only the first option has the redstone output on for an entire game tick. That one at least might work, but it would probably be better to keep it on for a redstone tick (0.1s). The other durations are too short to trigger any redstone changes without a serious stroke of luck, and any changes they did trigger would happen at well below the desired frequency. You may wish to look further in to how Minecraft handles redstone updates.
Moved to Ask a Pro.
15 posts
Posted 06 March 2014 - 11:08 PM
7083 posts
Location
Tasmania (AU)
Posted 06 March 2014 - 11:40 PM
Any chance of dumping the exact file with the error on
PasteBin?
12 posts
Location
The Internet Hub, Oslo, Norway
Posted 12 March 2014 - 10:41 PM
Try this:
while true do
shell.run("time")
sleep(1)
end
2151 posts
Location
Auckland, New Zealand
Posted 13 March 2014 - 09:22 AM
Try this:
while true do
shell.run("time")
sleep(1)
end
That writes the time, he is wanting essentially a flashing redstone pulse (also called a clock). I can understand your confusion, however.
1852 posts
Location
Sweden
Posted 13 March 2014 - 03:47 PM
First of all, Use code tags > [-CODE] print("This is some code! :-D") [-/CODE] ( Without the '-' )
Second of all, Use elseif/else & when you're not changing the
y I'm wondering why you're not using while true do instead
I think this works xP
local x = 0 -- Made this local
-- 0 state - off state
-- 1 state - 10Hz
-- 2 state - 50Hz
-- 3 state - 200Hz
-- 4 state - 500Hz
-- 5 state - 1KHz
while true do -- Changed the loop and removed the unecessary 'y' variable
if redstone.input("left", true) then
if x >= 1 then
x = x - 1
elseif x == 0 then
x = 5
end
elseif redstone.input("left", false) then
if x == 1 then
redstone.output("right", true)
sleep(0.05)
redstone.output("right", false)
elseif x == 2 then
redstone.output("right", true)
sleep(0.01)
redstone.output("right", false)
elseif x == 3 then
redstone.output("right", true)
sleep(0.0025)
redstone.output("right", false)
elseif x == 4 then
redstone.output("right", true)
sleep(0.001)
redstone.output("right", false)
elseif x == 5 then
redstone.output("right", true)
sleep(0.0005)
redstone.output("right", false)
elseif x == 0 then
redstone.output("right", false)
end
end
end
Change the sleep rate yourself :P/>
Edited on 13 March 2014 - 02:57 PM
15 posts
Posted 21 March 2014 - 01:19 AM
BTW same error, but did clean up some stuff, and the error seems to be a timeout that appears at at different times through the loop.
1852 posts
Location
Sweden
Posted 21 March 2014 - 06:42 PM
Hmm.. I think it is
redstone.setOutput( "right", true )
or you can shorten it to this
rs.setOutput( "right", true )
That should be instead of this
redstone.output( "right", true )
How could I not have realized that earlier? x)
Edited on 21 March 2014 - 05:44 PM
15 posts
Posted 24 March 2014 - 10:20 PM
And i have plenty of times gone over something and not realized the simplest mistake.
And you are incorrect, it is setOutput and getInput.
7083 posts
Location
Tasmania (AU)
Posted 24 March 2014 - 11:28 PM
Although Hellkid's grammar is iffy, that's what he and CometWolf told you.
15 posts
Posted 12 May 2014 - 03:50 AM
Anymore suggestions cause it seems to time out, I need it to ignore the fact there is no signal and keep looping without response.
76 posts
Posted 12 May 2014 - 04:19 AM
I may be wrong, but if you have a loop without a guaranteed result then it will get a too long without yield error, try putting this at the end of the while loop and see if it helps
else
sleep(0.05) -- this will create a 1 tick sleep allowing the next tick to be loaded essentially under a new loop
end
also the fastest clock you can have in MC as Lyqyd stated is 10Hz (2 ticks per pulse (1tick on, 1tick off)) otherwise the redstone state wont change between pulses and you will phase the pulse essentially causing your pulse to slow. (If you set your pulse to, say, 30Hz you will only get roughly 3Hz as half the time that the tick refreshes it will be getting the same result as its previous setOutput.
Think of a TV and our eyes, the only reason we see moving picture and not a series of still images, is because the tv phases faster than our eyes do, now if you use a digital camera/video camera, you will get lines running through the image, this is because the camera phase is roughly equivalent if not faster than the TV phase. The same thing will happen to your clock system, you will (if I can use my example) get lines through your image as the phasing isnt right or you will get a moving image and not a series of still images(pulses) as you want.
As an extension from this the next slowest after 10Hz I believe is (and ill probably be very wrong here) 5Hz or 1phase every 0.2 seconds (2ticks on, 2ticks off) although if you don't mind having an uneven phase you could go to 7.5Hz or 1phase every 0.15 seconds (1tick on, 2 ticks off or, 2ticks on 1tick off)
Edited on 12 May 2014 - 02:22 AM