This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
DarkenedEvil's profile picture

[gui Sorta]make An Image Blink Or Change States?

Started by DarkenedEvil, 18 November 2013 - 03:49 PM
DarkenedEvil #1
Posted 18 November 2013 - 04:49 PM
Well I am currently re-coding my OS and I have run into a slight issue. I am making an icon that is suppose to be a shell. Basically its a black rectangle with "> Shell" printed on the top right to make it look like a real shell. All of this is within a while loop to check for mouse_click. My question is how can I make that text that was printed ontop of the image change like so. So first state would be "> Shell" the other state would be " Shell" as to simulate blinking.

It wouldnt be much of a problem. Just put it in a while loop with the states as a variable and whether the state is 1 or 0 then the text would be in that state. The problem is that when put into a while loop thats checking for mouse_click it simply doesn't work.

Yes it is indented in my editor, for some reason the website didn't like it:(
Spoiler
local blink = 1
while true do
local event, button, x, y = os.pullEvent()
if blink == 1 then
drawShellIconBlinkOne()
local blink = 2
elseif blink == 2 then
drawShellIconBlinkTwo()
local blink = 1
else
error("Unknown blink. Please report this to DarkenedEvil")
end
if event == "mouse_click" then
if x >= 3 and x <= 8 and y == 1 and button == 1 then --DropDown
drawDropDown()
while true do
local event, button, x, y = os.pullEvent()
if event == "mouse_click" then
if x >= 1 and x <= 8 and y == 3 and button == 1 then --Update
--os.run({}, "update")
elseif x >= 1 and x <= 8 and y == 4 and button == 1 then --Settings

elseif x >= 1 and x <= 8 and y == 5 and button == 1 then --about
drawBackGround()
drawAbout()
while true do
local event, button, x, y = os.pullEvent()
if event == "mouse_click" then
if x == 40 and y == 5 and button == 1 then --close box
drawBackGround()
break
end
end
end
break
elseif x >= 1 and x <= 8 and y == 6 and button == 1 then --credits
drawBackGround()
drawCredits()
while true do
local event, button, x, y = os.pullEvent()
if event == "mouse_click" then
if x == 46 and y == 5 and button == 1 then --close box
drawBackGround()
break
end
end
end
break
elseif x >= 1 and x <= 8 and y == 7 and button == 1 then --Logout
os.reboot()
elseif x >= 1 and x <= 8 and y == 8 and button == 1 then --shutdown
os.shutdown()
  elseif x >= 1 and x <= 7 and y == 1 and button == 1 then
drawBackGround()
break
end
end
end
else
drawBackGround()
end
if x >= 37 and x <= 45 and y >= 5 and y <= 15 and button == 1 then --Usercontrol
os.run({}, "usercontrol", tArgs[1])
elseif x >= 1 and x <= 8 and y <=8 and y >= 7 and button == 1  then --FileBrowser
os.run({}, "filebrowser")
elseif x >= 1 and x <= 8 and y <= 10 and y >= 10 and button == 1 then --Shell
os.run({["shell"] = shell}, "luaide", "luaide", username)
elseif x >=1 and x <= 8 and y <=5 and y >=4 and button == 1 then --AppCenter
if Alert == true then
drawBackGround()
Alert = false
else
drawAlert("Comming Soon!")
Alert = true
end
else
--drawBackGround()
end
end
end
Edited on 18 November 2013 - 03:50 PM
Bomb Bloke #2
Posted 18 November 2013 - 05:47 PM
Try turning off the rich text editor thingy before pasting. Check the light switch at the top left of the posting box.

You keep declaring "blink" as local over and over again. Don't do that.

This won't blink unless you do something to trigger an event. You could fire off events automatically using os.startTimer().

Even then, the current structure of your code is such that the moment you click on a button, it'll no longer try to blink - even if you click on something that isn't a button, I suspect your background will cover the blinker over. Consider under what circumstances that code at the top will or will not be executed.
DarkenedEvil #3
Posted 18 November 2013 - 08:23 PM
Try turning off the rich text editor thingy before pasting. Check the light switch at the top left of the posting box.

You keep declaring "blink" as local over and over again. Don't do that.

This won't blink unless you do something to trigger an event. You could fire off events automatically using os.startTimer().

Even then, the current structure of your code is such that the moment you click on a button, it'll no longer try to blink - even if you click on something that isn't a button, I suspect your background will cover the blinker over. Consider under what circumstances that code at the top will or will not be executed.

Thank you for the help! I used os.startTimer() to fire it off. Although its a little buggy right now I think that I can make it better. Thanks again.