2 posts
Posted 11 October 2012 - 12:35 AM
ok, im trying to write a function in a program and i keep getting a '<name>' expected error when the program tries to call the function. im not total programming noob but it has been years since i coaded anything.
Spoiler
function pulse (side, con, pulse, wait, cof, rep)
local i = 0
for i = 0, rep do
redstone.setBundledOutput (side, con)
sleep (pulse)
redstone.setBundledOutput (side, 0)
i = i + 1
end
if i == rep then
sleep (wait)
end
for i = rep, 0 do
redstone.setBundledOutput (side, cof)
sleep(pulse)
redstone.setBundledOutput (side, conf)
i= i - 1
end
end
while true do
if rs.getInput("top", true) then
pulse ("back", colors.orange, 0.500, 5, colors.white. 4)
end
end
209 posts
Location
In your fridge.
Posted 11 October 2012 - 02:13 AM
1. You didn't end pulse(). There is the "function" call, which needs ended, and a for loop, which is ended, as the program will read it. You need a second "end," provided that line break means what it usually means: a new section. If this is only the function, give the whole code.
2. Do not put a space between the function, and the parenthesis. Ever. Those () tell the program it's a function, and the fact that they are not connected tells it you are calling a variable. i.e. you are calling the variable "pulse" rather than the function "pulse()."
Fix those two errors (quite minor fix) and see if it works, if not, let us all know. Unless of course this is not the full code, in which case there may be numerous errors similar to this one. Always give the full code. Sometimes, the error is not where you expect it. Most of the time, the error is common, and we look for those first. Otherwise, it may be a one-time issue in how you called the function.
I hope that helps!
–Lettuce
P.S. Please use code tags. That can be done the same way you used spoiler tags, but instead write "code" or click the <> at the top of the editor (you'll see them). It makes this stuff easier to read.
2 posts
Posted 11 October 2012 - 03:43 AM
ok i double checked my the lines, and as far as i can tell (I am useing Notepad ++ for writing the actual program) it looks as if the function is closed, unless it needs more then just end. the space has also been removed. i will repost the code with the modifications. it is giveing me the error at line 27 when i call on the function.
function pulse (side, con, pls, wait, cof, rep)
local i = 0
for i = 0, rep do
redstone.setBundledOutput (side, con)
sleep (pls)
redstone.setBundledOutput (side, 0)
i = i + 1
end
if i == rep then
sleep (wait)
end
for i = rep, 0 do
redstone.setBundledOutput (side, cof)
sleep(pls)
redstone.setBundledOutput (side, 0)
i= i - 1
end
end pulse()
while true do
if rs.getInput("top", true) then
pulse("back", colors.orange, 0.500, 5, colors.white. 4)
end
end
1111 posts
Location
Portland OR
Posted 11 October 2012 - 03:49 AM
It is probably passing the colors as strings. You can check this in the pulse function by doing say:
local sType = type(varName)
print(sType)
I'm not sure you will be able to pass the colors this way. you might have to send the numbers instead.
Also your going to need another sleep in your pulse function right after it turns the color off. Otherwise it will immediately come back on and never pulse.