QJ.NET | Videos | Forums | iPhone | MMORPG | Nintendo DS | Wii | PlayStation 3 | PSP | Xbox 360 | PC | Downloads | Contact Us
Forums | Gaming News | Videos | Downloads | Today's Posts | Mark Forums Read | Chat | FAQ | Members List | Contact

QJ.net Game Discussion - PSP, Xbox, Wii, PS3, PSP Homebrew, and PSP Guides

Go Back   QJ.net Game Discussion - PSP, Xbox, Wii, PS3, PSP Homebrew, and PSP Guides > Developers Corner > PSP Development, Hacks, and Homebrew > PSP Development Forum
The above video goes away if you are a member and logged in, so log in now!

Need Some LUA help PLEASE

This is a discussion on Need Some LUA help PLEASE within the PSP Development Forum forums, part of the PSP Development, Hacks, and Homebrew category; Ive created a simple program that enables USB and it works. USB gets activated when you press X. My only ...

Reply
 
LinkBack Thread Tools
Old 08-16-2006, 10:28 AM   #1
 
 
My Mood: Bored
Join Date: Apr 2006
Location: England ~¦¦¦|+|¦¦¦~
Posts: 1,112
Trader Feedback: 0
Default Need Some LUA help PLEASE

Ive created a simple program that enables USB and it works. USB gets activated when you press X. My only problem is, the text that says USB mode is active (screenrint(240,136,"US B mode is active",red)) It will only display when i am holding it down. How to i get it to stay there?
__________________
...Just Returned To The Scene...
JaSo PsP is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 08-16-2006, 10:32 AM   #2
 
Nutterbutter's Avatar
 
Join Date: Jun 2006
Location: London
Posts: 645
Trader Feedback: 0
Default

Set up a int, call it, usba.

Make a while loop in your program, that has the button input code. But if X is pressed set the usba to 1. Then set up an if loop that runs the screen printf if usba is 1.

This is it in C.

Code:
 int main(){

  SceCtrlData pad;
  int usba = 0;
 
 while(1){ 
  
        sceCtrlReadBufferPositive(&pad, 1);

      if (pad.Buttons & PSP_CTRL_CROSS){

       usba = 1 }
   
     if (usba == 1) {

     printf("USB mode is active");

     }

}
}
Im dont remember what the USB activation code is tho.

Sorry my lua isnt great, otherwise i would have written the lua code out.
__________________
[b][center]
[URL="http://forums.qj.net/showthread.php?t=65032"][SIZE="3"][COLOR="Blue"]Omicron[/COLOR] - [COLOR="DeepSkyBlue"]A hacking simulation game for the PSP[/COLOR][/SIZE][/URL]

[url=http://profile.mygamercard.net/dr+nutterbutter][img]http://card.mygamercard.net/gbar/live/dr+nutterbutter.gif[/img][/url][/b][/center]
Nutterbutter is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 08-16-2006, 10:33 AM   #3
 
 
My Mood: Bored
Join Date: Apr 2006
Location: England ~¦¦¦|+|¦¦¦~
Posts: 1,112
Trader Feedback: 0
Default

Quote:
Originally Posted by Nutterbutter
Set up a int, call it, usba.

Make a while loop in your program, that has the button input code. But if X is pressed set the usba to 1. Then set up an if loop that runs the screen printf if usba is 1.

Sorry my lua isnt great, otherwise i would have written the code out.
got it, i have to put the 'press x to enter usb mode' outside the 'while true do' part
__________________
...Just Returned To The Scene...
JaSo PsP is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 08-16-2006, 10:37 AM   #4

I'm Baaaack!
 
Access_Denied's Avatar
 
Join Date: May 2006
Location: Waukegan,Illinois
Posts: 2,185
Trader Feedback: 0
Default

Try this:

if pad:cross() then
Dofunction()
end

Dofunction()
while true do
usb mode activate
screen print
screen.waitVblankStart()
screen.flip()
end
end
__________________
Access_Denied is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 08-16-2006, 10:40 AM   #5
 
Nutterbutter's Avatar
 
Join Date: Jun 2006
Location: London
Posts: 645
Trader Feedback: 0
Default

Try this.

Code:
usba = 1

while true do

      pad = Controls.read()
	        if pad:start() then
               
                    // USB activate code goes here
              
                 usba = 1
                 end

               if usba = 1 then 

                 (screenrint(240,136,"USB mode is active",red))

               end

end
Functions are pretty hard for somebody of his experience.
__________________
[b][center]
[URL="http://forums.qj.net/showthread.php?t=65032"][SIZE="3"][COLOR="Blue"]Omicron[/COLOR] - [COLOR="DeepSkyBlue"]A hacking simulation game for the PSP[/COLOR][/SIZE][/URL]

[url=http://profile.mygamercard.net/dr+nutterbutter][img]http://card.mygamercard.net/gbar/live/dr+nutterbutter.gif[/img][/url][/b][/center]

Last edited by Nutterbutter; 08-16-2006 at 10:41 AM.. Reason: Automerged Doublepost
Nutterbutter is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 08-16-2006, 10:41 AM   #6

Your Fate is Grim...
 
Grimfate126's Avatar
 
Join Date: Oct 2005
Posts: 2,269
Trader Feedback: 0
Default

Quote:
Originally Posted by Access_Denied
Try this:

if pad:cross() then
Dofunction()
end

Dofunction()
while true do
usb mode activate
screen print
screen.waitVblankStart()
screen.flip()
end
end
ull still have the same problme tho.

try:
Code:
usbEnabled = false
oldpad = Controls.read()

while true do
screen:clear()
pad = Controls.read()

if pad:cross() and oldpad:cross() ~= pad:cross() and usbEnabled == false then
usbEnabled = true
else
usbEnabled = false
end

if usbEnabled == true then
--activate usb
-- print whatever
end

screen.waitVblankStart()
screen:flip()
oldpad = pad
end
__________________
--------------------------------------------------------------------------------------
Grimfate126 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 08-16-2006, 10:42 AM   #7
 
 
My Mood: Bored
Join Date: Apr 2006
Location: England ~¦¦¦|+|¦¦¦~
Posts: 1,112
Trader Feedback: 0
Default

no, i sort of got it but the screen was flickering from lowser to my program??
__________________
...Just Returned To The Scene...
JaSo PsP is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 08-16-2006, 10:44 AM   #8
 
JoeDaStudd's Avatar
 
Join Date: Feb 2006
Location: Earth, UK
Posts: 457
Trader Feedback: 0
Default

The main loop should look like this, kinda

Code:
while true do
pad=Controls.read
screen:clear()
if pad:cross()then
usba="yes"
 
end
if usba=="yes" then
System.usbDiskModeActivate()
screen:print(240,136,"USB mode is active",red)
end
screen.waitVblankStart()
screen.flip()
end
__________________
<<Put A message Here>>
<<Just made another rubbish website visit it [URL="http://www.joedastudd.co.uk/"]here[/URL].>>
JoeDaStudd is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 08-16-2006, 10:45 AM   #9
 
Nutterbutter's Avatar
 
Join Date: Jun 2006
Location: London
Posts: 645
Trader Feedback: 0
Default

Quote:
Originally Posted by Nutterbutter
Try this.

Code:
usba = 1

while true do

      pad = Controls.read()
	        if pad:start() then
               
                    // USB activate code goes here
              
                 usba = 1
                 end

               if usba = 1 then 

                 (screenprint(240,136,"USB mode is active",red))

               end

end
Functions are pretty hard for somebody of his experience.
USE THIS!!!
__________________
[b][center]
[URL="http://forums.qj.net/showthread.php?t=65032"][SIZE="3"][COLOR="Blue"]Omicron[/COLOR] - [COLOR="DeepSkyBlue"]A hacking simulation game for the PSP[/COLOR][/SIZE][/URL]

[url=http://profile.mygamercard.net/dr+nutterbutter][img]http://card.mygamercard.net/gbar/live/dr+nutterbutter.gif[/img][/url][/b][/center]
Nutterbutter is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 08-16-2006, 10:45 AM   #10
 

 
Join Date: Mar 2006
Location: LOLWUT
Posts: 2,625
Trader Feedback: 1
Default

Quote:
Originally Posted by JaSo PsP
no, i sort of got it but the screen was flickering from lowser to my program??
You have too many screen.waitVblankStart's, or screen.flip's.
PSPduh is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 08-16-2006, 10:47 AM   #11
 
 
My Mood: Bored
Join Date: Apr 2006
Location: England ~¦¦¦|+|¦¦¦~
Posts: 1,112
Trader Feedback: 0
Default

this is wot i got at the moment:

Code:
red = Color.new(255,0,0)
screen:print(240,136,"Press X to enter USB mode", red)

while true do
pad = Controls.read()
if pad:cross() then
screen:clear()
System.usbDiskModeActivate()
screen:print(240,136,"USB mode active", red)
end
if pad:start() then
return
end
screen.flip()
end
-= Double Post =-
Quote:
Originally Posted by PSPduh
You have too many screen.waitVblankStart's, or screen.flip's.
i dont have a single screen:waitVblankStarts
__________________
...Just Returned To The Scene...

Last edited by JaSo PsP; 08-16-2006 at 10:47 AM.. Reason: Automerged Doublepost
JaSo PsP is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 08-16-2006, 10:49 AM   #12
 

 
Join Date: Mar 2006
Location: LOLWUT
Posts: 2,625
Trader Feedback: 1
Default

Quote:
Originally Posted by JaSo PsP
this is wot i got at the moment:

Code:
red = Color.new(255,0,0)
screen:print(240,136,"Press X to enter USB mode", red)

while true do
pad = Controls.read()
if pad:cross() then
screen:clear()
System.usbDiskModeActivate()
screen:print(240,136,"USB mode active", red)
end
if pad:start() then
return
end
screen.flip()
end
-= Double Post =-


i dont have a single screen:waitVblankStarts
You should. It should be at the VERY end of your code:

screen.waitVblankStart()
screen.flip()
end

Also, have you ever heard of this thread?
PSPduh is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 08-16-2006, 10:54 AM   #13
 
 
My Mood: Bored
Join Date: Apr 2006
Location: England ~¦¦¦|+|¦¦¦~
Posts: 1,112
Trader Feedback: 0
Default

Quote:
Originally Posted by PSPduh
You should. It should be at the VERY end of your code:

screen.waitVblankStart()
screen.flip()
end

Also, have you ever heard of this thread?
i know about screen.waitVblankStart() but ive almost got it, the USB mode active text stays there but when it says press X to activate USB mode it has lowser in the background...?
-= Double Post =-
ok, it still flashes like this...

Code:
screen:clear()
red = Color.new(255,0,0)
screen:print(240,136,"Press X to enter USB mode", red)

while true do
pad = Controls.read()
if pad:cross() then
screen:clear()
System.usbDiskModeActivate()
screen:print(240,136,"USB mode active", red)
end
if pad:start() then
return
end
screen.waitVblankStart() 
screen.flip()
end
__________________
...Just Returned To The Scene...

Last edited by JaSo PsP; 08-16-2006 at 10:55 AM.. Reason: Automerged Doublepost
JaSo PsP is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 08-16-2006, 10:57 AM   #14
 
JoeDaStudd's Avatar
 
Join Date: Feb 2006
Location: Earth, UK
Posts: 457
Trader Feedback: 0
Default

try
Code:
red = Color.new(255,0,0)
usba="no"

while true do
pad = Controls.read()
screen:clear()
if usba=="no" then
screen:print(240,136,"Press X to enter USB mode", red)
else
screen:print(240,136,"USB mode active", red)
end
if pad:cross() then
System.usbDiskModeActivate()
usba="yes"
end
if pad:start() then
break
end
screen.waitVblankStart()
screen.flip()
end
__________________
<<Put A message Here>>
<<Just made another rubbish website visit it [URL="http://www.joedastudd.co.uk/"]here[/URL].>>
JoeDaStudd is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 08-16-2006, 10:59 AM   #15

I'm Baaaack!
 
Access_Denied's Avatar
 
Join Date: May 2006
Location: Waukegan,Illinois
Posts: 2,185
Trader Feedback: 0
Default

Do this:
Code:
function Activate()
while true do
screen:clear()
pad = Contols.read()
screen: print(240,136,"USB mode active", red)
System.usbDiskModeActivate()
if pad:start() then
return
end
screen.waitVblankStart()
screen.flip()
end
end


red = Color.new(255,0,0)
while true do
screen:clear()
pad = Controls.read()

screen: print(240,136,"Pre ss X to enter USB mode", red)
if pad:cross() then
Activate()
end
screen.waitVblankStart()
screen.flip()
end
__________________
Access_Denied is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 08-16-2006, 11:00 AM   #16
 
 
My Mood: Bored
Join Date: Apr 2006
Location: England ~¦¦¦|+|¦¦¦~
Posts: 1,112
Trader Feedback: 0
Default

Quote:
Originally Posted by JoeDaStudd
try
Code:
red = Color.new(255,0,0)
usba="no"

while true do
pad = Controls.read()
screen:clear()
if usba=="no" then
screen:print(240,136,"Press X to enter USB mode", red)
else
screen:print(240,136,"USB mode active", red)
end
if pad:cross() then
System.usbDiskModeActivate()
usba="yes"
end
if pad:start() then
break
end
screen.waitVblankStart()
screen.flip()
end
yer, u got it, ill see if it works...
__________________
...Just Returned To The Scene...
JaSo PsP is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 08-16-2006, 11:06 AM   #17

sceKernelExitGame();
 
Bronx's Avatar
 
Join Date: Jan 2006
Location: New York
Posts: 3,125
Trader Feedback: 0
Default

Quote:
Originally Posted by Nutterbutter
USE THIS!!!
your syntax is al wrong , ur combining c and lua lol
Bronx is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 08-16-2006, 12:10 PM   #18
 
Nutterbutter's Avatar
 
Join Date: Jun 2006
Location: London
Posts: 645
Trader Feedback: 0
Default

Quote:
Originally Posted by Bronx
your syntax is al wrong , ur combining c and lua lol
__________________
[b][center]
[URL="http://forums.qj.net/showthread.php?t=65032"][SIZE="3"][COLOR="Blue"]Omicron[/COLOR] - [COLOR="DeepSkyBlue"]A hacking simulation game for the PSP[/COLOR][/SIZE][/URL]

[url=http://profile.mygamercard.net/dr+nutterbutter][img]http://card.mygamercard.net/gbar/live/dr+nutterbutter.gif[/img][/url][/b][/center]
Nutterbutter is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 08-16-2006, 04:25 PM   #19

...in a dream...
 
SG57's Avatar
 
Join Date: Jul 2005
Posts: 4,957
Trader Feedback: 0
Default

No need for a completely seperate thread for something as simple as a bool to tell whether or not the usb is active or not...

Code:
usb = false
white = Color.new(255,255,255)

while true do
     pad = Controls.read()
     
     if usb==true then screen:print(0,0,"SG57: USB On", white)
     else screen:print(0,0,"SG57: Usb Off",white) end

     if pad:cross() then usb = ~usb end
end
Im positive someone has explained booleans to you if you read all those tutorials right?
__________________
SG57 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 08-16-2006, 04:53 PM   #20

Developer
 
yaustar's Avatar
 
Join Date: Jun 2006
Location: UK
Posts: 2,317
Trader Feedback: 0
Default

I would change it this so that it can tell the difference from a singular key press and release:
Code:
usb = false
WasCrossPressed = false;
white = Color.new(255,255,255)

while true do
     pad = Controls.read()
     
     if usb==true then screen:print(0,0,"SG57: USB On", white)
     else screen:print(0,0,"SG57: Usb Off",white) end

     if pad:cross() then 
          if not WasCrossPressed then
               usb = ~usb
          end
          WasCrossPressed = true
     else
          WasCrossPressed = false
     end
end
yaustar is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Tags
lua

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off



All times are GMT -8. The time now is 09:24 PM.



Use of this Web site constitutes acceptance of the TERMS & CONDITIONS and PRIVACY POLICY
Copyright © 2009, QJ.NET. All Rights Reserved.
Contact Us