Discord
Login
Community
DARK THEME

keyboard glitch

Alrighty so whenever I use the keyboard.press command it does not work, in more context copy and paste this command into a new project

init = function() space1 = true space2 = false space3 = false space4 = false end

update = function() if space1 == true then if keyboard.press.A then space1 = false space2 = true space3 = false space4 = false end end if space2 == true then if keyboard.press.A then space1 = false space2 = false space3 = true space4 = false end end if space3 == true then if keyboard.press.A then space1 = false space2 = false space3 = false space4 = true end end if space4 == true then if keyboard.press.A then space1 = true space2 = false space3 = false space4 = false end end end draw = function() screen.fillRect(0,0,screen.width,screen.height,"#FFF") text() end

text = function() if space1 == true then screen.drawText("1",0,0,90,"rgb(0,0,0)") end if space2 == true then screen.drawText("2",0,0,90,"rgb(0,0,0)") end if space3 == true then screen.drawText("3",0,0,90,"rgb(0,0,0)") end if space4 == true then screen.drawText("4",0,0,90,"rgb(0,0,0)") end end

basically what it does is its just ignoring the ".press" part of the command, ive double checked other characters and it wont work

three ` characters at the beginning and end mean that everything in the middle is treated as program code and will not be squeezed by the parser when pasting here (the keyboard key responsible for this character is next to the number one key on my keyboard) .

you don't see the difference in the displayed string because you check the condition for the first variable which is true and set the variable for condition two to true. The program continues to run and now you check the condition for the second variable, which you just changed to true.

You need a "return" call or an "elsif" construct.

update = function()

if ... then
  ....
  return
end
if ... then
  ...
  return
end
end
if ... then 
   ....
elsif ... then
   ...
end 
init = function()
  space1 = true
  space2 = false 
  space3 = false 
  space4 = false 
end

update = function() 
  if space1 == true then 
    if keyboard.press.A then 
      space1 = false
      space2 = true
      space3 = false 
      space4 = false 
    end 
  elsif space2 == true then 
    if keyboard.press.A then 
      space1 = false 
      space2 = false 
      space3 = true 
      space4 = false 
    end 
  elsif space3 == true then 
    if keyboard.press.A then 
      space1 = false 
      space2 = false 
      space3 = false 
      space4 = true 
    end 
  elsif space4 == true then 
    if keyboard.press.A then 
      space1 = true 
      space2 = false 
      space3 = false 
      space4 = false 
    end
  end 
end 
draw = function() 
  screen.fillRect(0,0,screen.width,screen.height,"#FFF") 
  text() 
end

text = function() 
  if space1 == true then 
    screen.drawText("1",0,0,90,"rgb(0,0,0)") 
  end 
  if space2 == true then 
    screen.drawText("2",0,0,90,"rgb(0,0,0)") 
  end 
  if space3 == true then 
    screen.drawText("3",0,0,90,"rgb(0,0,0)") 
  end 
  if space4 == true then 
    screen.drawText("4",0,0,90,"rgb(0,0,0)") 
  end 
end

Post a reply

Progress

Status

Preview
Cancel
Post
Validate your e-mail address to participate in the community