Jump to content


crazyguymgd's Content

There have been 139 items by crazyguymgd (Search limited from 30-March 23)


By content type

See this member's


Sort by                Order  

#71968 [Turtle][Programming] Trouble with a variable

Posted by crazyguymgd on 10 January 2013 - 12:05 PM in Ask a Pro

vx, vy, and vz are only accessible inside the scope they are initialize. An if, end block is it's own scope so you will only be able to access the variable inside that if,end block.



#125322 [miscPeripherals]help with the smart helmet

Posted by crazyguymgd on 10 June 2013 - 08:04 PM in Peripheral Help and Discussion

Place a Smallnet Sender next to a computer then right click on the sender. This will create a link between you and it. On the computer type:

m = peripheral.wrap("side")
m.send("smartHelmet","message")



#71974 [lua]If statement troubles?

Posted by crazyguymgd on 10 January 2013 - 12:15 PM in Ask a Pro

what is f initialized to? And where is it initialized?



#71930 [Lua][Question] Storing Functions in a Table

Posted by crazyguymgd on 10 January 2013 - 11:23 AM in Ask a Pro

View PostChunLing, on 10 January 2013 - 11:01 AM, said:

And the actual storing of the functions in a table means that you can call them using variables, which is a bit more difficult if you don't have them in a table.

Like:
funcName = read()
if turtle[funcName] then turtle[funcName]() end
There, now I can use user input to decide which turtle function to call, cause they are all in a table (and indexed by strings).

Well that is incredibly useful for a project I'm working on :)



#72455 [lua][help]Making a timer (more detail in the description)

Posted by crazyguymgd on 11 January 2013 - 10:59 AM in Ask a Pro

Can you post what you have. You're probably on the right track and then we can help you from there :)



#73991 [LUA][ERROR]Getting false " 'then' expected " error?

Posted by crazyguymgd on 13 January 2013 - 10:27 PM in Ask a Pro

m == 1 and k == 28 instead of one =



#74287 [Lua][Error] startup:27: attempt to call nil

Posted by crazyguymgd on 14 January 2013 - 11:27 AM in Ask a Pro

how old of a version of cc are you using in that tekkit pack?



#74682 [Lua][Error] startup:27: attempt to call nil

Posted by crazyguymgd on 15 January 2013 - 07:43 AM in Ask a Pro

So you retyped the whole program to put it on here? Interesting... well glad it's fixed.



#73947 [Lua][Error] startup:27: attempt to call nil

Posted by crazyguymgd on 13 January 2013 - 09:14 PM in Ask a Pro

Well I ran your program without any errors so I'm not too sure why you would be having a problem.
And I just spent a little while trying to force the error with no luck so something else you are doing must be wrong.
Sorry I couldn't find the problem, just letting you know I tried.



#73999 [Lua][Error] I need help finding out the error im getting for this a* demo

Posted by crazyguymgd on 13 January 2013 - 10:49 PM in Ask a Pro

as far as i can tell, reverse everything that calls it.



#74009 [Lua][Error] I need help finding out the error im getting for this a* demo

Posted by crazyguymgd on 13 January 2013 - 11:07 PM in Ask a Pro

wait i think I was confused to your last question there. What I was saying originally was to change it to:

[code]
81: for x = 1,h do -- for each cell do
82: cell[x] = {}
83: stringl = filel.readLine()
84: for y = 1,w do
85: cell[x][y] = {}
86: --calculate heuristic
87: dx = math.abs(ex - x)
88: dy = math.abs(ey - y)
89: h = dx + dy
90: cell[x][y].h = h-1
91: ce = stringl:sub(y,y)
92: cell[x][y].type = gettype(ce)
93: end
94: end
[/code]
edit - can't figure out formating with this copied and pasted. sorry all you formatting gods :P



#73960 [Lua][Error] I need help finding out the error im getting for this a* demo

Posted by crazyguymgd on 13 January 2013 - 09:32 PM in Ask a Pro

you should be able to just switch the for loops. for x = 1, w .... for y = 1, h...



#74020 [Lua][Error] I need help finding out the error im getting for this a* demo

Posted by crazyguymgd on 13 January 2013 - 11:36 PM in Ask a Pro

oh, your original loops had y associated with the width and x with the height... i thought that was strange but just kept that for you.
basically if it doesn't do what you want it to do, you'll probably have to re-write it to properly fit the structure you want...



#73937 [Lua][Error] I need help finding out the error im getting for this a* demo

Posted by crazyguymgd on 13 January 2013 - 08:53 PM in Ask a Pro

View Postcolumna1, on 13 January 2013 - 08:21 PM, said:

Im pretty sure that the way im defining it in the for loop:

81:	for y = 1,w do -- for each cell do
82:	   cell[y] = {}
83:	   stringl = filel.readLine()
84:	   for x = 1,h do
85:		 cell[x][y] = {}
86:		 --calculate heuristic
87:		 dx = math.abs(ex - x)
88:		 dy = math.abs(ey - y)
89:		 h = dx + dy
90:		 cell[x][y].h = h-1
91:		 ce = stringl:sub(y,y)
92:		 cell[x][y].type = gettype(ce)
93:	   end
94:	 end

would define cell[x] first then it would define
cell[x][y] as a table
so that i could use it almost as an object with a 2d identifier

Also if you want i could post the code without the lines numbered
and i have defined cell to as a table

cell[y] = {}, when y is 1, puts an empty table at cell[1].
then you go into the x loop.
when x = 1, cell[1][1] = {} works fine because you created that empty table at cell[1].
But the next time through the for loop, you try to access cell[2][1] which doesn't exist...



#73269 [Lua][Error] Bios:338 error?

Posted by crazyguymgd on 12 January 2013 - 06:11 PM in Ask a Pro

cool :)



#73252 [Lua][Error] Bios:338 error?

Posted by crazyguymgd on 12 January 2013 - 05:50 PM in Ask a Pro

Yup that's exactly what you have to do. But you can also create a new function that does take parameters and loops x number of times, and then just call that function.



#71913 [Lua][Error]

Posted by crazyguymgd on 10 January 2013 - 11:09 AM in Ask a Pro

Why is he only turning right if c is false?



#71926 [lua] turtle compare statements not working as expected

Posted by crazyguymgd on 10 January 2013 - 11:20 AM in Ask a Pro

it's turtle.detect() not turtle.detect
hopefully that's your only problem



#73246 [lua] strip mining automation complication

Posted by crazyguymgd on 12 January 2013 - 05:40 PM in Ask a Pro

First, you don't need to increment d when you dig up because you don't actually move. Then your repeat until would then go up to 101 not 202. If you did increment d, when you turn around to go back, you'll be going twice as far which isn't ideal.

Second tip, instead of
if false then
  ...
end
if true then
  ...
end
you can simplify to
if true then
  ...
else
  ...
end

Then you can just add TheOiginalBITs suggestion and you'll have made some progress in the right direction.



#74587 [lua] script problem

Posted by crazyguymgd on 15 January 2013 - 05:06 AM in Ask a Pro

Use == in your ifs. A single = is for assignments, double == is for comparisons.



#72399 [lua] Need help writing a program

Posted by crazyguymgd on 11 January 2013 - 09:17 AM in Ask a Pro

I just ran it and it works fine. That error would mean nothing is in loctable at index pos. Did you add the code I gave you to an existing program or run it on it's own. Again, it works for me with no error.



#72326 [lua] Need help writing a program

Posted by crazyguymgd on 11 January 2013 - 05:43 AM in Ask a Pro

Do you get any errors? After a quick glance on my phone I noticed you use curpos in the last while loop but declare it as a local variable up in the function above. This may be the problem?



#71849 [lua] Need help writing a program

Posted by crazyguymgd on 10 January 2013 - 09:37 AM in Ask a Pro

View Postrobertcarr22, on 10 January 2013 - 09:33 AM, said:

Still cant figure it out :/ can someone please help?

is the code above still the most recent copy? I'd be happy to take a look but what you have above doesn't work and I don't want to debug it all if you've already done some of that.



#72393 [lua] Need help writing a program

Posted by crazyguymgd on 11 January 2013 - 09:03 AM in Ask a Pro

Here's what I came up with for you. It uses your general method just cleaned up a bit. Took out some unnecessary variables, made loctable hold all the data so we're not trying to access multiple tables. And some other little things. Here you go!


local loctable = {}
local currline = 0
local pos = 1
local wire = 0

function readFile()
  term.clear()
  term.setCursorPos(1,1)

  local countlines = 1
  file = io.open("power","r")

  for line in file:lines() do
    for name, active in string.gmatch(line, "(.+):(/>%w+)") do
      loctable[countlines] = {["name"] = name, ["active"] = active}
    end
    countlines = countlines + 1
  end
  file:close()
end

readFile()
function printMenu()
  term.setCursorPos(1,1)
  term.clear()
  for i = 1, #loctable do
    wire = redstone.getBundledOutput("bottom")
    if loctable[i].active == "Open" then
      term.setTextColor(colors.lime)
      wire = colors.combine(wire, 2^#loctable)
    else
      term.setTextColor(colors.red)
      wire=colors.subtract(wire, 2^#loctable)
    end
    redstone.setBundledOutput("bottom", wire)

    if i == pos then
      print(loctable[i].name.."="..loctable[i].active.."*")
    else
      print(loctable[i].name.."="..loctable[i].active)
    end  
  end
  term.setTextColor(colors.white)
end      


while true do
  printMenu()
  local event, a = os.pullEvent("key")
  if a == 200 and pos > 1 then
    pos = pos - 1
  end
  if a == 208 and pos < 3 then
    pos = pos + 1
  end
  if a == 28 then

    if loctable[pos].active == "Open" then
       loctable[pos].active = "Closed"
     else
       loctable[pos].active = "Open"
     end  


  end  
end



#72382 [lua] Need help writing a program

Posted by crazyguymgd on 11 January 2013 - 08:45 AM in Ask a Pro

Problem I found:
Every time you call printMenu(), you read from the file again, overwriting any data you may have changed if the enter key works, and reprint the old data. So you may be doing that part correctly but you're overwriting it every time through the loop.