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; @ EminentJonFrost, you DO NOT need spaces between your ='s, <'s, or >',s. although they do make your code easier ...
-
04-29-2006, 04:40 AM #1891QJ Gamer Green
- Registriert seit
- Dec 2005
- Ort
- Here
- Beiträge
- 2.715
- Points
- 13.310
- Level
- 75
- Downloads
- 0
- Uploads
- 0
oh, i thought it was only inside parantheses () that spaces didnt matter.@ EminentJonFrost, you DO NOT need spaces between your ='s, <'s, or >',s. although they do make your code easier to read.
[CENTER][IMG]http://img148.imageshack.us/img148/6985/siglw8.jpg[/IMG][/CENTER]
-
04-29-2006, 06:16 AM #1892QJ Gamer Silver
- Registriert seit
- Jun 2005
- Ort
- The Migrant Fleet
- Beiträge
- 908
- Points
- 9.678
- Level
- 66
- Downloads
- 0
- Uploads
- 0
I have absolutley no clue on how to do this.. but how do you make a scrolling background..
-
04-29-2006, 09:50 AM #1893words 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
Well, your problem is that the screenblit function does not return an integer/anything bresides the image to tell if its true or not after blitting. Therefore, we must make it return something. If i am not mistakin,, you want to display an image while R and the image color at the co-ordinates 3,0 are all true. well,i do not know if this is orrect, but does the luaplayer currently have the screen:blit function return anything? besides the image? But i dunno, So if the screen:blit function/prototype does return an integer, then u can do, if screen:blit(blahcX, blahY, blah)==1 then ... That is a guess, casue usually functions/prototypes return 1 for completion/a pointer to the newly created obect/memory allocated, or return NULL for an error.
Zitat von natan333
@montorb - A sidescrolling backround is nothng short of a simple backround, blitted usingthe co-ordsinates of a variabel you can change. Yet another mini-tut by SG57 lol:
Just a basic sidescrolling backround. There is a way to do this via either Lumo's tut, or using the offsets of the image to keep verlapping after off the screeen, but thats a little too advanced for new comers to understandCode:SsBg = Image.load("side _scrolling_bg.png") bgX = 0 bgY = 0 bg2X = 479 ScrollingSpeed = 5 while true do screen:blit(bgX, bgY, SsBg) screen:blit(bg2X, bgY, SsBg) bgX=bgX+ScrollingSpeed bg2X=bg2X+ScrollingSpeed if bgX<-475 then bgX=0 bg2X=479 end end
So ya, all this is doing is blitting the backround 2 times, making there X Co-ordinates move via bgX and bg2X, and once bgX is almost offscreen, itll reset back to the start/right of the screen and keep going. Also, in C, you can declare your image's dimensions, and if the dimensions are too big, they just blit the image again until it fills those dimensions, so in C i use only have to blit my image once, use only 1 variable to change/move, etc.
Hope this gives someone a basic un derstanding.
...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
-
04-29-2006, 10:58 AM #1894QJ Gamer Gold
- Registriert seit
- Mar 2006
- Ort
- LOLWUT
- Beiträge
- 2.625
- Points
- 18.627
- Level
- 86
- Downloads
- 0
- Uploads
- 0
Yes it's me again! I have had another problem. This time, I'm trying to code a game/useful tool to release, and I am having a problems. One, how would you print the result from a function? Like:
function duh()
[some code]
end
screen
rint(x, y, "duh: " .. duh(), color)
would that be it? Also, I am getting the error: script.lua:11: '=' expected near *
that line of code is:
function caf()
r*r*3.14 < line #11
end
then later I want to:
screen
rint(x, y, "caf: " .. caf(), color)
Is that the right way?
If you get the kind of useful tool that I am trying to make, please don't steal it or post it.
And no, I tryed it spacing the *'s out, but it still doesn't work.
Thanks in advance!Geändert von PSPduh (04-29-2006 um 11:04 AM Uhr)
-
04-29-2006, 11:03 AM #1895QJ Gamer Green
- Registriert seit
- Dec 2005
- Ort
- Here
- Beiträge
- 2.715
- Points
- 13.310
- Level
- 75
- Downloads
- 0
- Uploads
- 0
you have to say
Zitat von PSPduh
something = r*r*3.14 -- the mathematical sentence equals 'something'
i cant really tell what your app is by what your showing. but i think its a *a***l*t*r. (lol)[CENTER][IMG]http://img148.imageshack.us/img148/6985/siglw8.jpg[/IMG][/CENTER]
-
04-29-2006, 11:11 AM #1896QJ Gamer Gold
- Registriert seit
- Mar 2006
- Ort
- LOLWUT
- Beiträge
- 2.625
- Points
- 18.627
- Level
- 86
- Downloads
- 0
- Uploads
- 0
LOL. Sort of, but not really. How would I print that result out?
function caf()
x = r*r*3.14
end
then later...
screen
rint(x, y, "caf: " .. x, color)
If i do that then it gives me an error of: attempt to concatenate global 'x' (a nil value) On line 48. That screen
rint line is line 48.
And also, how do I make something happen when a button is held down for a certain amount of time?
Thanks again! (Once I release this, should be in a couple of days, I'll mention you, PSPmillionare, and whitehawk in the credits!)
-
04-29-2006, 11:16 AM #1897QJ Gamer Green
- Registriert seit
- Dec 2005
- Ort
- Here
- Beiträge
- 2.715
- Points
- 13.310
- Level
- 75
- Downloads
- 0
- Uploads
- 0
Zitat von PSPduh
Code:screen:print(#, #, x, color) -- no parantheses, just 'x'
thanks! (for the credit)
[CENTER][IMG]http://img148.imageshack.us/img148/6985/siglw8.jpg[/IMG][/CENTER]
-
04-29-2006, 11:28 AM #1898QJ Gamer Gold
- Registriert seit
- Mar 2006
- Ort
- LOLWUT
- Beiträge
- 2.625
- Points
- 18.627
- Level
- 86
- Downloads
- 0
- Uploads
- 0
Ughhh, another problem...I got everything to load, the background and the r = 0 part, so now the screen is green and R = 0 appears, but when I press up, down, left, or right, it still stays the same:
This is the whole code:
Now you are probably guessing what it is, but I'll never say until its done. :icon_razzCode:red = Color.new(255,0,0) yellow = Color.new(255, 255, 0) blue = Color.new(0, 0, 255) orange = Color.new(223, 88, 6) grey = Color.new(94, 97, 111) black = Color.new(0, 0, 0) white = Color.new(255, 255, 255) green = Color.new(0,255,0) r = 0 function caf() x = r*r*3.14 end while true do screen:clear(green) pad = Controls.read() oldpad = Controls.read() if pad:up() and oldpad:up() ~= pad:up() then r = r + 1 end if pad:down() and oldpad:down() ~= pad:down() then r = r + 5 end if pad:right() and oldpad:right() ~= pad:right() then r = r + 20 end if pad:left() and oldpad:left() ~= pad:left() then r = r + 10 end if r > 500 then r = 0 end if pad:cross() then caf() screen:print(50, 10, 'x', black) end screen:print(10,10,"R = " .. r, black) oldpad = pad screen.waitVblankStart() screen.flip() end
Thanks a bunch again!
-
04-29-2006, 11:38 AM #1899QJ Gamer Green
- Registriert seit
- Dec 2005
- Ort
- Here
- Beiträge
- 2.715
- Points
- 13.310
- Level
- 75
- Downloads
- 0
- Uploads
- 0
Try taking out the part that I put in bold letters.
Zitat von PSPduh
edit - oh, and you dont need these marks: ' '[CENTER][IMG]http://img148.imageshack.us/img148/6985/siglw8.jpg[/IMG][/CENTER]
-
04-29-2006, 11:52 AM #1900QJ Gamer Gold
- Registriert seit
- Mar 2006
- Ort
- LOLWUT
- Beiträge
- 2.625
- Points
- 18.627
- Level
- 86
- Downloads
- 0
- Uploads
- 0
Now that I did, it works, but it goes up WAY to fast. That was the point of that oldpad. But now that its out, it works...Anyway to make it go slower without the oldpad, or a way to work it with the oldpad? Because besides that, my app does not have any other problems. Once that's worked out, then all I have to do is some more coding.
It just printed x without the ' ' marks. That line works now; it is:
screen
rint(100, 100, 'caf = ' .. x, black)
Thanks.
-
04-29-2006, 11:55 AM #1901QJ Gamer Green
- Registriert seit
- Dec 2005
- Ort
- Here
- Beiträge
- 2.715
- Points
- 13.310
- Level
- 75
- Downloads
- 0
- Uploads
- 0
just before (in other words RIGHT ABOVE) the 'end' for each of your 'if' loops. put a "screen.waitVblankStart(5 )".
Zitat von PSPduh
put a small number in the parantheses, whichever you want. that should slow things down to how you want.[CENTER][IMG]http://img148.imageshack.us/img148/6985/siglw8.jpg[/IMG][/CENTER]
-
04-29-2006, 12:01 PM #1902QJ Gamer Green
- Registriert seit
- Dec 2005
- Ort
- Here
- Beiträge
- 2.715
- Points
- 13.310
- Level
- 75
- Downloads
- 0
- Uploads
- 0
so it would look like this:
Code:if pad:up() then r = r + 1 screen.waitVblankStart(5) end if pad:down() then r = r + 5 screen.waitVblankStart(5) end if pad:right() then r = r + 20 screen.waitVblankStart(5) end if pad:left() then r = r + 10 screen.waitVblankStart(5) end
[CENTER][IMG]http://img148.imageshack.us/img148/6985/siglw8.jpg[/IMG][/CENTER]
-
04-29-2006, 12:03 PM #1903QJ Gamer Gold
- Registriert seit
- Mar 2006
- Ort
- LOLWUT
- Beiträge
- 2.625
- Points
- 18.627
- Level
- 86
- Downloads
- 0
- Uploads
- 0
SO MUCH THANKS! And also, another problem. (I never stop having problems) This should be the last one. In my code I have:
Yet as r increases, d stays the same. If i set r as 1, d would show up as d = 2, and never go up no matter how much r goes up. THis is the final problem, (I hope!)Code:r = 0 d = r*2 function caf() x = r*r*3.14 end function cac() y = d*3.14 end
THANKS again.
-
04-29-2006, 12:08 PM #1904QJ Gamer Green
- Registriert seit
- Dec 2005
- Ort
- Here
- Beiträge
- 2.715
- Points
- 13.310
- Level
- 75
- Downloads
- 0
- Uploads
- 0
can you post all the code again, i need to see it all in one place as it is. (its confusing going back and forth between posts to see where we are)
Zitat von PSPduh
[CENTER][IMG]http://img148.imageshack.us/img148/6985/siglw8.jpg[/IMG][/CENTER]
-
04-29-2006, 12:10 PM #1905QJ Gamer Gold
- Registriert seit
- Mar 2006
- Ort
- LOLWUT
- Beiträge
- 2.625
- Points
- 18.627
- Level
- 86
- Downloads
- 0
- Uploads
- 0
Whoops, here is the whole code:
Now you can kinda see what I am trying to make.Code:red = Color.new(255,0,0) yellow = Color.new(255, 255, 0) blue = Color.new(0, 0, 255) orange = Color.new(223, 88, 6) grey = Color.new(94, 97, 111) black = Color.new(0, 0, 0) white = Color.new(255, 255, 255) green = Color.new(0,255,0) r = 0 d = r*2 function caf() x = r*r*3.14 end function cac() y = d*3.14 end while true do screen:clear(green) pad = Controls.read() if pad:up() then r = r + 1 screen.waitVblankStart(7) end if pad:down() then r = r + 5 screen.waitVblankStart(7) end if pad:right() then r = r + 20 screen.waitVblankStart(7) end if pad:left() then r = r + 10 screen.waitVblankStart(7) end if r > 500 then r = 0 end if pad:cross() then caf() screen:print(100, 100, 'Circles area = ' .. x, black) end if pad:square() then cac() screen:print(10,10,'Circles circumfence = ' .. y, black) end screen:print(10,20,"Diameter = " .. d, black) screen:print(10,10,"Radius = " .. r, black) oldpad = pad screen.waitVblankStart() screen.flip() end
-
04-29-2006, 12:24 PM #1906QJ Gamer Green
- Registriert seit
- Dec 2005
- Ort
- Here
- Beiträge
- 2.715
- Points
- 13.310
- Level
- 75
- Downloads
- 0
- Uploads
- 0
do the circle's diameter and circumference show correctly? (i cant find my PSP's usb wire so i cant test it)
Zitat von PSPduh
[CENTER][IMG]http://img148.imageshack.us/img148/6985/siglw8.jpg[/IMG][/CENTER]
-
04-29-2006, 12:33 PM #1907QJ Gamer Gold
- Registriert seit
- Mar 2006
- Ort
- LOLWUT
- Beiträge
- 2.625
- Points
- 18.627
- Level
- 86
- Downloads
- 0
- Uploads
- 0
Yeah, both of them show correctly. It's just that I would like them to d to increase as r is. It would make the app much simpler.
-
04-29-2006, 12:44 PM #1908QJ Gamer Green
- Registriert seit
- Dec 2005
- Ort
- Here
- Beiträge
- 2.715
- Points
- 13.310
- Level
- 75
- Downloads
- 0
- Uploads
- 0
I really dont know..all the coding looks fine. dont know why it doesnt work.
[CENTER][IMG]http://img148.imageshack.us/img148/6985/siglw8.jpg[/IMG][/CENTER]
-
04-29-2006, 12:50 PM #1909QJ Gamer Gold
- Registriert seit
- Mar 2006
- Ort
- LOLWUT
- Beiträge
- 2.625
- Points
- 18.627
- Level
- 86
- Downloads
- 0
- Uploads
- 0
Meh, then thanks anyway. I could work around that...Do you know how to code menus? Because if you do, then just PM me, because I could use you for this app.
-
04-29-2006, 01:19 PM #1910Developer

- Registriert seit
- Mar 2006
- Ort
- Isle of Wight
- Beiträge
- 491
- Points
- 12.360
- Level
- 72
- Downloads
- 0
- Uploads
- 0
JW, In LUA is it possible to find out the PSP Username?
-
04-29-2006, 01:23 PM #1911QJ Gamer Green
- Registriert seit
- Dec 2005
- Ort
- Here
- Beiträge
- 2.715
- Points
- 13.310
- Level
- 75
- Downloads
- 0
- Uploads
- 0
dont think so...JW, In LUA is it possible to find out the PSP Username?[CENTER][IMG]http://img148.imageshack.us/img148/6985/siglw8.jpg[/IMG][/CENTER]
-
04-29-2006, 02:10 PM #1912
1 hour ago i found out how to change the pixels of the paint =PP
when i finish i will release my 2nd verson
=PPPBequiet!!!
I'm learning cc©cc
-
04-29-2006, 02:21 PM #1913Your Fate is Grim...

- Registriert seit
- Oct 2005
- Beiträge
- 2.269
- Points
- 11.640
- Level
- 70
- Downloads
- 0
- Uploads
- 0
Zitat von PSPduh
i could help. i have just written a guide on menus. search "menus in lua" and youll see it. or i can do it for you.--------------------------------------------------------------------------------------
-
04-29-2006, 02:22 PM #1914QJ Gamer Bronze
- Registriert seit
- Oct 2005
- Ort
- Alabama
- Beiträge
- 272
- Points
- 5.975
- Level
- 50
- Downloads
- 0
- Uploads
- 0
This is because you only defined "d" in the top of your code.
Zitat von PSPduh
It isn't anywhere in your loop so it can't be updated. It's only created at the top of your code. You need to either put it somewhere in your loop to update the variable, or into a function that gets called.My lua tutorials for PSP - www.evilmana.com/tutorials
PSP Lua CodeBase - Add your own code examples to the codebase! - www.evilmana.com/tutorials/codebase/
-
04-29-2006, 02:24 PM #1915<img src="images/smilies/psp.gif" border="0" alt="" title="" cl***="inlineimg" /> <img src="images/smilies/Punk.gif" border="0" alt="" title="" cl***=&

- Registriert seit
- Jun 2005
- Ort
- Canada
- Beiträge
- 1.944
- Points
- 11.105
- Level
- 69
- Downloads
- 0
- Uploads
- 0
how would you 'refresh' a randomly chosen number,
so when i tell it to, it will randomize again,(pick a new number)
-
04-29-2006, 02:29 PM #1916QJ Gamer Bronze
- Registriert seit
- Oct 2005
- Ort
- Alabama
- Beiträge
- 272
- Points
- 5.975
- Level
- 50
- Downloads
- 0
- Uploads
- 0
Do it the same way you made the first number.
Zitat von Sousanator
If you did
to get the first number then just call that command again wherever you want a new random number.Code:number = math.random(1,10)
I would also recommend at the top of your code before your loop to "seed" your random numbers so that the same ones arent generated each time you run your app.Here's a good way to do that.
That's a good wayCode:math.randomseed(os.time))
My lua tutorials for PSP - www.evilmana.com/tutorials
PSP Lua CodeBase - Add your own code examples to the codebase! - www.evilmana.com/tutorials/codebase/
-
04-29-2006, 02:32 PM #1917<img src="images/smilies/psp.gif" border="0" alt="" title="" cl***="inlineimg" /> <img src="images/smilies/Punk.gif" border="0" alt="" title="" cl***=&

- Registriert seit
- Jun 2005
- Ort
- Canada
- Beiträge
- 1.944
- Points
- 11.105
- Level
- 69
- Downloads
- 0
- Uploads
- 0
thanks,,
and is there a way turn rotate/ or zoom in on an image,
-
04-29-2006, 02:51 PM #1918
guys. i put a qustion in a page but no one answered
what do i change so the tga picture will go to root of the memory stick or in another location ?Code:if pad:l() and pad:triangle() then screen:save("PortablePaint.tga") endBequiet!!!
I'm learning cc©cc
-
04-29-2006, 04:10 PM #1919
- Registriert seit
- Apr 2006
- Beiträge
- 17
- Points
- 4.107
- Level
- 40
- Downloads
- 0
- Uploads
- 0
screen:save("ms0:/PortablePaint.tga") to save to root of ms, or
Zitat von natan333
screen:save("ms0:/PSP/SCREENIES/PortablePaint.tga") to save in "screenies" folder within the "psp" folder on the ms.
-
04-29-2006, 04:23 PM #1920
thank you so much dragon
dragaronBequiet!!!
I'm learning cc©cc


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