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; i know you can do it by putting the map in the code itself, but i don't know if you ...
-
03-10-2006, 04:23 PM #631
i know you can do it by putting the map in the code itself, but i don't know if you can read it from a file.
This is from here: http://wiki.ps2dev.org/psp:lua_player:tutorialCode:tiles = Image.load("tiles.png") map = { "mmmmmmmmmmmmmmmmmmmmmmmmmmmmmm", "mmmmmmmmmmmmmmmmmmmmmmmmmmmmmm", "mmeaaaaaaaaaaaaaaaaaaaaaaaafmm", "mmdpnnnnnnnnnnnnnnnnnnnnnnpbmm", "mmdokcccccclnkccccccccccclnbmm", "mmdojaaaaafdnbmmmmmmmmmmmdnbmm", "mmdooooooobdnbmmmmmmmmmmmdnbmm", "mmdokccclobdnbmmmmmmmmmmmdnbmm", "mmdobmmmdobdnbmmmmmmmmmmmdnbmm", "mmdobmmmdobdnjaaaaaaaaaafdnbmm", "mmdobmmmdpbdnnnnnnnnnnnnbdnbmm", "mmdobmmmhcghcccccccccclnbdnbmm", "mmdojaaaaaaaaaaaaaaaaainjinbmm", "mmdpnnnnnnnnnnnnnnnnnnnnnnpbmm", "mmhccccccccccccccccccccccccgmm", "mmmmmmmmmmmmmmmmmmmmmmmmmmmmmm", "mmmmmmmmmmmmmmmmmmmmmmmmmmmmmm" } function drawTile(tile, x, y) local tileX = math.mod(tile, 4) local tileY = math.floor(tile / 4) screen:blit(16 * x, 16 * y, tiles, 17 * tileX + 1, 17 * tileY + 1, 16, 16, false) end while true do pad = Controls.read() if pad:start() then break end screen:clear() for y = 1, 17 do line = map[y] for x = 1, 30 do tile = string.byte(line, x) - string.byte("a") drawTile(tile, x - 1, y - 1) end end screen.waitVblankStart() screen:flip() end
LUA manual:
[url]http://www.lua.org/manual/5.0/manual.html[/url]
LUA Wiki:
[url]http://wiki.ps2dev.org/psp:lua_player[/url]
-
03-10-2006, 04:27 PM #632QJ Gamer Blue
- Registriert seit
- Feb 2006
- Beiträge
- 224
- Points
- 5.036
- Level
- 45
- Downloads
- 0
- Uploads
- 0
Thanks so much!! Hope this works!
-
03-10-2006, 04:29 PM #633
Maybe this works:
where "file.extension" is obviously your file "map.txt" in this case. Im not sure if this works. Its not in the command list, but i found it in some example.Code:io.input(”file.extension”)
You can always try =)LUA manual:
[url]http://www.lua.org/manual/5.0/manual.html[/url]
LUA Wiki:
[url]http://wiki.ps2dev.org/psp:lua_player[/url]
-
03-10-2006, 05:25 PM #634QJ Gamer Bronze
- Registriert seit
- Oct 2005
- Ort
- Alabama
- Beiträge
- 272
- Points
- 5.975
- Level
- 50
- Downloads
- 0
- Uploads
- 0
i would suggest using numbers instead of the alphabet...alphabet limits you to 26 tile images, whereas numbers would be pretty much limitless
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/
-
03-10-2006, 11:25 PM #635is not posting very often

- Registriert seit
- Feb 2006
- Ort
- omnipresent
- Beiträge
- 5.162
- Points
- 33.152
- Level
- 100
- Downloads
- 0
- Uploads
- 0
Altair, i tried usin a mix of ur an my codes then JUST urs bt it dont work the cursor blits but stays still, heres the code:
-- PSPOffice
--created by Glynnder
dblue = Color.new(0, 0, 255)
red = Color.new(230, 0, 0)
pink = Color.new(255, 0 , 153)
blue = Color.new(0 , 153, 255)
orange = Color.new(255, 102, 0)
gray = Color.new(153, 153, 153)
black = Color.new(0 , 0 , 0)
white = Color.new(255, 255, 255)
screen
rint(194, 136, "loading: 0%", red)
screen.flip()
background = Image.load("images/home.png")
screen:clear()
screen
rint(194, 136, "loading 20%", pink)
screen. flip()
pstype = Image.load("images/pstypebutton.png")
screen:clear()
screen
rint(194, 136, "Loading: 40%", pink)
screen.flip()
psdraw = Image.load("images/psdrawbutton.png")
x1 = 0 ; x0 = 0 ; y1 = 0 ; y0 = 0
screen:clear()
screen
rint(194, 136, "Loading: 60%", pink)
screen.flip()
pscalc = Image.load("images/pscalcbutton.png")
screen:clear()
screen
rint(194, 136, "Loading: 80%", pink)
screen.flip()
links = Image.load("images/linksbutton.png")
screen:clear()
screen
rint(194, 136, "Loading: 90%", pink)
screen.flip()
bg2 = Image.load("images/apps.png")
cursor = Image.load("images/cursor.png")
x=200
y=100
screen:clear()
screen
rint(194, 136, "Loading: 100%", pink)
screen.flip()
screen.waitVblankStart(60 )
screen.flip()
while true do
screen:blit(0, 0, background, false)
screen:blit(30, 150, pstype, true)
screen:blit(100, 195, pscalc, true)
screen:blit(285, 195, psdraw, true)
screen:blit(355, 150, links, true)
screen:blit(x, y, cursor, 0, 0, cursor:width(), cursor:height())
time = os.time()
dateString = os.date("%c")
screen
rint(1, 1, os.date(), red)
dateFields = os.date("*t")
hour = dateFields.hour
if hour < 10 then
hour = "0" .. hour
end
min = dateFields.min
if min < 10 then
min = "0" .. min
end
sec = dateFields.sec
if sec < 10 then
sec = "0" .. sec
end
screen
rint(30, 260, "Press 'Start' to quit", blue)
screen
rint(400, 1, "Batt:", red)
if (System.powerIsLowBattery ()) == true then
screen
rint(440, 1, tostring(System.powerGetB atteryLifePercent()) .. "%", blue)
else screen
rint(450, 1, tostring(System.powerGetB atteryLifePercent()) .. "%", red)
end
if (System.powerIsBatteryCha rging()) == true then
screen
rint(457, 1, "+", red) end
screen
rint(300, 260, "'Select' = Screenshot", white)
pad = Controls.read()
screen.flip()
if pad:start() then
break
end
if pad:select() then
screen:save("screenshot.j pg")
dx = pad:analogX()
if math.abs(dx) > 32 then
x = x + dx / 32
end
dy = pad:analogY()
if math.abs(dy) > 32 then
y = y + dy / 32
end
screen.waitVblankStart()
screen:flip()
end
end
-
03-10-2006, 11:28 PM #636QJ Gamer Gold
- Registriert seit
- Mar 2006
- Ort
- Somewhere
- Beiträge
- 3.629
- Points
- 18.874
- Level
- 87
- Downloads
- 0
- Uploads
- 0
ok... im a noob to this im trying to learn basic coding but i can teven get my hello world thing i made to work idk what i did rong. i follwed the tutorial and made it on a notepad in the luaplayer folder and renamed it but when i start up lua its not there. anyone have sugestions?
Veteran
PSN Name: Eldiabl1o
Zitat von gmansixfo
-
03-11-2006, 04:03 AM #637QJ Gamer Blue
- Registriert seit
- Feb 2006
- Beiträge
- 224
- Points
- 5.036
- Level
- 45
- Downloads
- 0
- Uploads
- 0
it has to be in applications folder inside lua player.. or if you just press X then it will go up one folder
-
03-11-2006, 04:07 AM #638QJ Gamer Blue
- Registriert seit
- Feb 2006
- Beiträge
- 224
- Points
- 5.036
- Level
- 45
- Downloads
- 0
- Uploads
- 0
Oh yeah, good idea, thanks.
Zitat von PSPMillionaire
-
03-11-2006, 07:24 AM #639QJ Gamer Gold
- Registriert seit
- Mar 2006
- Ort
- Somewhere
- Beiträge
- 3.629
- Points
- 18.874
- Level
- 87
- Downloads
- 0
- Uploads
- 0
i have the hello world inside the aplications folder but when i start lua player it says its nto there. and i named it scipt.lua but it says that its a text file. is that right? or do i need to make it say lua file? if so how do i do that cuz renaming it didnt help for me
Veteran
PSN Name: Eldiabl1o
Zitat von gmansixfo
-
03-11-2006, 08:35 AM #640SHOOP DA WHOOP

- Registriert seit
- Aug 2005
- Ort
- Wii forums
- Beiträge
- 7.407
- Points
- 12.310
- Level
- 72
- Downloads
- 0
- Uploads
- 0
try naming it index.lua
it should work then
-
03-11-2006, 08:37 AM #641SHOOP DA WHOOP

- Registriert seit
- Aug 2005
- Ort
- Wii forums
- Beiträge
- 7.407
- Points
- 12.310
- Level
- 72
- Downloads
- 0
- Uploads
- 0
ALSO make sure that windows isnt hiding the .txt file...
go to control panel > folder options > look for the thing that says "hide extensions for known file types" then uncheck that....
if you look at your program after you do that it might say index.lua.txt (the .txt was hidden before) then just take off the .txt part and it should work
-
03-11-2006, 09:05 AM #642QJ Gamer Green
- Registriert seit
- Oct 2005
- Ort
- OMG where AM I!?!?!?!?
- Beiträge
- 820
- Points
- 6.374
- Level
- 52
- Downloads
- 0
- Uploads
- 0
Hey i have a question. Is it possible to put a function inside a table and call for that function without the screen
rint() option?
[SPOILER="For PSP History"]1.50 > 1.52 > 2.00 > 1.5 > 1.5 (POC CF) > 1.5 (Harleyg) > 1.5 (Casual) > 3.03 OE-A > 3.03 OE-C[/SPOILER]
Check it out: [URL="http://youtube.com/watch?v=xNVPKM07TWs&mode=related&search="]Pen Spinning[/URL]
-
03-11-2006, 09:53 AM #643Quality Haxing Since 1991
- Registriert seit
- Oct 2005
- Ort
- Pennsylvania, USA Fi
- Beiträge
- 6.206
- Points
- 29.255
- Level
- 99
- Downloads
- 0
- Uploads
- 0
Well I have two questions.
First, I am trying to make an image go from the top to the bottom of the screen. That's all. I haven't been able to do it though because I haven't found a way yet. I triedandCode:while image[1].y < 272 do image[1].y=image[1].y + 2 end
but neither of those really did anything. I tried a bunch of other ways, but they were pretty much duds too.Code:if image[1].y < 272 then image[1].y=image[1].y + 2
(image[1] is part of an array where i have x and y coordinates stored, and for this one I have y=10 so that the image starts at 10. That could be part of the problem but I just can't figure it out.)
Second, I cannot figure out for the life of me how to have a dynamically changing score. Everytime I try to get the new score, I have to clear the screen and display it, but I don't want to clear the screen of the other images on there. Could someone show me a way to do this?
Thanks in advance, you guys are great.Geändert von PSPHax0r9 (03-11-2006 um 10:02 AM Uhr)
Zitat von Noriko
-
03-11-2006, 10:10 AM #644QJ Gamer Blue
- Registriert seit
- Feb 2006
- Beiträge
- 224
- Points
- 5.036
- Level
- 45
- Downloads
- 0
- Uploads
- 0
I would make a function and do something like
droptimer = 0
x = 10
y = 10
function movedown()
droptimer = droptimer + 1
if droptimer>=100 and droptimer<=200 then
y = y + 2
droptimer = 0
end
end
while true do
screen:clear()
movedown()
then do all the loading of images and stuff...
but it depends on how fast you want it to drop...
if you wanted it to drop really fast you would change the if droptimer>=100 and droptimer<=200 to lower numbers...
-
03-11-2006, 10:16 AM #645Quality Haxing Since 1991
- Registriert seit
- Oct 2005
- Ort
- Pennsylvania, USA Fi
- Beiträge
- 6.206
- Points
- 29.255
- Level
- 99
- Downloads
- 0
- Uploads
- 0
OK thanx I will try that.
Also, do you know anything about my second question? I want it to display the new number every time the score changes, but I don't want to clear the whole screen.
Thanx :icon_smil
Zitat von Noriko
-
03-11-2006, 10:31 AM #646Developer

- Registriert seit
- Oct 2005
- Ort
- Boston, MA
- Beiträge
- 1.389
- Points
- 14.378
- Level
- 77
- Downloads
- 0
- Uploads
- 0
if you blit all the stuff on your screen in the main loop, why not clear the screen as the first command in the main loop and let it blit over again, each loop?, dunno if it will be a slowdown though.
Zitat von PSPHax0r9
-
03-11-2006, 11:44 AM #647QJ Gamer Blue
- Registriert seit
- Feb 2006
- Beiträge
- 224
- Points
- 5.036
- Level
- 45
- Downloads
- 0
- Uploads
- 0
score = 0
Zitat von PSPHax0r9
if *something happens* then
score = score + 10 --or whatever...
end
screen:blit(0, 0, background)
screen
rint(10, 10, string.format("Score: ".. score), white)
screen.flip()
screen.waitVblankStart()
end
I only used background as an example but that is the end of the code where you would blit every image..Geändert von lui2603 (03-11-2006 um 03:47 PM Uhr)
-
03-11-2006, 12:21 PM #648
@PSPHax0r9
Your own code SHOULD work, both. You do refresh the screen every loop?
For the timer, you dont have to clear the screen everytime. Just blitting over the old one should suffice. That is if you blit a background over everything. If you don't have something that blits over the entire screen, then i think you have to clear the screen before you blit/print something new, or you will see a "trail".
@InhumanElmo:
I dont know if you can put a function in a table, but why don't you just try and see for your self? I guess it should be able.Geändert von Altair (03-11-2006 um 12:29 PM Uhr)
LUA manual:
[url]http://www.lua.org/manual/5.0/manual.html[/url]
LUA Wiki:
[url]http://wiki.ps2dev.org/psp:lua_player[/url]
-
03-11-2006, 12:27 PM #649
@Glynnder-PSPro
Do the other buttons work?
Also you dont need more then one screen.flip() in the while loop. The first one can go.LUA manual:
[url]http://www.lua.org/manual/5.0/manual.html[/url]
LUA Wiki:
[url]http://wiki.ps2dev.org/psp:lua_player[/url]
-
03-11-2006, 01:03 PM #650Quality Haxing Since 1991
- Registriert seit
- Oct 2005
- Ort
- Pennsylvania, USA Fi
- Beiträge
- 6.206
- Points
- 29.255
- Level
- 99
- Downloads
- 0
- Uploads
- 0
Well I don't have a background image yet, I was just trying to do this simple minigame, and I wanted to do all the hard stuff like image movement and everything first. Is it OK if I PM you my code so far? It's sort of messy and I was wondering if you could give me some tips on it or edit things to work better. Thank you.
Zitat von Altair
Zitat von Noriko
-
03-11-2006, 01:05 PM #651Is in your zone.

- Registriert seit
- Oct 2005
- Ort
- Jacksonville, FL
- Beiträge
- 3.429
- Points
- 24.342
- Level
- 94
- Downloads
- 0
- Uploads
- 0
What is the command prompt (or whatever it is) That displays the error with the code in luaplayerwindows?

--XBL Gamertag: PhenoM904--
-
03-11-2006, 01:10 PM #652Tha Sigerator

- Registriert seit
- Jul 2005
- Ort
- New Orleans, LA
- Beiträge
- 4.047
- Points
- 26.703
- Level
- 97
- Downloads
- 0
- Uploads
- 0
theres a prompt tthat does that?
jus go through your code carfully till u find what's wrong with it. usually a small misttake- - - - Somewhere Lurking in THA SHADOWS - - - -
-
03-11-2006, 01:15 PM #653Quality Haxing Since 1991
- Registriert seit
- Oct 2005
- Ort
- Pennsylvania, USA Fi
- Beiträge
- 6.206
- Points
- 29.255
- Level
- 99
- Downloads
- 0
- Uploads
- 0
Well I know that it displays the error very quickly in the main window if the game doesn't start up. I've learned to read it even though it's fast. It tells you the line of your error and what it is and everything. It displays for a split second longer if click and hold somewher in the screen, too. There's probably an easier way to do it, but that's how I do it.
Zitat von Noriko
-
03-11-2006, 01:17 PM #654Is in your zone.

- Registriert seit
- Oct 2005
- Ort
- Jacksonville, FL
- Beiträge
- 3.429
- Points
- 24.342
- Level
- 94
- Downloads
- 0
- Uploads
- 0
Yeah, theres a prompt that freezes the screen so you can read it, I remember there ws a thread somewhere here but I cant remember which it was. Im gonna look around though. But how the hell do you read it? Its impossible for me.
Hint: If anyone has played the flash game Stick Avalanche thats what I am making.
--XBL Gamertag: PhenoM904--
-
03-11-2006, 01:20 PM #655Quality Haxing Since 1991
- Registriert seit
- Oct 2005
- Ort
- Pennsylvania, USA Fi
- Beiträge
- 6.206
- Points
- 29.255
- Level
- 99
- Downloads
- 0
- Uploads
- 0
I have the eyes of a ninja...
P.S. I just checked in your other thread and the cmd is pause.
Zitat von Noriko
-
03-11-2006, 01:30 PM #656Is in your zone.

- Registriert seit
- Oct 2005
- Ort
- Jacksonville, FL
- Beiträge
- 3.429
- Points
- 24.342
- Level
- 94
- Downloads
- 0
- Uploads
- 0
Okay, heres my code Im testing and i get Unexpected symbol near "=" heres the code
Code:spike = Image.load = ("spike.png") background = Image.load = ("background.png") while true do screen:blit(0, 0, background) screen:flip() screen:blit(130, 130, spike) screen:flip() screen:waitVblankStart() end
--XBL Gamertag: PhenoM904--
-
03-11-2006, 01:34 PM #657Is in your zone.

- Registriert seit
- Oct 2005
- Ort
- Jacksonville, FL
- Beiträge
- 3.429
- Points
- 24.342
- Level
- 94
- Downloads
- 0
- Uploads
- 0
Wow im stupid nevermind
But I test the images loading and I get this
God Photobucket is gay... But you can see the image is distorted...(Its supposed to be a black triangle) and the background it supposed to be white.Geändert von Mast3r_Shak3 (03-11-2006 um 01:42 PM Uhr)

--XBL Gamertag: PhenoM904--
-
03-11-2006, 01:34 PM #658Tha Sigerator

- Registriert seit
- Jul 2005
- Ort
- New Orleans, LA
- Beiträge
- 4.047
- Points
- 26.703
- Level
- 97
- Downloads
- 0
- Uploads
- 0
edit: dammit u gotta stop doin that
- - - - Somewhere Lurking in THA SHADOWS - - - -
-
03-11-2006, 03:52 PM #659QJ Gamer Blue
- Registriert seit
- Feb 2006
- Beiträge
- 224
- Points
- 5.036
- Level
- 45
- Downloads
- 0
- Uploads
- 0
To see the error you just have to open it in cmd thingy...
Press start, run then type cmd and run it, in cmd it should automatically point to the directory c:/documents and settings/*your user name*/
when they shows up, if you have your luaplayer windows in a folder on your desktop you just type:
cd desktop/*name of folder*/
and enter
then type:
test.cmd
and it will show you the error and won't dissapear
-
03-11-2006, 04:50 PM #660QJ Gamer Blue
- Registriert seit
- Feb 2006
- Beiträge
- 224
- Points
- 5.036
- Level
- 45
- Downloads
- 0
- Uploads
- 0
does anyone know what commands are to activate and use IR???


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