forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

im a noob!!!!!!!!, need some advice

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Lua Player Development
View previous topic :: View next topic  
Author Message
Hazuki



Joined: 20 Mar 2005
Posts: 21

PostPosted: Sun Feb 05, 2006 2:45 am    Post subject: im a noob!!!!!!!!, need some advice Reply with quote

hi,

i've never coded in my life >_<, and i REALLY want to make a QTE replica of the game in shenmue. if you dont know it, its a simply game with button symbols flashing up on screen, and you press them before they dissapear.

i've read the tutorials i can find, but i dont understand some stuff, i would like for the player to show an image and wait 1 second, and hide the image again. if x is pressed while the image is there then a counter goes up (score), and if any other button is pressed (or no buttons) then a seperate coutner goes down (lives).

ignore me if this is too trivial for this forum.

i can get it to show the image, and make a counter go up when x is pressed, but they are unrelated (and the counter shoots up fast, obviously).

any help would be appreciated.
Back to top
View user's profile Send private message
the underminer



Joined: 03 Oct 2005
Posts: 124
Location: Netherlands

PostPosted: Mon Feb 06, 2006 1:29 am    Post subject: Reply with quote

Code:
System.sleep(miliseconds)

It halts script execution completely, saving battery life as a bonus.

1 second would be:
Code:
System.sleep(1000)

all default lua functions can be found here:
http://www.lua.org/manual/5.0/

but I think this isn't what you're looking for, since you want luaplayer to check if the x button is pressed while the image is displayed. You need a timer. See this page for timer functions and other luaplayer functions:

http://wiki.ps2dev.org/psp:lua_player:functions#millisecond_timer

after you created a new timer and started it, you should make a loop that checks the time and if it is greater than 1000, remove the image.

Code:

while timer:time() < 1000 do
pad = Controls.read()
if pad:cross() then
score = score + 1
end
end

screen:clear()


something like that. I might have made some spelling mistakes in the code
_________________
Behold! The Underminer got hold of a PSP
Back to top
View user's profile Send private message
Hazuki



Joined: 20 Mar 2005
Posts: 21

PostPosted: Mon Feb 06, 2006 10:37 pm    Post subject: Reply with quote

thanks alot, thats a great help!

let you know how its going once i've had a go with the timer!

thanks again!
Back to top
View user's profile Send private message
fullerlee



Joined: 03 Nov 2005
Posts: 54

PostPosted: Tue Feb 07, 2006 1:58 am    Post subject: Reply with quote

I think you'd be better adding screen.waitVblankStart() inside the loop.

This will pause execution of the PSP until the next cycle. Without this line, you'll be throttling the CPU. Someone correct me if i'm wrong.

Lee


Code:
while timer:time() < 1000 do
   pad = Controls.read()
   if pad:cross() then
      score = score + 1
   end
   --This will sync each loop to 1/60th of a ms
   screen.waitVblankStart()
end

screen:clear()
Back to top
View user's profile Send private message
KawaGeo



Joined: 27 Aug 2005
Posts: 191
Location: Calif Mountains

PostPosted: Tue Feb 07, 2006 2:39 am    Post subject: Reply with quote

What about system.sleep()? It is supposed to free CPU while sleeping.
_________________
Geo Massar
Retired Engineer
Back to top
View user's profile Send private message Send e-mail
fullerlee



Joined: 03 Nov 2005
Posts: 54

PostPosted: Tue Feb 07, 2006 3:42 am    Post subject: Reply with quote

I could be way off here, but I believe that
Code:
screen.waitVblankStart()
will only wait as long as it needs until the end of the next clock cycle (1/60th ms), whereas
Code:
System.sleep(miliseconds)
will always wait the specified amount of time (and will also only resolve to a millisecond integer).

Lee
Back to top
View user's profile Send private message
romero126



Joined: 24 Dec 2005
Posts: 200

PostPosted: Tue Feb 07, 2006 10:31 am    Post subject: Reply with quote

System.sleep() sleeps the entire system for x ammount of time which means no input can be processed.

So in otherwords thats a no go.

setting up a timer would be the only option you have available for timing each element to a specific event.

Another thing I would introduce is the ability time multiple elements in the script.

which would probably go something like this

Code:
local timer = Timer.new()
timer:start() // this starts the timer and also gets the seconds. (A bug possibly)
timertable = { }


function timertable_insert(endtime)
   // adds a table to timertable (used for loop below)
   table.insert(timertable, { timer:start(), endtime })
end


timertable_insert(10000);

while true do
   // An endless loop break fixes that
   // Keyboard input here.
   local mytime = timer:start(); // Gets time
   
   for k,v in timertable do
      // gets all the elements of timertable
      if (timer:start() > (v[1] + v[2])) then
         timertable[k] = nil; // removes the variable from existance
      end
   end
   
end


More code must be added to this to make it workable but its a general idea of how to use it.
Back to top
View user's profile Send private message
Hazuki



Joined: 20 Mar 2005
Posts: 21

PostPosted: Tue Feb 07, 2006 11:51 pm    Post subject: Reply with quote

woah, thanks for all of this, i think it'll take me a while to do this, and get my head round it!

awesome, cant wait to actually get some of this going!
Back to top
View user's profile Send private message
the underminer



Joined: 03 Oct 2005
Posts: 124
Location: Netherlands

PostPosted: Wed Feb 08, 2006 6:56 pm    Post subject: Reply with quote

romero126 wrote:


Code:

   local mytime = timer:start(); // Gets time
   



Isn't timer:start() the time that the timer was started? So, if I understand correctly, it doesn't get the current time. I don't quite understand why you put that line there.

By the way, romero, i've got some experience with lua coding now, and part of that is because of you. You really should get an award for all the work you do for noobs :-)
_________________
Behold! The Underminer got hold of a PSP
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Lua Player Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group