Discord
Login
Community
DARK THEME

toggle sysytem


init = function()
  plots = 4
  play = 1
  UIx = -200
  UIon = false
end

update = function()
  if keyboard.SPACE and UIon == false then
    UIon = true
  end
  
  if keyboard.SPACE and UIon == true then
    UIon = false
  end
  if UIon == true and UIx < -125 then
    UIx += 1
  end
  if UIon == false and UIx > -200 then
    UIx -= 1
  end
end

why is my toggle system not working?

2 reasons:

one, they are one after another. it's checking if keyboard is pressed and there is UIon == false and turning it on, and then immediately checking if its true then turning it off. you need to use

if (check) then 
//stuff
elsif (check) then
//else stuff
end 

so that it only does one.

two, you are using keyboard.SPACE, which checks every single frame, and unless you can click for exactly odd amounts of frames, it'll change every frame. you need to use keyboard.press.SPACE to check only one

ohhh

Post a reply

Progress

Status

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