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

Discuss using and improving Lua and the Lua Player specific to the PSP.

Moderators: Shine, Insert_witty_name

Post Reply
Hazuki
Posts: 21
Joined: Sun Mar 20, 2005 2:33 am

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

Post by Hazuki »

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.
the underminer
Posts: 123
Joined: Mon Oct 03, 2005 4:25 am
Location: Netherlands

Post by the underminer »

Code: Select all

System.sleep&#40;miliseconds&#41;
It halts script execution completely, saving battery life as a bonus.

1 second would be:

Code: Select all

System.sleep&#40;1000&#41;
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:f ... cond_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: Select all

while timer&#58;time&#40;&#41; < 1000 do
pad = Controls.read&#40;&#41;
if pad&#58;cross&#40;&#41; then
score = score + 1
end
end

screen&#58;clear&#40;&#41;
something like that. I might have made some spelling mistakes in the code
Behold! The Underminer got hold of a PSP
Hazuki
Posts: 21
Joined: Sun Mar 20, 2005 2:33 am

Post by Hazuki »

thanks alot, thats a great help!

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

thanks again!
fullerlee
Posts: 54
Joined: Thu Nov 03, 2005 9:46 am

Post by fullerlee »

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: Select all

while timer&#58;time&#40;&#41; < 1000 do
	pad = Controls.read&#40;&#41;
	if pad&#58;cross&#40;&#41; then
		score = score + 1
	end
	--This will sync each loop to 1/60th of a ms
	screen.waitVblankStart&#40;&#41;
end

screen&#58;clear&#40;&#41;
KawaGeo
Posts: 191
Joined: Sat Aug 27, 2005 6:52 am
Location: Calif Mountains

Post by KawaGeo »

What about system.sleep()? It is supposed to free CPU while sleeping.
Geo Massar
Retired Engineer
fullerlee
Posts: 54
Joined: Thu Nov 03, 2005 9:46 am

Post by fullerlee »

I could be way off here, but I believe that

Code: Select all

screen.waitVblankStart&#40;&#41;
will only wait as long as it needs until the end of the next clock cycle (1/60th ms), whereas

Code: Select all

System.sleep&#40;miliseconds&#41;
will always wait the specified amount of time (and will also only resolve to a millisecond integer).

Lee
romero126
Posts: 200
Joined: Sat Dec 24, 2005 2:42 pm

Post by romero126 »

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: Select all

local timer = Timer.new&#40;&#41;
timer&#58;start&#40;&#41; // this starts the timer and also gets the seconds. &#40;A bug possibly&#41;
timertable = &#123; &#125;


function timertable_insert&#40;endtime&#41;
	// adds a table to timertable &#40;used for loop below&#41;
	table.insert&#40;timertable, &#123; timer&#58;start&#40;&#41;, endtime &#125;&#41;
end


timertable_insert&#40;10000&#41;;

while true do
	// An endless loop break fixes that
	// Keyboard input here.
	local mytime = timer&#58;start&#40;&#41;; // Gets time
	
	for k,v in timertable do
		// gets all the elements of timertable
		if &#40;timer&#58;start&#40;&#41; > &#40;v&#91;1&#93; + v&#91;2&#93;&#41;&#41; then
			timertable&#91;k&#93; = 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.
Hazuki
Posts: 21
Joined: Sun Mar 20, 2005 2:33 am

Post by Hazuki »

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!
the underminer
Posts: 123
Joined: Mon Oct 03, 2005 4:25 am
Location: Netherlands

Post by the underminer »

romero126 wrote:

Code: Select all

	local mytime = timer&#58;start&#40;&#41;; // 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
Post Reply