Lua Programming Help Thread
This is a discussion on Lua Programming Help Thread within the PSP Development Forum forums, part of the PSP Development, Hacks, and Homebrew category; well...in the beginning you already made "RN9" equal to "complete". plus, it seems all this is pointless...: Code: if RN0 ...
-
09-22-2006, 01:58 PM #3511QJ Gamer Green
- Registriert seit
- Dec 2005
- Ort
- Here
- Beiträge
- 2.715
- Points
- 13.310
- Level
- 75
- Downloads
- 0
- Uploads
- 0
well...in the beginning you already made "RN9" equal to "complete".
plus, it seems all this is pointless...:
Code:if RN0 == 1 and RN9 == complete then RN9 = one end if RN1 == 1 and RN9 == one then RN9 = two end if RN2 == 1 and RN9 == two then RN9 = three end
[CENTER][IMG]http://img148.imageshack.us/img148/6985/siglw8.jpg[/IMG][/CENTER]
-
09-22-2006, 02:15 PM #3512QJ Gamer Silver

- Registriert seit
- Jun 2006
- Ort
- UK
- Beiträge
- 2.326
- Points
- 10.263
- Level
- 67
- Downloads
- 0
- Uploads
- 0
complete, one, two and three are all nil variables rather then string literals (which is what I assume you are trying to use).
-
09-23-2006, 03:09 AM #3513QJ Gamer Green
- Registriert seit
- Jul 2006
- Ort
- Middle Europe
- Beiträge
- 1.281
- Points
- 11.800
- Level
- 71
- Downloads
- 0
- Uploads
- 0
i have 2 questions:
1st. how do i save text which i typed in MagicianFBs keyboard???
2nd:Code:keyyellow = Color.new(255, 255, 0) keywhite = Color.new(255, 255, 255) keyblue = Color.new(0, 0, 255) keyblack = Color.new(0, 0, 0) keygreen = Color.new(0, 127, 0) keyorange = Color.new(255, 100, 0) keygray = Color.new(127, 127, 127) text = "" function drawRect(where, x, y, width, height, color) where:drawLine(x, y, x+width, y, color) where:drawLine(x+width, y, x+width, y+height, color) where:drawLine(x+width, y+height, x, y+height, color) where:drawLine(x, y+height, x, y, color) end keyscreen = Image.createEmpty(480, 272) keyscreen:clear(keyyellow) textdisp = Image.createEmpty(300, 172) textdisp:clear(keywhite) keyscreen:blit(150, 50, textdisp) key0123 = Image.createEmpty(26, 26) key4567 = Image.createEmpty(26, 26) key89 = Image.createEmpty(26, 26) keyabcd = Image.createEmpty(26, 26) keyefgh = Image.createEmpty(26, 26) keyijkl = Image.createEmpty(26, 26) keymnop = Image.createEmpty(26, 26) keyqrst = Image.createEmpty(26, 26) keyuvwx = Image.createEmpty(26, 26) keyyz = Image.createEmpty(26, 26) keysymb = Image.createEmpty(26, 26) keysymb2 = Image.createEmpty(26, 26) keybrd = Image.createEmpty(80, 106) keybrd:clear(keywhite) keybrd:blit(1, 1, key0123) keybrd:blit(27, 1, key4567) keybrd:blit(53, 1, key89) keybrd:blit(1, 27, keyabcd) keybrd:blit(27, 27, keyefgh) keybrd:blit(53, 27, keyijkl) keybrd:blit(1, 53, keymnop) keybrd:blit(27, 53, keyqrst) keybrd:blit(53, 53, keyuvwx) keybrd:blit(1, 79, keyyz) keybrd:blit(27, 79, keysymb) keybrd:blit(53, 79, keysymb2) keybrdsel = Image.createEmpty(78, 104) --Line 50 keyposx = 1 keyposy = 2 function keysel() keybrdsel:clear() keyscreen:blit(40, 91, keybrd) drawRect(keybrdsel, ((keyposx*26)-26), ((keyposy*26)-26), 26, 26, keyblue) keyscreen:blit(41, 92, keybrdsel) screen:blit(0, 0, keyscreen) screen:flip() end function lowercase() case = "lower" key0123:clear() key4567:clear() key89:clear() keyabcd:clear() keyefgh:clear() keyijkl:clear() keymnop:clear() keyqrst:clear() keyuvwx:clear() keyyz:clear() keysymb:clear() keysymb2:clear() key0123:print(10, 4, "0", keyblack) key0123:print(16, 10, "1", keyblack) key0123:print(4, 10, "3", keyblack) key0123:print(10, 16, "2", keyblack) key4567:print(10, 4, "4", keyblack) key4567:print(16, 10, "5", keyblack) key4567:print(10, 16, "6", keyblack) key4567:print(4, 10, "7", keyblack) key89:print(10, 4, "8", keyblack) key89:print(16, 10, "9", keyblack) keyabcd:print(10, 4, "a", keyblack) keyabcd:print(16, 10, "b", keyblack) keyabcd:print(10, 16, "c", keyblack) keyabcd:print(4, 10, "d", keyblack) keyefgh:print(10, 4, "e", keyblack) keyefgh:print(16, 10, "f", keyblack) keyefgh:print(10, 16, "g", keyblack) keyefgh:print(4, 10, "h", keyblack) -- Line 100 keyijkl:print(10, 4, "i", keyblack) keyijkl:print(16, 10, "j", keyblack) keyijkl:print(10, 16, "k", keyblack) keyijkl:print(4, 10, "l", keyblack) keymnop:print(10, 4, "m", keyblack) keymnop:print(16, 10, "n", keyblack) keymnop:print(10, 16, "o", keyblack) keymnop:print(4, 10, "p", keyblack) keyqrst:print(10, 4, "q", keyblack) keyqrst:print(16, 10, "r", keyblack) keyqrst:print(10, 16, "s", keyblack) keyqrst:print(4, 10, "t", keyblack) keyuvwx:print(10, 4, "u", keyblack) keyuvwx:print(16, 10, "v", keyblack) keyuvwx:print(10, 16, "w", keyblack) keyuvwx:print(4, 10, "x", keyblack) keyyz:print(10, 4, "y", keyblack) keyyz:print(16, 10, "z", keyblack) keysymb:print(10, 4, ":", keyblack) keysymb:print(16, 10, ";", keyblack) keysymb:print(10, 16, "-", keyblack) keysymb:print(4, 10, "+", keyblack) keysymb2:print(10, 4, ",", keyblack) keysymb2:print(16, 10, "<", keyblack) keysymb2:print(10, 16, ".", keyblack) keysymb2:print(4, 10, ">", keyblack) keybrd:clear(keywhite) keybrd:blit(1, 1, key0123) keybrd:blit(27, 1, key4567) keybrd:blit(53, 1, key89) keybrd:blit(1, 27, keyabcd) keybrd:blit(27, 27, keyefgh) keybrd:blit(53, 27, keyijkl) keybrd:blit(1, 53, keymnop) keybrd:blit(27, 53, keyqrst) keybrd:blit(53, 53, keyuvwx) keybrd:blit(1, 79, keyyz) keybrd:blit(27, 79, keysymb) keybrd:blit(53, 79, keysymb2) keyscreen:blit(40, 91, keybrd) keyscreen:blit(41, 92, keybrdsel) screen:blit(0, 0, keyscreen) screen:flip() end function uppercase() case = "upper" key0123:clear() key4567:clear() key89:clear() keyabcd:clear() keyefgh:clear() keyijkl:clear() keymnop:clear() --Line 150 keyqrst:clear() keyuvwx:clear() keyyz:clear() keysymb:clear() keysymb2:clear() key0123:print(10, 4, "!", keyblack) key0123:print(16, 10, "@", keyblack) key0123:print(4, 10, "#", keyblack) key0123:print(10, 16, "$", keyblack) key4567:print(10, 4, "%", keyblack) key4567:print(16, 10, "^", keyblack) key4567:print(10, 16, "&", keyblack) key4567:print(4, 10, "*", keyblack) key89:print(4, 10, "(", keyblack) key89:print(16, 10, ")", keyblack) keyabcd:print(10, 4, "A", keyblack) keyabcd:print(16, 10, "B", keyblack) keyabcd:print(10, 16, "C", keyblack) keyabcd:print(4, 10, "D", keyblack) keyefgh:print(10, 4, "E", keyblack) keyefgh:print(16, 10, "F", keyblack) keyefgh:print(10, 16, "G", keyblack) keyefgh:print(4, 10, "H", keyblack) keyijkl:print(10, 4, "I", keyblack) keyijkl:print(16, 10, "J", keyblack) keyijkl:print(10, 16, "K", keyblack) keyijkl:print(4, 10, "L", keyblack) keymnop:print(10, 4, "M", keyblack) keymnop:print(16, 10, "N", keyblack) keymnop:print(10, 16, "O", keyblack) keymnop:print(4, 10, "P", keyblack) keyqrst:print(10, 4, "Q", keyblack) keyqrst:print(16, 10, "R", keyblack) keyqrst:print(10, 16, "S", keyblack) keyqrst:print(4, 10, "T", keyblack) keyuvwx:print(10, 4, "U", keyblack) keyuvwx:print(16, 10, "V", keyblack) keyuvwx:print(10, 16, "W", keyblack) keyuvwx:print(4, 10, "X", keyblack) keyyz:print(10, 4, "Y", keyblack) -- Line 200 keyyz:print(16, 10, "Z", keyblack) keysymb:print(10, 4, "~", keyblack) keysymb:print(16, 10, "_", keyblack) keysymb:print(10, 16, "?", keyblack) keysymb:print(4, 10, "/", keyblack) keysymb2:print(10, 4, "{", keyblack) keysymb2:print(16, 10, "]", keyblack) keysymb2:print(10, 16, "}", keyblack) keysymb2:print(4, 10, "[", keyblack) keybrd:clear(keywhite) keybrd:blit(1, 1, key0123) keybrd:blit(27, 1, key4567) keybrd:blit(53, 1, key89) keybrd:blit(1, 27, keyabcd) keybrd:blit(27, 27, keyefgh) keybrd:blit(53, 27, keyijkl) keybrd:blit(1, 53, keymnop) keybrd:blit(27, 53, keyqrst) keybrd:blit(53, 53, keyuvwx) keybrd:blit(1, 79, keyyz) keybrd:blit(27, 79, keysymb) keybrd:blit(53, 79, keysymb2) keyscreen:blit(40, 91, keybrd) keyscreen:blit(41, 92, keybrdsel) screen:blit(0, 0, keyscreen) screen:flip() end function prints() if case=="lower" then if pad:triangle() then if keyposy==1 then if keyposx==1 then text = text .. "0" elseif keyposx==2 then text = text .. "4" elseif keyposx==3 then text = text .. "8" end elseif keyposy==2 then if keyposx==1 then text = text .. "a" elseif keyposx==2 then text = text .. "e" elseif keyposx==3 then text = text .. "i" end elseif keyposy==3 then if keyposx==1 then text = text .. "m" elseif keyposx==2 then text = text .. "q" elseif keyposx==3 then text = text .. "u" end elseif keyposy==4 then if keyposx==1 then text = text .. "y" elseif keyposx==2 then text = text .. ":" elseif keyposx==3 then text = text .. "," end end elseif pad:circle() then if keyposy==1 then if keyposx==1 then text = text .. "1" elseif keyposx==2 then text = text .. "5" elseif keyposx==3 then text = text .. "9" end elseif keyposy==2 then if keyposx==1 then text = text .. "b" elseif keyposx==2 then text = text .. "f" elseif keyposx==3 then text = text .. "j" end elseif keyposy==3 then if keyposx==1 then text = text .. "n" elseif keyposx==2 then text = text .. "r" elseif keyposx==3 then text = text .. "v" end elseif keyposy==4 then if keyposx==1 then text = text .. "z" elseif keyposx==2 then text = text .. ";" elseif keyposx==3 then text = text .. "<" end end elseif pad:cross() then if keyposy==1 then if keyposx==1 then text = text .. "2" elseif keyposx==2 then text = text .. "6" elseif keyposx==3 then text = text .. "" end elseif keyposy==2 then if keyposx==1 then text = text .. "c" elseif keyposx==2 then text = text .. "g" elseif keyposx==3 then text = text .. "k" end elseif keyposy==3 then if keyposx==1 then text = text .. "o" elseif keyposx==2 then text = text .. "s" elseif keyposx==3 then text = text .. "w" end elseif keyposy==4 then if keyposx==1 then text = text .. "" elseif keyposx==2 then text = text .. "-" elseif keyposx==3 then text = text .. "." end end elseif pad:square() then if keyposy==1 then if keyposx==1 then text = text .. "3" elseif keyposx==2 then text = text .. "7" elseif keyposx==3 then text = text .. " " end elseif keyposy==2 then if keyposx==1 then text = text .. "d" elseif keyposx==2 then text = text .. "h" elseif keyposx==3 then text = text .. "l" end elseif keyposy==3 then if keyposx==1 then text = text .. "p" elseif keyposx==2 then text = text .. "t" elseif keyposx==3 then text = text .. "x" end elseif keyposy==4 then if keyposx==1 then text = text .. "" elseif keyposx==2 then text = text .. "+" elseif keyposx==3 then text = text .. ">" end end elseif pad:l() then text = string.sub(text, 1, string.len(text)-1) elseif pad:r() then text = text .. " " end elseif case=="upper" then if pad:triangle() then if keyposy==1 then if keyposx==1 then text = text .. "!" elseif keyposx==2 then text = text .. "%" elseif keyposx==3 then text = text .. "" end elseif keyposy==2 then if keyposx==1 then text = text .. "A" elseif keyposx==2 then text = text .. "E" elseif keyposx==3 then text = text .. "I" end elseif keyposy==3 then if keyposx==1 then text = text .. "M" elseif keyposx==2 then text = text .. "Q" elseif keyposx==3 then text = text .. "U" end elseif keyposy==4 then if keyposx==1 then text = text .. "Y" elseif keyposx==2 then text = text .. "~" elseif keyposx==3 then text = text .. "{" end end elseif pad:circle() then if keyposy==1 then if keyposx==1 then text = text .. "@" elseif keyposx==2 then text = text .. "^" elseif keyposx==3 then text = text .. ")" end elseif keyposy==2 then if keyposx==1 then text = text .. "B" elseif keyposx==2 then text = text .. "F" elseif keyposx==3 then text = text .. "J" end elseif keyposy==3 then if keyposx==1 then text = text .. "N" elseif keyposx==2 then text = text .. "R" elseif keyposx==3 then text = text .. "V" end elseif keyposy==4 then if keyposx==1 then text = text .. "Z" elseif keyposx==2 then text = text .. "_" elseif keyposx==3 then text = text .. "]" end end elseif pad:cross() then if keyposy==1 then if keyposx==1 then text = text .. "#" elseif keyposx==2 then text = text .. "&" elseif keyposx==3 then text = text .. "" end elseif keyposy==2 then if keyposx==1 then text = text .. "C" elseif keyposx==2 then text = text .. "G" elseif keyposx==3 then text = text .. "K" end elseif keyposy==3 then if keyposx==1 then text = text .. "O" elseif keyposx==2 then text = text .. "S" elseif keyposx==3 then text = text .. "W" end elseif keyposy==4 then if keyposx==1 then text = text .. "" elseif keyposx==2 then text = text .. "?" elseif keyposx==3 then text = text .. "}" end end elseif pad:square() then if keyposy==1 then if keyposx==1 then text = text .. "$" elseif keyposx==2 then text = text .. "*" elseif keyposx==3 then text = text .. "(" end elseif keyposy==2 then if keyposx==1 then text = text .. "D" elseif keyposx==2 then text = text .. "H" elseif keyposx==3 then text = text .. "L" end elseif keyposy==3 then if keyposx==1 then text = text .. "P" elseif keyposx==2 then text = text .. "T" elseif keyposx==3 then text = text .. "X" end elseif keyposy==4 then if keyposx==1 then text = text .. "" elseif keyposx==2 then text = text .. "/" elseif keyposx==3 then text = text .. "[" end end elseif pad:l() then text = string.sub(text, 1, string.len(text)-1) elseif pad:r() then text = text .. " " end end maxline = math.ceil(string.len(text)/37) printline = 1 textdisp:clear(keywhite) while printline<=maxline do if printline==maxline then textend = string.len(text) else textend = printline*37 end textdisp:print(3, 3+((printline-1)*8), string.sub(text, (printline-1)*37+1, textend), keyblack) printline = printline+1 if textend==string.len(text) then break end end if string.len(text)<=37 then curstextx = (3+(string.len(string.sub(text, (maxline-1)*37, string.len(text)))*8)) elseif string.len(text)>37 then curstextx = (3+(string.len(string.sub(text, (maxline-1)*37, string.len(text)-1))*8)) end textdisp:print(curstextx, 3+((maxline-1)*8), "|", keygreen) keyscreen:blit(150, 50, textdisp) screen:blit(0, 0, keyscreen) screen:flip() end function keyboard() text = "" keyposx = 1 keyposy = 2 keyscreen:clear(keyyellow) drawRect(keyscreen, 149, 49, 301, 173, keygray) drawRect(keyscreen, 39, 90, 81, 107, keygray) keyscreen:print(0, 17, " " .. string.rep("=", 22) .. "Text Entering" .. string.rep("=", 23), keyorange) keyscreen:print(8, 208, " Select = Shift", keyblue) keyscreen:print(8, 216, " Start = Enter", keyblue) keyscreen:print(8, 224, " D-pad = Select Key", keyblue) keyscreen:print(8, 233, " Control Pad = Print Character", keyblue) keyscreen:print(8, 240, " L = Backspace", keyblue) keyscreen:print(8, 248, " R = Space", keyblue) keyscreen:blit(150, 50, textdisp) keyscreen:blit(40, 91, keybrd) keyscreen:blit(41, 92, keybrdsel) lowercase() while true do screen.waitVblankStart(8) pad = Controls.read() if pad:up() then if keyposy==1 then keyposy = 4 else keyposy = keyposy-1 end keysel() elseif pad:down() then if keyposy==4 then keyposy = 1 else keyposy = keyposy+1 end keysel() elseif pad:right() then if keyposx==3 then keyposx = 1 else keyposx = keyposx+1 end keysel() elseif pad:left() then if keyposx==1 then keyposx = 3 else keyposx = keyposx-1 end keysel() elseif pad:l() then prints() elseif pad:r() then prints() elseif pad:triangle() then prints() elseif pad:circle() then prints() elseif pad:cross() then prints() elseif pad:square() then prints() elseif pad:select() then if case=="lower" then uppercase() elseif case=="upper" then lowercase() end elseif pad:start() then save.text() elseif pad:note() then break end end keyscreen:clear() screen:flip() return text end
how do i give SELECT button 2 functions?
like:
and now when i press SELECT again i want to usbDikModeDeactivate..Code:if pad:select() then System.usbDiskModeActivate() end
pls help[1 Year QJ Member]
[LUA Coder and C Learner]
[Ball Revamped Clone v0.1]
[Phil's Shooting Range v0.3]
[HideFile PRX v2]
[SSR PRX v1.1]
-
09-23-2006, 03:33 AM #3514
i can answer the 2 qestion :
select = 1
if pad:select() then
if select == 1 then
select = 2
System.usbDiskModeActivat e()
end
end
if pad:select() then
if select == 2 then
select = 1
System.usbDiskModeDeactiv ate()
end
end
-
09-23-2006, 03:56 AM #3515QJ Gamer Green
- Registriert seit
- Jul 2006
- Ort
- Middle Europe
- Beiträge
- 1.281
- Points
- 11.800
- Level
- 71
- Downloads
- 0
- Uploads
- 0
it doesnt work :/ it doesnt even activate USB
but still thx for caring
[1 Year QJ Member]
[LUA Coder and C Learner]
[Ball Revamped Clone v0.1]
[Phil's Shooting Range v0.3]
[HideFile PRX v2]
[SSR PRX v1.1]
-
09-23-2006, 04:29 AM #3516QJ Gamer Bronze
- Registriert seit
- Feb 2006
- Ort
- Earth, UK
- Beiträge
- 457
- Points
- 5.924
- Level
- 49
- Downloads
- 0
- Uploads
- 0
Question 2
Code:UsbOn = 0 if pad:select() and oldpad:select()~=pad:select() and UsbOn == 0 then select = 1 end if pad:select() and oldpad:select()~=pad:select() and UsbOn == 1 then select = 0 end if UsbOn == 0 then System.usbDiskModeActivate() end if UsbOn == 1 then System.usbDiskModeDeactivate() end
<<Put A message Here>>
<<Just made another rubbish website visit it here.>>
-
09-23-2006, 04:42 AM #3517QJ Gamer Green
- Registriert seit
- Jul 2006
- Ort
- Middle Europe
- Beiträge
- 1.281
- Points
- 11.800
- Level
- 71
- Downloads
- 0
- Uploads
- 0
thx i will try it!
edit. hmm now it activates USB right after i acces the app, then when i press SELECT i just get Error "oldpad" something...
Heres my full code:
and yeh i just started yesterdayCode:-- Moj prvy LUA program -- Author: myschoo -- ******* Variables ******** green = Color.new(0,255,0) zelena = Color.new(34,70,77) oranzova = Color.new(214,128,11) modra = Color.new(0,24,240) bordova = Color.new(138,0,11) myschoo = Color.new(236,225,28) biela = Color.new(255,255,255) upPressed = 'Drzis sipku nahor' downPressed = 'Drzis sipku nadol' leftPressed = 'Drzis sipku dolava' rightPressed = 'Drzis sipku doprava' LPressed = 'Drzis "L" tlacitko' -- *****Main Loop****** while true do dofile("key.lua") back = Image.load("blue.jpg") boltsnd = Sound.load("sound.wav") screen:blit(0, 0, back) screen:print(145, 5, 'Podrz START pre vypnutie', biela) screen:print(155, 15, "Podrz SELECT pre USB", biela) screen:print(155, 25, "Podrz krizik pre zvuk", biela) screen:print(145, 35, 'Podrz R+stvorec pre info', biela) screen:print(145, 45, 'Podrz R+L pre klavesnicu', biela) pad = Controls.read() if pad:up() then screen:print(185,125,upPressed,green) end if pad:down() then screen:print(185,125,downPressed,zelena) end if pad:left() then screen:print(185,125,leftPressed,oranzova) end if pad:right() then screen:print(185,125,rightPressed,modra) end if pad:l() then screen:print(185,125,LPressed,bordova) end if pad:r() then screen:print(185,125,'Drzis "R" tlacitko',green) end if pad:triangle() then screen:print(185,125,'Drzis trojuholnik',zelena) end if pad:circle() then screen:print(185,125,'Drzis kruzok',oranzova) end if pad:cross() then boltsnd:play() screen.flip() Music.volume(128) end if pad:square() then screen:print(185,125,'Drzis stvorec',bordova) end UsbOn = 0 if pad:select() and oldpad:select()~=pad:select() and UsbOn == 0 then select = 1 end if pad:select() and oldpad:select()~=pad:select() and UsbOn == 1 then select = 0 end if UsbOn == 0 then System.usbDiskModeActivate() end if UsbOn == 1 then System.usbDiskModeDeactivate() end if pad:start() then break end if pad:square() and pad:r() then screen:print(175, 255, 'Autor: myschoo', myschoo) end if pad:r() and pad:l() then -- Examples print(keyboard()) thetext = keyboard() end screen.waitVblankStart() screen.flip() end[1 Year QJ Member]
[LUA Coder and C Learner]
[Ball Revamped Clone v0.1]
[Phil's Shooting Range v0.3]
[HideFile PRX v2]
[SSR PRX v1.1]
-
09-23-2006, 05:32 AM #3518QJ Gamer Green
- Registriert seit
- Dec 2005
- Ort
- Here
- Beiträge
- 2.715
- Points
- 13.310
- Level
- 75
- Downloads
- 0
- Uploads
- 0
THAT should work. i never got the "oldpad" way myself...lolCode:select_does_this = 1 if pad:select() and select_does_this == 1 then select_does_this = 2 elseif select_does_this == 2 then select_does_this = 1 end if select_does_this == 1 then System.usbDiskModeDeactivate() elseif select_does_this == 2 then System.usbDiskModeActivate() end
[CENTER][IMG]http://img148.imageshack.us/img148/6985/siglw8.jpg[/IMG][/CENTER]
-
09-23-2006, 05:57 AM #3519QJ Gamer Green
- Registriert seit
- Jul 2006
- Ort
- Middle Europe
- Beiträge
- 1.281
- Points
- 11.800
- Level
- 71
- Downloads
- 0
- Uploads
- 0
yeh this is quiet better...but there is still problem... well..i press SELECT and my PSP USB activates..thats ok :) but then when i stop holding button USB Deactivates, so basicly i have to hold button to be connected now
thx for help guys i appreciate it! ;)Code:-- Moj prvy LUA program -- Author: myschoo -- ******* Variables ******** green = Color.new(0,255,0) zelena = Color.new(34,70,77) oranzova = Color.new(214,128,11) modra = Color.new(0,24,240) bordova = Color.new(138,0,11) myschoo = Color.new(236,225,28) biela = Color.new(255,255,255) upPressed = 'Drzis sipku nahor' downPressed = 'Drzis sipku nadol' leftPressed = 'Drzis sipku dolava' rightPressed = 'Drzis sipku doprava' LPressed = 'Drzis "L" tlacitko' -- *****Main Loop****** while true do dofile("key.lua") back = Image.load("blue.jpg") boltsnd = Sound.load("sound.wav") screen:blit(0, 0, back) screen:print(145, 5, 'Podrz START pre vypnutie', biela) screen:print(155, 15, "Podrz SELECT pre USB", biela) screen:print(155, 25, "Podrz krizik pre zvuk", biela) screen:print(145, 35, 'Podrz R+stvorec pre info', biela) screen:print(145, 45, 'Podrz R+L pre klavesnicu', biela) pad = Controls.read() if pad:up() then screen:print(185,125,upPressed,green) end if pad:down() then screen:print(185,125,downPressed,zelena) end if pad:left() then screen:print(185,125,leftPressed,oranzova) end if pad:right() then screen:print(185,125,rightPressed,modra) end if pad:l() then screen:print(185,125,LPressed,bordova) end if pad:r() then screen:print(185,125,'Drzis "R" tlacitko',green) end if pad:triangle() then screen:print(185,125,'Drzis trojuholnik',zelena) end if pad:circle() then screen:print(185,125,'Drzis kruzok',oranzova) end if pad:cross() then boltsnd:play() screen.flip() Music.volume(128) end if pad:square() then screen:print(185,125,'Drzis stvorec',bordova) end select_does_this = 1 if pad:select() and select_does_this == 1 then select_does_this = 2 elseif select_does_this == 2 then select_does_this = 1 end if select_does_this == 1 then System.usbDiskModeDeactivate() elseif select_does_this == 2 then System.usbDiskModeActivate() end if pad:start() then break end if pad:square() and pad:r() then screen:print(175, 255, 'Autor: myschoo', myschoo) end if pad:r() and pad:l() then -- Examples print(keyboard()) thetext = keyboard() end screen.waitVblankStart() screen.flip() end[1 Year QJ Member]
[LUA Coder and C Learner]
[Ball Revamped Clone v0.1]
[Phil's Shooting Range v0.3]
[HideFile PRX v2]
[SSR PRX v1.1]
-
09-23-2006, 08:22 AM #3520Developer

- Registriert seit
- Jul 2006
- Beiträge
- 205
- Points
- 4.318
- Level
- 41
- Downloads
- 0
- Uploads
- 0
It doesn't work right because you don't check for pad:select when select_does_this==2. Also, you'll have to be very quick or just lucky if you don't use the "oldpad" way, because the code might loop more than once while you are pressing the button, so it would change back and forth.
Zitat von EminentJonFrost
One of many solutions:
At the top of your code with the rest of the constant definitions, put this:When you want to change the USB mode (inside your loop):Code:oldpad=Controls.read() usbmode=false
At the bottom of your loop (still inside):Code:if pad:select() and oldpad:select()~=pad:select() then if usbmode then System.usbDiskModeDeactivate() else System.usbDiskModeActivate() end endNote that the "oldpad" way is just comparing your button presses in the current loop to your button presses in the last loop. If you only want your "if" statement to execute once, then you have to make sure that your button presses in the current loop isn't equal to the ones in your previous loop. This is because code runs so fast that even though you think you are just pressing a button once, the code may loop several times.Code:oldpad=pad
-
09-23-2006, 11:07 AM #3521QJ Gamer Green
- Registriert seit
- Jul 2006
- Ort
- Middle Europe
- Beiträge
- 1.281
- Points
- 11.800
- Level
- 71
- Downloads
- 0
- Uploads
- 0
ok i added ur suggestions and codes and its still SAME... i press button USB activated i realease button USB deactivated... but i want it to stay activated after i stop holding that button

Code:-- Moj prvy LUA program -- Author: myschoo -- ******* Variables ******** green = Color.new(0,255,0) zelena = Color.new(34,70,77) oranzova = Color.new(214,128,11) modra = Color.new(0,24,240) bordova = Color.new(138,0,11) myschoo = Color.new(236,225,28) biela = Color.new(255,255,255) upPressed = 'Drzis sipku nahor' downPressed = 'Drzis sipku nadol' leftPressed = 'Drzis sipku dolava' rightPressed = 'Drzis sipku doprava' LPressed = 'Drzis "L" tlacitko' -- *****Main Loop****** while true do dofile("key.lua") back = Image.load("blue.jpg") boltsnd = Sound.load("sound.wav") screen:blit(0, 0, back) screen:print(145, 5, 'Podrz START pre vypnutie', biela) screen:print(155, 15, "Podrz SELECT pre USB", biela) screen:print(155, 25, "Podrz krizik pre zvuk", biela) screen:print(145, 35, 'Podrz R+stvorec pre info', biela) screen:print(145, 45, 'Podrz R+L pre klavesnicu', biela) pad = Controls.read() if pad:up() then screen:print(185,125,upPressed,green) end if pad:down() then screen:print(185,125,downPressed,zelena) end if pad:left() then screen:print(185,125,leftPressed,oranzova) end if pad:right() then screen:print(185,125,rightPressed,modra) end if pad:l() then screen:print(185,125,LPressed,bordova) end if pad:r() then screen:print(185,125,'Drzis "R" tlacitko',green) end if pad:triangle() then screen:print(185,125,'Drzis trojuholnik',zelena) end if pad:circle() then screen:print(185,125,'Drzis kruzok',oranzova) end if pad:cross() then boltsnd:play() screen.flip() Music.volume(128) end if pad:square() then screen:print(185,125,'Drzis stvorec',bordova) end oldpad=Controls.read() usbmode=false select_does_this = 1 if pad:select() and select_does_this == 1 then select_does_this = 2 elseif select_does_this == 2 then select_does_this = 1 end if pad:select() and oldpad:select()~=pad:select() then if usbmode then System.usbDiskModeDeactivate() else System.usbDiskModeActivate() end end if select_does_this == 1 then System.usbDiskModeDeactivate() elseif select_does_this == 2 then System.usbDiskModeActivate() oldpad=pad end if pad:start() then break end if pad:square() and pad:r() then screen:print(175, 255, 'Autor: myschoo', myschoo) end if pad:r() and pad:l() then -- Examples print(keyboard()) thetext = keyboard() end screen.waitVblankStart() screen.flip() end[1 Year QJ Member]
[LUA Coder and C Learner]
[Ball Revamped Clone v0.1]
[Phil's Shooting Range v0.3]
[HideFile PRX v2]
[SSR PRX v1.1]
-
09-24-2006, 06:48 AM #3522QJ Gamer Green
- Registriert seit
- Nov 2005
- Ort
- NoWhere . . . .
- Beiträge
- 1.266
- Points
- 7.598
- Level
- 58
- Downloads
- 0
- Uploads
- 0
i keep getting expected then near = at line 50 with this code
but this code worksCode:if menustatus => 4 then menustatus = 1 end
Code:if menustatus <= 0 then menustatus = 3 end
-
09-24-2006, 07:56 AM #3523
i think it is meant to be like this :
if menustatus >= 4 then
menustatus = 1
end
-
09-24-2006, 08:10 AM #3524sceKernelExitGame();
- Registriert seit
- Jan 2006
- Ort
- New York
- Beiträge
- 3.126
- Points
- 19.955
- Level
- 89
- Downloads
- 0
- Uploads
- 0
Yeah, it is
Zitat von PSP-Maniac
-
09-24-2006, 08:12 AM #3525QJ Gamer Green
- Registriert seit
- Nov 2005
- Ort
- NoWhere . . . .
- Beiträge
- 1.266
- Points
- 7.598
- Level
- 58
- Downloads
- 0
- Uploads
- 0
ya it works great i took that part from the lua sniplets thread at the top and didnt think that idbe wrong so i didnt check.
-
09-24-2006, 08:21 AM #3526QJ Gamer Green
- Registriert seit
- Jul 2006
- Ort
- Middle Europe
- Beiträge
- 1.281
- Points
- 11.800
- Level
- 71
- Downloads
- 0
- Uploads
- 0
can anyone help me? ??????????????? pls!!
[1 Year QJ Member]
[LUA Coder and C Learner]
[Ball Revamped Clone v0.1]
[Phil's Shooting Range v0.3]
[HideFile PRX v2]
[SSR PRX v1.1]
-
09-24-2006, 08:31 AM #3527Developer

- Registriert seit
- Jul 2006
- Beiträge
- 205
- Points
- 4.318
- Level
- 41
- Downloads
- 0
- Uploads
- 0
You almost did.
Zitat von myschoo
The "oldpad = Controls.read()" and "usbmode=false" lines are supposed to be before the while loop, in your ***Variables*** section.
EDIT: Also, you need to get rid of these parts:
andCode:if pad:select() and select_does_this == 1 then select_does_this = 2 elseif select_does_this == 2 then select_does_this = 1 end
And put the "oldpad = pad" line at the end of the while loop.Code:if select_does_this == 1 then System.usbDiskModeDeactivate() elseif select_does_this == 2 then System.usbDiskModeActivate() oldpad=pad end
-
09-24-2006, 12:05 PM #3528QJ Gamer Green
- Registriert seit
- Jul 2006
- Ort
- Middle Europe
- Beiträge
- 1.281
- Points
- 11.800
- Level
- 71
- Downloads
- 0
- Uploads
- 0
thx i will try it asap!!
now when i press SELECT it activates USB but wneh i press SELECT again nothing happensCode:-- Moj prvy LUA program -- Author: myschoo -- ******* Variables ******** green = Color.new(0,255,0) zelena = Color.new(34,70,77) oranzova = Color.new(214,128,11) modra = Color.new(0,24,240) bordova = Color.new(138,0,11) myschoo = Color.new(236,225,28) biela = Color.new(255,255,255) upPressed = 'Drzis sipku nahor' downPressed = 'Drzis sipku nadol' leftPressed = 'Drzis sipku dolava' rightPressed = 'Drzis sipku doprava' LPressed = 'Drzis "L" tlacitko' oldpad=Controls.read() usbmode=false -- *****Main Loop****** while true do dofile("key.lua") back = Image.load("blue.jpg") boltsnd = Sound.load("sound.wav") screen:blit(0, 0, back) screen:print(145, 5, 'Podrz START pre vypnutie', biela) screen:print(155, 15, "Podrz SELECT pre USB", biela) screen:print(155, 25, "Podrz krizik pre zvuk", biela) screen:print(145, 35, 'Podrz R+stvorec pre info', biela) screen:print(145, 45, 'Podrz R+L pre klavesnicu', biela) pad = Controls.read() if pad:up() then screen:print(185,125,upPressed,green) end if pad:down() then screen:print(185,125,downPressed,zelena) end if pad:left() then screen:print(185,125,leftPressed,oranzova) end if pad:right() then screen:print(185,125,rightPressed,modra) end if pad:l() then screen:print(185,125,LPressed,bordova) end if pad:r() then screen:print(185,125,'Drzis "R" tlacitko',green) end if pad:triangle() then screen:print(185,125,'Drzis trojuholnik',zelena) end if pad:circle() then screen:print(185,125,'Drzis kruzok',oranzova) end if pad:cross() then boltsnd:play() screen.flip() Music.volume(128) end if pad:square() then screen:print(185,125,'Drzis stvorec',bordova) end if pad:select() and oldpad:select()~=pad:select() then if usbmode then System.usbDiskModeDeactivate() else System.usbDiskModeActivate() end end if pad:start() then break end if pad:square() and pad:r() then screen:print(175, 255, 'Autor: myschoo', myschoo) end if pad:r() and pad:l() then -- Examples print(keyboard()) thetext = keyboard() end screen.waitVblankStart() screen.flip() oldpad = pad end
(:Cry:
Geändert von myschoo (09-24-2006 um 12:17 PM Uhr)
[1 Year QJ Member]
[LUA Coder and C Learner]
[Ball Revamped Clone v0.1]
[Phil's Shooting Range v0.3]
[HideFile PRX v2]
[SSR PRX v1.1]
-
09-24-2006, 12:39 PM #3529Your Fate is Grim...

- Registriert seit
- Oct 2005
- Beiträge
- 2.269
- Points
- 11.640
- Level
- 70
- Downloads
- 0
- Uploads
- 0
Zitat von myschoo
try this:
Code:--put thsi outside your main loop-- selectPressed = false usbInit = false --put this in youre main loop-- if pad:select() then if not selectPressed then if usbInit == false then usbInit = true end selectPressed = true else selectPressed = false end if usbInit == true --usb acivate code, im too lazy to find it-- else --usb UNactivate-- end
with the above code, you dont need oldpad, it works 100% of them time.--------------------------------------------------------------------------------------
-
09-24-2006, 12:42 PM #3530I'm Baaaack!

- Registriert seit
- May 2006
- Ort
- Nowhere
- Beiträge
- 2.186
- Points
- 17.067
- Level
- 83
- Downloads
- 0
- Uploads
- 0
Try this:
Code:usbmode = "false" if pad:select() and oldpad:select() ~= pad:select() and usbmode == "false" then System.usbDiskModeActivate() end if pad:select() and oldpad:select() ~= pad:select() and usbmode == "true" then System.usbDiskModeDeactivate() end

-
09-24-2006, 12:53 PM #3531Developer

- Registriert seit
- Jul 2006
- Beiträge
- 205
- Points
- 4.318
- Level
- 41
- Downloads
- 0
- Uploads
- 0
You guys are hilarious...he won't learn if you just give him code to "try" without telling him what's wrong.
On my suggestion, I forgot to make it switch the state of "usbmode," so it always tries to activate it. All you have to do is change it back and forth when select is pressed:
Just go with what makes sense to you. I tried to explain "oldpad" in my last post, but as mentioned it is not the only way.Code:if pad:select() and oldpad:select()~=pad:select() then if usbmode then System.usbDiskModeDeactivate() usbmode=false else System.usbDiskModeActivate() usbmode=true end end
-
09-25-2006, 07:35 AM #3532QJ Gamer Green
- Registriert seit
- Jul 2006
- Ort
- Middle Europe
- Beiträge
- 1.281
- Points
- 11.800
- Level
- 71
- Downloads
- 0
- Uploads
- 0
Ok so here we go:
LMelior: if i try ur method,t activates USB and thena after 1 sec deactivates without moving my finger from button :/
ARza: ur method activates usb without toching anything
Grimfate: Error: A.LUA:90: "then" expected near "System"
[1 Year QJ Member]
[LUA Coder and C Learner]
[Ball Revamped Clone v0.1]
[Phil's Shooting Range v0.3]
[HideFile PRX v2]
[SSR PRX v1.1]
-
09-26-2006, 03:11 AM #3533Developer

- Registriert seit
- Jul 2006
- Beiträge
- 205
- Points
- 4.318
- Level
- 41
- Downloads
- 0
- Uploads
- 0
This works perfectly fine for me:
I just printed out a message so I could test on Luaplayer for Windows. I also changed the button because I'm too lazy to look up what key "select" is, but I know which key "cross" is.Code:-- ******* Variables ******** green = Color.new(0,255,0) oldpad=Controls.read() usbmode=false -- *****Main Loop****** while true do screen:clear() pad=Controls.read() if pad:cross() and oldpad:cross()~=pad:cross() then if usbmode then System.usbDiskModeDeactivate() usbmode=false else System.usbDiskModeActivate() usbmode=true end end if usbmode then screen:print(200,100,'USB Activated',green) else screen:print(200,100,'USB Deactivated',green) end screen.waitVblankStart() screen.flip() oldpad = pad end
As for the others:
ARza forgot the same thing I did, to switch the state of usbmode after the button is pressed.
Read the error that you posted for Grimfate's. Isn't the fix obvious?
-
09-26-2006, 10:55 AM #3534QJ Gamer Green
- Registriert seit
- Jul 2006
- Ort
- Middle Europe
- Beiträge
- 1.281
- Points
- 11.800
- Level
- 71
- Downloads
- 0
- Uploads
- 0
THX LMelior!!! it works!!! thx!!!!
-= Double Post =-
OK i have new question
i used this code:
to view battery...but when i try it in my PC LUA player i can see it in CMDCode:print(tostring(System.powerGetBatteryLifePercent()) .. "%") screen:flip()
Geändert von myschoo (09-26-2006 um 10:55 AM Uhr) Grund: Automerged Doublepost
[1 Year QJ Member]
[LUA Coder and C Learner]
[Ball Revamped Clone v0.1]
[Phil's Shooting Range v0.3]
[HideFile PRX v2]
[SSR PRX v1.1]
-
09-26-2006, 11:01 AM #3535
what was the question?
-
09-26-2006, 11:18 AM #3536QJ Gamer Green
- Registriert seit
- Jul 2006
- Ort
- Middle Europe
- Beiträge
- 1.281
- Points
- 11.800
- Level
- 71
- Downloads
- 0
- Uploads
- 0
which question do u mean??? its in my post
[1 Year QJ Member]
[LUA Coder and C Learner]
[Ball Revamped Clone v0.1]
[Phil's Shooting Range v0.3]
[HideFile PRX v2]
[SSR PRX v1.1]
-
09-26-2006, 11:56 AM #3537QJ Gamer Silver

- Registriert seit
- Jun 2006
- Ort
- UK
- Beiträge
- 2.326
- Points
- 10.263
- Level
- 67
- Downloads
- 0
- Uploads
- 0
You are using the print function which prints to the console rather then the screen. Use screen:print instead.
-
09-26-2006, 12:24 PM #3538QJ Gamer Green
- Registriert seit
- Jul 2006
- Ort
- Middle Europe
- Beiträge
- 1.281
- Points
- 11.800
- Level
- 71
- Downloads
- 0
- Uploads
- 0
it says some error when i use screen
rint
[1 Year QJ Member]
[LUA Coder and C Learner]
[Ball Revamped Clone v0.1]
[Phil's Shooting Range v0.3]
[HideFile PRX v2]
[SSR PRX v1.1]
-
09-26-2006, 12:38 PM #3539QJ Gamer Silver

- Registriert seit
- Jun 2006
- Ort
- UK
- Beiträge
- 2.326
- Points
- 10.263
- Level
- 67
- Downloads
- 0
- Uploads
- 0
Considering you used it twice already in your own code, you should really be able to fix the error yourself.
-
09-27-2006, 04:39 AM #3540QJ Gamer Green
- Registriert seit
- Jul 2006
- Ort
- Middle Europe
- Beiträge
- 1.281
- Points
- 11.800
- Level
- 71
- Downloads
- 0
- Uploads
- 0
that was usefull :/
[1 Year QJ Member]
[LUA Coder and C Learner]
[Ball Revamped Clone v0.1]
[Phil's Shooting Range v0.3]
[HideFile PRX v2]
[SSR PRX v1.1]


LinkBack URL
About LinkBacks
Mit Zitat antworten

Hello everyone I am new here and I am glad to be part of this amazing community and I think there...
New to forum