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; BlackShark - And you did such an awesome job on it too... Honestly, anyone in their right mind thinking a ...
-
01-29-2007, 03:59 PM #5401words are stones in my <3

- Registriert seit
- Jul 2005
- Ort
- Spokane
- Beiträge
- 5.008
- Points
- 35.274
- Level
- 100
- My Mood
-
- Downloads
- 1
- Uploads
- 0
BlackShark - And you did such an awesome job on it too... Honestly, anyone in their right mind thinking a custom firmware had been written in Lua, let alone written by a novice (shown in your sig by homebrew releases), is NOT in their right mind... And quit being so conceited, you didnt even answer his question... (hopefully you can for htat matter)
xtreme - Your looking to use a timer... In this code below, itll do as you say, and add a '.' every 1 second, after 3 periods have been added, itll reset:
Code:timer = Timer.new() timer:start() red = Color.new(255,0,0) while true do screen:clear() screen:print(208,131,"Bricking",red) if timer:time() >= 1000 and timer:time() < 2000 then screen:print(272,131,".",red) elseif timer:time() >= 2000 and timer:time() < 3000 then screen:print(272,131,"..",red) elseif timer:time() >= 3000 and timer:time() < 4000 then screen:print(272,131,"...",red) elseif timer:time() >= 4000 then timer:reset() timer:start() end screen.waitVblankStart() screen.flip() end

...at what speed must I live.. to be able to see you again?...
Projects
You can support my Open World 3D RPG for PSP by voting for it here
-
01-29-2007, 03:59 PM #5402
just remove all the while true do's, since your are not looping.
Zitat von xtreme0915
actually, since you wanted it to repeat you could just do one big 'while true do' loop around all the code, with and 'end' at the end.
-
01-29-2007, 04:08 PM #5403
edit: damn this forum RTE sucks.Code:blue = Color.new(0, 0, 255) dots = {".","..","..."} i=1 while true do if i <= 3 then screen:print(200,130,"bricking" .. dots[i], blue) i=i+1 screen.flip() screen.waitVblankStart(60) else --' code to run after message end endGeändert von eyece (01-29-2007 um 04:12 PM Uhr) Grund: Automerged Doublepost
-
01-29-2007, 04:24 PM #5404
thx, where do you guys learn all this stuff? ive seen the two tuts but other than that nothing
-
01-29-2007, 04:28 PM #5405QJ Gamer Silver

- Registriert seit
- Oct 2006
- Ort
- Pimp'en in the US F#
- Beiträge
- 1.254
- Points
- 7.278
- Level
- 56
- Downloads
- 0
- Uploads
- 0
Golly G wiz!
Zitat von SG57
release one prank bricker and the world is out to get you! :/, Plus it wasn't for QJ readers, it was to be USED by qj readers on a friend or something :/, I wasn't being conceited was I?
Well Xtreme, SG answered your Question pretty well, so give it a try,
good luck
NEWMy New BLOG!NEWThe Wentire Worls in two Sectors....When did I get dev statz?
Spoiler for my PSP homebrewReleases:Spoiler for Great Quotes:
-
01-29-2007, 04:50 PM #5406QJ Gamer Silver

- Registriert seit
- Jun 2006
- Ort
- UK
- Beiträge
- 2.326
- Points
- 10.263
- Level
- 67
- Downloads
- 0
- Uploads
- 0
Stick a texture on a quad and volia, we have a sprite.
Zitat von eldiablov
Links: http://wiki.ps2dev.org/psp:lua_playe...#3d_gu_mapping
Look at the GDI tutorial which will help you get going but not understand what you are actually doing or calling.
Also look at other source code such as yoursam's Wedge Racer.
If you really want to start getting serious in programming, I recommend looking at learning vector and matrix math which you really start to use for various tasks.[Blog] [Portfolio]
[Homebrew Illuminati - Serious Homebrew Development Forums]
[I want to make Homebrew FAQ] [How I broke into the Games Industry]
[Programming Book List] [Programming Article List]
-
01-29-2007, 04:53 PM #5407QJ Gamer Blue
- Registriert seit
- Jul 2006
- Beiträge
- 72
- Points
- 4.209
- Level
- 41
- Downloads
- 0
- Uploads
- 0
How would I access a file in "ms0:/seplugins/"?
-
01-29-2007, 05:03 PM #5408words are stones in my <3

- Registriert seit
- Jul 2005
- Ort
- Spokane
- Beiträge
- 5.008
- Points
- 35.274
- Level
- 100
- My Mood
-
- Downloads
- 1
- Uploads
- 0
You have read-only permission, meaning you cant write to a file through this file stream.Code:yourFile = io.open("ms0:/seplugins/whateverFile.extension","r")
eyece - I would have done it that way, but it's inefficient to use for loops when you can easily unwrap yourself.... Plus, it's a tad unneeded to store incremental '.'s in an array.. Just use the 'i' var to determine how many periodsyou want, no need to make an array for them...
...at what speed must I live.. to be able to see you again?...
Projects
You can support my Open World 3D RPG for PSP by voting for it here
-
01-29-2007, 05:04 PM #5409QJ Gamer Silver

- Registriert seit
- Oct 2006
- Ort
- Pimp'en in the US F#
- Beiträge
- 1.254
- Points
- 7.278
- Level
- 56
- Downloads
- 0
- Uploads
- 0
System.listDirectory("ms0 :/seplugins/")
give that a try no guarrenties but this should work.
NVM, SG beat me to the punch!NEWMy New BLOG!NEWThe Wentire Worls in two Sectors....When did I get dev statz?
Spoiler for my PSP homebrewReleases:Spoiler for Great Quotes:
-
01-29-2007, 05:09 PM #5410QJ Gamer Blue
- Registriert seit
- Jul 2006
- Beiträge
- 72
- Points
- 4.209
- Level
- 41
- Downloads
- 0
- Uploads
- 0
if I use "w" as the second arguement will I be able to write?
and on another note, what's up with people capitalizing words in their function and variable names? Just an extra keystroke to me
-
01-29-2007, 05:21 PM #5411lol

- Registriert seit
- Aug 2006
- Ort
- Whittier, CA
- Beiträge
- 5.791
- Points
- 20.859
- Level
- 91
- Downloads
- 0
- Uploads
- 0
LUA Player is case-sensitive
Yes, You will be able to write
-
01-29-2007, 05:56 PM #5412QJ Gamer Blue
- Registriert seit
- Jul 2006
- Beiträge
- 72
- Points
- 4.209
- Level
- 41
- Downloads
- 0
- Uploads
- 0
another question: can someone explain to me how to use
table System.listDirectory( [path] )
because I
m clueless how a "table of tables" works. The ps2dev wiki doesnt say how to access each element, like if I wanted the name of the first file in the directory, how would I get that? the example they gave didn;t work wit the error "attempt to call a table value"
-
01-29-2007, 06:15 PM #5413
as far as i know there is no way to repeat a string based on the value of a variable.I would have done it that way, but it's inefficient to use for loops when you can easily unwrap yourself.... Plus, it's a tad unneeded to store incremental '.'s in an array.. Just use the 'i' var to determine how many periodsyou want, no need to make an array for them...
, unless you make your own function.
-
01-29-2007, 06:15 PM #5414
ok, thx you guys, one more thing, how can i make one timer end and lead into another
-
01-29-2007, 06:24 PM #5415words are stones in my <3

- Registriert seit
- Jul 2005
- Ort
- Spokane
- Beiträge
- 5.008
- Points
- 35.274
- Level
- 100
- My Mood
-
- Downloads
- 1
- Uploads
- 0
PSPhackor -
That should print out whatever is on the root of your PSP, its size, and whether or not its a directory.Code:files = System.listDirectory("ms0:/") for i=1, table.getn(files) do screen:print(0,i*20,files[i].name,Color.new(255,255,255)) screen:print(300,i*20, "Size: " .. files[i].size,Color.new(255,0,126)) if files[i].directory then screen:print(200,i*20, "Directory",Color.new(0,255,0)) else screen:print(200,i*20, "File",Color.new(255,255,255)) end end screen.flip() while true do screen.waitVblankStart() end
xtreme - Im not sure waht you mean... But..
eyece - This is what i meant, but having only 3 values to check doesnt really have one single way to do somethingCode:timer = {Timer.new(),Timer.new()} timer[1].start() while true do if timer[1]:time() >=1000 then timer[2]:reset(timer[1]:time()) timer[2]:start() timer[1]:stop() end end
Code:green = Color.new(0, 255, 0) i=0 while true do screen:print(208,131,"Bricking" , green) if i>=1 then screen:print(272,131,".",green) end if i>=2 then screen:print(282,131,".",green) end if i>=3 then screen:print(292,131,".",green) end screen.flip() screen.waitVblankStart(60) if i<=3 then i = i + 1 else break end end while true do end -- code to run after message
Geändert von SG57 (01-29-2007 um 06:47 PM Uhr)

...at what speed must I live.. to be able to see you again?...
Projects
You can support my Open World 3D RPG for PSP by voting for it here
-
01-29-2007, 06:30 PM #5416
how can i make
timer = Timer.new()
timer:start()
while true do
screen:clear()
screen
rint(153,131,"Preparing flash0",red)
if timer:time() >= 1000 and timer:time() < 2000 then
screen
rint(280,131,".",red)
elseif timer:time() >= 2000 and timer:time() < 3000 then
screen
rint(280,131,"..",red)
elseif timer:time() >= 3000 and timer:time() < 4000 then
screen
rint(280,131,"...",red)
elseif timer:time() >= 4000 then
end
screen.waitVblankStart()
screen.flip()
lead into a new timer
-
01-29-2007, 06:41 PM #5417QJ Gamer Blue
- Registriert seit
- Jul 2006
- Beiträge
- 72
- Points
- 4.209
- Level
- 41
- Downloads
- 0
- Uploads
- 0
sg57, thank you very much. That cleared things up.
xtreme, what you need is probably to use the same timer but change
timer:time() < 2000
to math.floor(timer:time()/1000)==2
and change the others accordingly.
Maybe you should give that a try but if it doesn't work, then get someone who actually knows what they're doing (I'm a pretty new coder)
-
01-29-2007, 07:04 PM #5418words are stones in my <3

- Registriert seit
- Jul 2005
- Ort
- Spokane
- Beiträge
- 5.008
- Points
- 35.274
- Level
- 100
- My Mood
-
- Downloads
- 1
- Uploads
- 0
PSPhakkor - yup.
xtreme - If you want to use seconds, rather than miliseconds, divide timer:time() by 1000, and round up (ceiling) or down (floor). For the example i posted, i compared in miliseconds, to compare in seconds, youd do:
Code:timer = Timer.new() timer:start() while true do screen:clear() screenrint(153,131,"Pre paring flash0",red) if math.floor(timer:time()/1000) >= 1 and math.floor(timer:time()/1000) < 2 then screenrint(280,131,".", red) elseif math.floor(timer:time()/1000) >= 2 and math.floor(timer:time()/1000) < 3 then screenrint(280,131,".." ,red) elseif math.floor(timer:time()/1000) >= 3 and math.floor(timer:time()/1000) < 4 then screenrint(280,131,"... ",red) elseif math.floor(timer:time()/1000) >= 4 then end screen.waitVblankStart() screen.flip()

...at what speed must I live.. to be able to see you again?...
Projects
You can support my Open World 3D RPG for PSP by voting for it here
-
01-29-2007, 08:01 PM #5419
ok, after a few hours of learning and work here is what ii have tp produce
http://files.filefront.com//;6644819;;/
i still have a few alignment issues but im gonna work on it, what you think for my first time?
-
01-29-2007, 08:08 PM #5420lol

- Registriert seit
- Aug 2006
- Ort
- Whittier, CA
- Beiträge
- 5.791
- Points
- 20.859
- Level
- 91
- Downloads
- 0
- Uploads
- 0
LOLz, Good code!
But instead of doing this
Why not use a timer?Code:screen:clear() screen:print(150,131,"Preparing flash0",blue) screen:flip() screen.waitVblankStart(60) screen:clear() screen:print(150,131,"Preparing flash0.",blue) screen:flip() screen.waitVblankStart(60) screen:clear() screen:print(150,131,"Preparing flash0..",blue) screen:flip() screen.waitVblankStart(60) screen:clear() screen:print(150,131,"Preparing flash0...",blue) screen:flip()
-
01-29-2007, 08:43 PM #5421
because i just started today and timers confuse the sh17 out of me lol
-
01-30-2007, 12:57 AM #5422words are stones in my <3

- Registriert seit
- Jul 2005
- Ort
- Spokane
- Beiträge
- 5.008
- Points
- 35.274
- Level
- 100
- My Mood
-
- Downloads
- 1
- Uploads
- 0
xtreme - I posted an example that uses a timer, and does just waht you want. Timers arent confusing either, just think logically...
blah = Timer.new()
now... blah is a timer, and is not running right now. I want it to run... so...
blah:start()
Now... my timer is running.... I want to display the time in seconds, and if[] is pressed, stop it, if X is pressed, resume it, and finally, if O is pressed, reset it back to 0 and continue running
-= Double Post =-Code:white = Color.new(255,255,255) blah = Timer.new() blah:start() while true do screen:clear(white) pad = Controls.read() if pad:cross() then blah:start() end if pad:square() then blah:stop() end if pad:circle() then blah:reset() -- 0 by default blah:start() -- doesnt continue running once reset, so this is needed end screen:print(0,0,blah:time()) screen.waitVblankStart() screen.flip() end
Hey guys... I need a guiene (sorry spelling) pig. Ive made a particle demo in LUA, and i need someone to test it for me.
Rather than sending you the file, jsut someone copy and paste this into a file, save itas a lua script and run it...
Tell me what happens - please and thank you.Code:MAX_PARTICLES = 199 -- # of particles particle = {} -- Particle Array (Room For Particle Info) for i=0,MAX_PARTICLES do particle[i] = { life, -- Particle Life fade, -- Fade Speed x, -- X Position y, -- Y Position z, -- Z Position xi, -- X Direction yi, -- Y Direction zi -- Z Direction } end V, Angle = 0, 0 function Init() -- All Setup Goes Here for loop=0,MAX_PARTICLES do -- Initializes All Particles particle[loop].life=255 -- Give All The Particles Full Life particle[loop].fade=255/(math.random(0,100)/1000+0.05) -- Random Fade Speed V = math.random(0,25) -- Speed of the particle Angle = math.random(0,360) -- Angle of the particle particle[loop].x = 240 -- Set X position particle[loop].y = 136 -- Set Y position particle[loop].z = 0 -- Set Z position particle[loop].xi = math.sin(Angle) * V -- Set X velocity particle[loop].yi = math.cos(Angle) * V -- Set Y velocity particle[loop].zi = ((math.random(0,10)-5)/10) * V -- Set Z velocity end end function DrawScene() -- Here's Where We Do All The Drawing screen:clear() for loop=0,MAX_PARTICLES do -- Loop Through All The Particles x=particle[loop].x -- Grab Our Particle X Position y=particle[loop].y -- Grab Our Particle Y Position z=particle[loop].z -- Grab Our Particle Z Position x = 480 / 2 + x * z y = 272 / 2 + y * z -- Draw The Particle Using Our RGB Values, Fade The Particle Based On It's Life screen:fillRect(x,y,4,4,Color.new(126,126,255,particle[loop].life)) particle[loop].x=particle[loop].x+particle[loop].xi -- Move On The X Axis By X Speed particle[loop].y=particle[loop].y+particle[loop].yi -- Move On The Y Axis By Y Speed particle[loop].z=particle[loop].z+particle[loop].zi -- Move On The Z Axis By Z Speed -- Slow down the particles particle[loop].xi=particle[loop].xi*2 particle[loop].yi=particle[loop].yi*2 particle[loop].zi=particle[loop].zi*2 particle[loop].life=particle[loop].life-particle[loop].fade -- Reduce Particles Life By 'Fade' if (particle[loop].life<255/0.05) then -- If Particle Is Burned Out particle[loop].life=255 -- Give It New Life particle[loop].fade=255/((math.random(100))/10000 + 0.005) -- Random Fade Value particle[loop].x= 240 -- Center On X Axis particle[loop].y= 136 -- Center On Y Axis particle[loop].z= 0 -- Center On Z Axis V = (math.random(9)+1) Angle = math.random(360) particle[loop].xi = math.sin(Angle) * V particle[loop].yi = math.cos(Angle) * V particle[loop].zi = (math.random(10)-5) end end screen.waitVblankStart() screen.flip() end Init() while true do DrawScene() endGeändert von SG57 (01-30-2007 um 12:57 AM Uhr) Grund: Automerged Doublepost

...at what speed must I live.. to be able to see you again?...
Projects
You can support my Open World 3D RPG for PSP by voting for it here
-
01-30-2007, 03:28 AM #5423
it just displayed allot of 4x4 rectangles at 240x136, but after i changed
toCode:x=particle[loop].x -- Grab Our Particle X Position y=particle[loop].y -- Grab Our Particle Y Position z=particle[loop].z -- Grab Our Particle Z Positionit made a mess in the middle of my screen:Code:x=particle[loop].xi -- Grab Our Particle X Position y=particle[loop].yi -- Grab Our Particle Y Position z=particle[loop].zi -- Grab Our Particle Z Position
http://img408.imageshack.us/img408/3...mation1dh3.gif
Geändert von eyece (01-30-2007 um 03:34 AM Uhr) Grund: Automerged Doublepost
-
01-30-2007, 03:54 AM #5424QJ Gamer Silver

- Registriert seit
- Jun 2006
- Ort
- UK
- Beiträge
- 2.326
- Points
- 10.263
- Level
- 67
- Downloads
- 0
- Uploads
- 0
SG57, Lua arrays start from 1 not 0.
Code:for i=0,MAX_PARTICLES do
[Blog] [Portfolio]
[Homebrew Illuminati - Serious Homebrew Development Forums]
[I want to make Homebrew FAQ] [How I broke into the Games Industry]
[Programming Book List] [Programming Article List]
-
01-30-2007, 05:07 AM #5425
shouldnt matter becuase he created the table in the same way (0-199), but true.SG57, Lua arrays start from 1 not 0.
-
01-30-2007, 05:31 AM #5426QJ Gamer Silver

- Registriert seit
- Jun 2006
- Ort
- UK
- Beiträge
- 2.326
- Points
- 10.263
- Level
- 67
- Downloads
- 0
- Uploads
- 0
How are you slowing down the particles?
This doubles the speed, not slow it down.Code:-- Slow down the particles particle[loop].xi=particle[loop].xi*2 particle[loop].yi=particle[loop].yi*2 particle[loop].zi=particle[loop].zi*2
Why something so complicated, just have fade a random number between 50 and 150 and you will still get the ssame effect.Code:particle[loop].fade=255/(math.random(0,100)/1000+0.05) -- Random Fade Speed
Just check if life is below 0.Code:if (particle[loop].life<255/0.05) then -- If Particle Is Burned Out
Code:if ( particle[loop].life < 0 ) then
[Blog] [Portfolio]
[Homebrew Illuminati - Serious Homebrew Development Forums]
[I want to make Homebrew FAQ] [How I broke into the Games Industry]
[Programming Book List] [Programming Article List]
-
01-30-2007, 07:25 AM #5427words are stones in my <3

- Registriert seit
- Jul 2005
- Ort
- Spokane
- Beiträge
- 5.008
- Points
- 35.274
- Level
- 100
- My Mood
-
- Downloads
- 1
- Uploads
- 0
yaustar - I ported this from it's original OpenGL C++ form, and since the OpenGL API uses colors from 0.0 - 1.0, I needed the same % of intensity, in a 255-base form. So, 255/original_color would result in the smae effect. Now that I think about it, it SHOULD be multiply 255 by the original color... hmm... As for the comments, totally disregard them. I know it speeds it up, 2x actually, and since my PC runs the original particle demo flawlessly at 50% of the x,y, and z vector speeds (times them by .5), I could only assume the PSP would have a slower framerate. So, just to start it out, I doubled the vector speeds. The comments dont mean to much now, as Ive had to adopt quite alot of changes for this to work wthout a 3D API...
And yes, I know Lua, on default, sets the first element of an array as the '1' element. So I worked around it, as eyece pointed out...
eyece - The squares should have of faded out as they moved outward. Did they just seem to move from inside to the out?
Here - change all '255/' to '255/*' and it should fade out properly... Ill work on it more after school.
...at what speed must I live.. to be able to see you again?...
Projects
You can support my Open World 3D RPG for PSP by voting for it here
-
01-30-2007, 08:45 AM #5428QJ Gamer Silver

- Registriert seit
- Jun 2006
- Ort
- UK
- Beiträge
- 2.326
- Points
- 10.263
- Level
- 67
- Downloads
- 0
- Uploads
- 0
My question is whether particle[0] exists. I don't understand why you are making the the life part of the particle so complicated. Start at 255 (full colour) and count down by a fixed amount each frame by the .fade (which is a random number between 15 and 50). Once life is below 0 (ie can't be seen), then reset the particle.
Geändert von yaustar (01-30-2007 um 08:57 AM Uhr)
[Blog] [Portfolio]
[Homebrew Illuminati - Serious Homebrew Development Forums]
[I want to make Homebrew FAQ] [How I broke into the Games Industry]
[Programming Book List] [Programming Article List]
-
01-30-2007, 10:24 AM #5429QJ Gamer Green
- Registriert seit
- Dec 2005
- Ort
- Here
- Beiträge
- 2.715
- Points
- 13.310
- Level
- 75
- Downloads
- 0
- Uploads
- 0
like anything else my friend, we watch others (look at scripts), and practice. i've been at this...for as long as i've been a member here, (well, its a hobby really) and i have a long ways to go. at least, in my defense, i have had no prior programming history.
Zitat von xtreme0915
[CENTER][IMG]http://img148.imageshack.us/img148/6985/siglw8.jpg[/IMG][/CENTER]
-
01-30-2007, 11:32 AM #5430QJ Gamer Green
- Registriert seit
- Jul 2006
- Ort
- Middle Europe
- Beiträge
- 1.281
- Points
- 11.800
- Level
- 71
- Downloads
- 0
- Uploads
- 0
whats wrong with this? it should change colours...Code:x = 255 timer = Timer.new(0) timer:stop() function colorText() pad = Controls.read() if pad:cross() then timer:start() screen:print(100,100, "text meni farbu!", Color.new(x,x,x)) end if timer:time() > 0 < 1000 then x = x - 1 end if timer:time() > 1000 < 2000 then x = x - 1 end if timer:time() > 2000 < 3000 then x = x - 1 end if timer:time() > 3000 < 4000 then x = x - 1 end if timer:time() > 4000 < 5000 then x = x - 1 end end while true do screen:clear() colorText() screen.waitVblankStart() screen.flip() end
error:15: cannot compare boolean with number
edit. maybe this could be better??
but still same error on line 13Code:x = 255 timer = Timer.new(0) timer:stop() function colorText() pad = Controls.read() if pad:cross() then timer:start() end if timer:time() > 0 < 1000 then x = x - 1 screen:print(100,100, "text meni farbu!", Color.new(x,x,x)) end if timer:time() > 1000 < 2000 then x = x - 1 screen:print(100,100, "text meni farbu!", Color.new(x,x,x)) end if timer:time() > 2000 < 3000 then x = x - 1 screen:print(100,100, "text meni farbu!", Color.new(x,x,x)) end if timer:time() > 3000 < 4000 then x = x - 1 screen:print(100,100, "text meni farbu!", Color.new(x,x,x)) end if timer:time() > 4000 < 5000 then x = x - 1 screen:print(100,100, "text meni farbu!", Color.new(x,x,x)) end end while true do screen:clear() colorText() screen.waitVblankStart() screen.flip() end
Geändert von myschoo (01-30-2007 um 11:44 AM 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]


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