|
#1
|
|||
|
|||
|
I have finished creating my app, there are a lot of bugs, it does work on the Zen somewhat, I'm still trying to figure out how to kill all of the bugs in it at the moment. Feel free to work with it and try it out.
I just tried the newest version on the Zen, it allows you to create a password, then after that it won't start back up. Last edited by arleslie; 05-02-2010 at 09:26 PM. Reason: Update |
| Advertisement | [Remove Advertisement] |
|
|
|
|
#2
|
||||
|
||||
|
Hi arleslie, welcome on board
![]() Nice idea for an app, and I think you did well but there were some things I noticed that might cause it to malfunction on the player (the simulator is somewhat more flexible about some things). First, the loop is not correct. You forgot to ask if the control is touch or button. After that you can ask what type of control it was (click, hold, ), or in case of a control.isButton, which button it was, and then if it was an up, click or hold. I think that's because it crashes, because if the password.txt exists, you are opening it twice: Code:
if io.open("password.txt","r") then
print("read")
file = io.open("password.txt","r")
), sets the audio volume to max and back to where it was on exit, and works on the player:Code:
--this is my first Lua application
screen.orientation(1)
height = screen.height()
width = screen.width()
black = color.new(0,0,0)
red = color.new(255,0,0)
gray = color.new(100,100,100)
text.color(color.new(255,0,0))
text.size(20)
audioold=audio.volume()
audio.volume(25)
screen.fillrect(0,0,width,height,gray)
--screen.backlight(50,10)
screen.update()
print("load image")
img_lock = image.load("ICON.png")
print("load sound")
snd_stolen = wav.load("Stolen.wav")
ask = "yes"
print(ask)
print("check")
file = io.open("password.txt","r")
if file~=nil then
print("read")
password2 = file:read("*a")
file:close()
print(password2)
if string.len(password2) == 4 then
ask = "no"
else
text.draw(50,50,"No Password set")
print(ask)
end
else
text.draw(50,50,"No Password set")
end
password = ""
function create_pad()
--screen.fillrect(0,0,60,20,gray) --erase place of password
screen.drawrect(35,175,71,213,black)
text.draw(40,175,"1","center",71)
screen.drawrect(102,175,138,213,black)
text.draw(107,175,"2","center",138)
screen.drawrect(169,175,205,213,black)
text.draw(174,175,"3","center",205)
screen.drawrect(35,223,71,261,black)
text.draw(40,223,"4","center",71)
screen.drawrect(102,223,138,261,black)
text.draw(107,223,"5","center",138)
screen.drawrect(169,223,205,261,black)
text.draw(174,223,"6","center",205)
screen.drawrect(35,271,71,309,black)
text.draw(40,271,"7","center",71)
screen.drawrect(102,271,138,309,black)
text.draw(107,271,"8","center",138)
screen.drawrect(169,271,205,309,black)
text.draw(174,271,"9","center",205)
screen.drawrect(102,319,138,357,black)
text.draw(107,319,"0","center",138)
screen.update()
end
function flashimage()
for i=2, 7 do
if math.floor(i/2)==i/2 then
img_lock:draw(96,50)
screen.update()
screen.fillrect(96,50,48,48,gray)
else
screen.update()
end
os.wait(750)
end
end
function getnum(x, y)
if x >= 35 and x <= 71 and y >= 175 and y <= 213 then
num = "1"
elseif x >= 102 and x <= 138 and y >= 175 and y <= 213 then
num = "2"
elseif x >= 169 and x <= 205 and y >= 175 and y <= 213 then
num = "3"
elseif x >= 35 and x <= 71 and y >= 223 and y <= 261 then
num = "4"
elseif x >= 102 and x <= 138 and y >= 223 and y <= 261 then
num = "5"
elseif x >= 169 and x <= 205 and y >= 223 and y <= 261 then
num = "6"
elseif x >= 35 and x <= 71 and y >= 271 and y <= 309 then
num = "7"
elseif x >= 102 and x <= 138 and y >= 271 and y <= 309 then
num = "8"
elseif x >= 169 and x <= 205 and y >= 271 and y <= 309 then
num = "9"
elseif x >= 102 and x <= 138 and y >= 319 and y <= 357 then
num = "0"
else
num = ""
end
end
function setpassword(password)
file = io.open("password.txt","w")
file:write(password)
file:close()
password2=password
screen.fillrect(0,0,60,20,gray) --erase place of password
screen.fillrect(50,50,160,20,gray)
screen.update()
end
create_pad()
while 1 do
if control.read()==1 then
if control.isTouch()==1 then
x,y = touch.pos()
if touch.click() == 1 then
getnum(x,y)
password = password..num
screen.fillrect(0,0,60,20,gray) --erase place of password
text.draw(0,0,password)
screen.update()
if string.len(password) == 4 then
if ask == "yes" then
setpassword(password)
print("password created")
password = ""
ask= "no"
else
if password == password2 then
break
else
wav.play(snd_stolen)
password = ""
flashimage()
--create_pad()
end
end
end
end
elseif control.isButton()==1 then
if button.home()==1 then
if button.event()==1 then
wav.play(snd_stolen)
elseif button.hold()==1 then
wav.play(snd_stolen)
end
elseif button.power() == 1 then
wav.play(snd_stolen)
end
end
else
os.wait(50)
end
end
audio.volume(audioold)
screen.fillrect(0,0,width,height,gray)
screen.update()
img_lock:close()
snd_stolen:close()
screen.orientation(0)
When the player goes into idle shutdown, the app is closed and you can just turn the player back on, without having to enter a password.... so if you really intend to use this as a security app, you should turn off idle shutdown in the player's settings. (there is no way that I know of to disable idle shutdown in the code.) Last edited by Brett_val; 05-03-2010 at 07:34 AM. |
![]() |
«
Previous Thread
|
Next Thread
»
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
All times are GMT -5. The time now is 11:52 PM.













), sets the audio volume to max and back to where it was on exit, and works on the player:
Linear Mode
