| View previous topic :: View next topic |
| Author |
Message |
Hazuki
Joined: 20 Mar 2005 Posts: 21
|
Posted: Sun Feb 05, 2006 2:45 am Post subject: im a noob!!!!!!!!, need some advice |
|
|
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 |
|
 |
the underminer
Joined: 03 Oct 2005 Posts: 124 Location: Netherlands
|
Posted: Mon Feb 06, 2006 1:29 am Post subject: |
|
|
| Code: | | System.sleep(miliseconds) |
It halts script execution completely, saving battery life as a bonus.
1 second would be:
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 |
|
 |
Hazuki
Joined: 20 Mar 2005 Posts: 21
|
Posted: Mon Feb 06, 2006 10:37 pm Post subject: |
|
|
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 |
|
 |
fullerlee
Joined: 03 Nov 2005 Posts: 54
|
Posted: Tue Feb 07, 2006 1:58 am Post subject: |
|
|
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 |
|
 |
KawaGeo
Joined: 27 Aug 2005 Posts: 191 Location: Calif Mountains
|
Posted: Tue Feb 07, 2006 2:39 am Post subject: |
|
|
What about system.sleep()? It is supposed to free CPU while sleeping. _________________ Geo Massar
Retired Engineer |
|
| Back to top |
|
 |
fullerlee
Joined: 03 Nov 2005 Posts: 54
|
Posted: Tue Feb 07, 2006 3:42 am Post subject: |
|
|
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 |
|
 |
romero126
Joined: 24 Dec 2005 Posts: 200
|
Posted: Tue Feb 07, 2006 10:31 am Post subject: |
|
|
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 |
|
 |
Hazuki
Joined: 20 Mar 2005 Posts: 21
|
Posted: Tue Feb 07, 2006 11:51 pm Post subject: |
|
|
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 |
|
 |
the underminer
Joined: 03 Oct 2005 Posts: 124 Location: Netherlands
|
Posted: Wed Feb 08, 2006 6:56 pm Post subject: |
|
|
| 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 |
|
 |
|