Jump to content




All key presses seem to do the same thing in this code now


  • You cannot reply to this topic
3 replies to this topic

#1 CCJJSax

  • Members
  • 262 posts

Posted 29 March 2013 - 01:45 PM

This is a function to make the turtle select a slot using the arrows / wasd keys. At one point I had every button as a separate elseif, earlier today I made all the buttons that did the same thing into the same elseif. Now, with this code, every button (even the ones that aren't defined) make the slot move up one....

the elseif to or change I did was with the last one, and I got that to work. but after I moved the rest to that system, everything did the same thing. it's probably pretty obvious what is the problem, but, let's just say I need some sleep lol.

(i don't know how to do spoiler so the following spoiler attempt is a guess :) )

Spoiler

Thanks! :D

#2 Kingdaro

    The Doctor

  • Members
  • 1,636 posts
  • Location'MURICA

Posted 29 March 2013 - 02:00 PM

Hopefully this works:

local slot = 1
turtle.select(1)

while true do
  local _, k = os.pullEvent('key')
  if k == keys.left and slot > 1 then
    slot = slot - 1
  elseif k == keys.right and slot < 16 then
    slot = slot + 1
  elseif k == keys.up and slot > 4 then
    slot = slot - 4
  elseif k == keys.down and slot < 13 then
    slot = slot + 4
  end
  turtle.select(slot)
end


#3 CCJJSax

  • Members
  • 262 posts

Posted 29 March 2013 - 02:55 PM

View PostKingdaro, on 29 March 2013 - 02:00 PM, said:

Hopefully this works:

local slot = 1
turtle.select(1)

while true do
  local _, k = os.pullEvent('key')
  if k == keys.left and slot > 1 then
	slot = slot - 1
  elseif k == keys.right and slot < 16 then
	slot = slot + 1
  elseif k == keys.up and slot > 4 then
	slot = slot - 4
  elseif k == keys.down and slot < 13 then
	slot = slot + 4
  end
  turtle.select(slot)
end

that didn't work with wasd, but without having worked with it other than that code, I'd say that's an easy fix, plus it's much smaller than my code :D

#4 immibis

    Lua God

  • Members
  • 1,033 posts
  • LocationWellington, New Zealand

Posted 29 March 2013 - 07:08 PM

if pl == 200 or 17 then
is the same as:
if ((pl == 200) or (17)) then

This runs the code inside the if if pl == 200 is true, or 17 is true. 17 is not false or nil, so it's always true.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users