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; Use the latest Luaplayer HM all the Mp3 stuport functions are in the read me...
-
04-03-2008, 02:09 PM #8431Lua guy
- Registriert seit
- Jan 2008
- Ort
- Wales, cardiff
- Beiträge
- 1.442
- Points
- 11.690
- Level
- 71
- My Mood
-
- Downloads
- 0
- Uploads
- 0
Use the latest Luaplayer HM all the Mp3 stuport functions are in the read me
-
04-03-2008, 06:10 PM #8432
okay, i dont know what function to use to load up a random song from a folder, how do i do this?
Zitat von dan369
Mp3me.load()
Mp3me.play()
Mp3me.Stop()
Mp3me.eos() (EndOfStream)
Mp3me.getTime()
Mp3me.percent()
Mp3me.pause()
-
04-03-2008, 06:16 PM #8433words 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
ifiwere1337 - Think logically about it. You'd get the folder as a directory list, parse all the entries in the list containing a .mp3 extension and add that filepath (or element #) to another array and randomly select from that which to play. Sub-folder searching would require recursive scanning of the root folder you pass and that's a different story.
if your still stuck:
Untested but should work - the method i'm using is removing the non-MP3s from the directory list.Code:-- This will stop any currently playing song -- Load and play a random one from PSP/MUSIC/ folder function PlayRandomSong() -- get the files and folders in our music folder mp3List = System.listDirectory("ms0:/PSP/MUSIC/") -- loop through all the files/folders in our table for i = 1, table.getn(mp3List) do if string.sub(mp3List[i].name, -4) ~= ".mp3" and -- if the extension of the file name doesn't end with .mp3 string.sub(mp3List[i].name, -4) ~= ".Mp3" and -- and .Mp3 string.sub(mp3List[i].name, -4) ~= ".mP3" and -- and .mP3 string.sub(mp3List[i].name, -4) ~= ".MP3" then -- and .MP3 table.remove(mp3List, i) -- the filename clearly isn't properly named MP3 file so remove it i = 0 -- reset the searching variable since our table now has changed -- 0 because for loops, atleast in C, default to increase the iterator at the end of the loop -- try i = i - 1 instead, should produce the same result (if table.remove works like i think it does) end end -- if there is atleast 1 filename in the folder if table.getn(mp3List) > 0 then -- stop the currently playng mp3 if any Mp3me.Stop() -- now just load a random filename that hasn't been removed Mp3me.load( mp3List [ math.random (1, table.getn() ) ].name ) Mp3me.play() -- ... end endGeändert von SG57 (04-03-2008 um 06:41 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
-
04-03-2008, 06:27 PM #8434
you lost me at think logically, i am a newb to lua and i only understood about half of that
Zitat von SG57
-
04-03-2008, 06:43 PM #8435words 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 if you're still stuck take a look at what I made real quick. It's untested as I don't want to download luaplayer etc. etc.

...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-04-2008, 08:52 AM #8436Lua guy
- Registriert seit
- Jan 2008
- Ort
- Wales, cardiff
- Beiträge
- 1.442
- Points
- 11.690
- Level
- 71
- My Mood
-
- Downloads
- 0
- Uploads
- 0
i need help!!!
I what to scroll ONE image right, but without moving anything blitted apart from the player image.
So when the player's X is more than 260 i will scroll right but not moving anything Blitted (apart from the player.img)
and also keep Blitting that Image, so if the player's X is 480 u would still see the image scrolling right, BUT won't see anything moving that's been Blitted (apart from the player image )
-
04-04-2008, 09:14 AM #8437NetGameOrb Maker

- Registriert seit
- Jan 2008
- Ort
- New York
- Beiträge
- 683
- Points
- 6.138
- Level
- 50
- My Mood
-
- Downloads
- 2
- Uploads
- 0
do you mean a scroll map?
Zitat von dan369
GameLive name changed to NetGameOrb, Project is now online in Beta stage. Everyone encourage to register so they get news about the project and ability to play the games with NetGameOrb Support online. More info on site.
Stats Blog:http://netgameorb.blogspot.com/
Website:http://www.netgameorb.com/
-
04-04-2008, 09:21 AM #8438Lua guy
- Registriert seit
- Jan 2008
- Ort
- Wales, cardiff
- Beiträge
- 1.442
- Points
- 11.690
- Level
- 71
- My Mood
-
- Downloads
- 0
- Uploads
- 0
yes, which only scrolls left but doesn't move any off the images Blitted (apart from the player image )
-
04-04-2008, 09:28 AM #8439NetGameOrb Maker

- Registriert seit
- Jan 2008
- Ort
- New York
- Beiträge
- 683
- Points
- 6.138
- Level
- 50
- My Mood
-
- Downloads
- 2
- Uploads
- 0
than maybe you can clear the screen when the player reache the 260 x coordinate and then blit the map again with the new coordinate
for example
a = grass
b = bush
p = player
"
aaaaaaaaa
aabaapaaa
aaaaaaaaa
'
when map look like this
aaaaaaaaa
aabapaaaa
aaaaaaaaa
and player press left then map schouold look like this
'
aaaaaaaaa
aaabpaaaa
aaaaaaaaa
so really you are moving the map insted of the player
sorry if i am not clear if you wait a moment i try to make a code for youGameLive name changed to NetGameOrb, Project is now online in Beta stage. Everyone encourage to register so they get news about the project and ability to play the games with NetGameOrb Support online. More info on site.
Stats Blog:http://netgameorb.blogspot.com/
Website:http://www.netgameorb.com/
-
04-04-2008, 09:33 AM #8440QJ Gamer Green
- Registriert seit
- Jan 2008
- Beiträge
- 612
- Points
- 3.721
- Level
- 38
- Downloads
- 0
- Uploads
- 0
fixed it up a bit, changed how it does the loop to avoid not knowing how lua does it compared to C etcCode:-- This will stop any currently playing song -- Load and play a random one from PSP/MUSIC/ folder function PlayRandomSong() -- get the files and folders in our music folder mp3List = System.listDirectory("ms0:/PSP/MUSIC/") --remove all non-mp3 items in the folder i = 1 while i <= table.getn(mp3List) do if string.lower(string.sub(mp3List[i].name, -4)) ~= ".mp3" then table.remove(mp3List, i) else i = i + 1 end end if table.getn(mp3List) > 0 then --if there is atleast 1 song to play Mp3me.Stop() Mp3me.load(mp3List[math.random(1,table.getn(mp3List))].name) --load a random mp3 from the list Mp3me.play() end end
-
04-04-2008, 09:48 AM #8441NetGameOrb Maker

- Registriert seit
- Jan 2008
- Ort
- New York
- Beiträge
- 683
- Points
- 6.138
- Level
- 50
- My Mood
-
- Downloads
- 2
- Uploads
- 0
this is just a example of a scrolling map so it may have some error due to the fact i was doing it in a rush so modifi it as you like//here load your map make sure it larger than 272 in length
map = Image.load("map.png")
//here you load player
player = Image.load("player.png")
//here you have player x and y value
Px=220
Py=250
//here you have the current postion in the map
mapx = 480
mapy = 272
while true do
pad = Controls.read()
//here we clean up the screen so we could prepare to blit the new map postion
screen:clear()
//here we blit the map from were we are in the map picture
screen:blit(0, 0, map, [maplx, maply, 480, 272], [alpha = true])
//here we blit the player
screen:blit(px, py, player)
//here we check if the player x postion is greated than 270 so if it is then we will change the new position of the map
if pad:left() and Px > 270 then
mapx = mapx + 1
end
endGameLive name changed to NetGameOrb, Project is now online in Beta stage. Everyone encourage to register so they get news about the project and ability to play the games with NetGameOrb Support online. More info on site.
Stats Blog:http://netgameorb.blogspot.com/
Website:http://www.netgameorb.com/
-
04-04-2008, 10:46 AM #8442
thanks for this, it is greatly appreciated, ill mention both you and sg in my credits!!!:Jump:
Zitat von TurtlesPwn
--edit--
im having trouble, i am using a lua script from bumper harvest, and i add this under the functions, and it does not seem to load, i have tried adding it to many different places, but no luck, if you have a fix for this it would be niceGeändert von ifiwere1337 (04-04-2008 um 11:08 AM Uhr)
My Projects
[URL="http://www.megaupload.com/?d=Q860B1VV"]BUMPER HARVEST MOD - PEGGLE DELUXE BETA 1[/URL]
working on Zuno, an uno like game
[QUOTE=FreePlay]It's a picture of a monkey. There, I spoiled it for you.[/QUOTE]
-
04-04-2008, 11:57 AM #8443Developer and Tutor.
- Registriert seit
- Jul 2007
- Ort
- Widnes, England
- Beiträge
- 1.649
- Points
- 8.736
- Level
- 62
- My Mood
-
- Downloads
- 0
- Uploads
- 0
i think that where it says the math.random bit you need it in a math.floor so that is is an actual number with no decimals
Zitat von ifiwere1337
edit:
i just tested it and that isn't the problem, make sure its above while true do and use the correct name with the same case for all of the words
e.g. if it is Word dont use word------ FaT3oYCG -----
AKA Craig, call me what you want to It's your preference.
My Website: http://www.modern-gamer.co.uk/
Currently working on:
(0) MediaGrab
(0) PGE Gears Of War - On hold (Very large project).
(0) PS???? -On Hold A tactical 2d side scrolling game involving AI and online multiplayer features. - Tile engine nearley finished (1 bug to fix).
-
04-04-2008, 12:09 PM #8444
im not sure what you mean, could you elaborate?
Zitat von FaT3oYCG
My Projects
[URL="http://www.megaupload.com/?d=Q860B1VV"]BUMPER HARVEST MOD - PEGGLE DELUXE BETA 1[/URL]
working on Zuno, an uno like game
[QUOTE=FreePlay]It's a picture of a monkey. There, I spoiled it for you.[/QUOTE]
-
04-04-2008, 01:34 PM #8445Developer and Tutor.
- Registriert seit
- Jul 2007
- Ort
- Widnes, England
- Beiträge
- 1.649
- Points
- 8.736
- Level
- 62
- My Mood
-
- Downloads
- 0
- Uploads
- 0
it wasnt what i origionally thought but make sure it is like this when you use it
Zitat von ifiwere1337
PlayRandomSong()
and not like this
playrandomsong()------ FaT3oYCG -----
AKA Craig, call me what you want to It's your preference.
My Website: http://www.modern-gamer.co.uk/
Currently working on:
(0) MediaGrab
(0) PGE Gears Of War - On hold (Very large project).
(0) PS???? -On Hold A tactical 2d side scrolling game involving AI and online multiplayer features. - Tile engine nearley finished (1 bug to fix).
-
04-04-2008, 04:23 PM #8446words 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
I didn't know Lua had a tolower or toupper string member. Neat :) And ya thx for the fix up, I expected no less ;)
Zitat von TurtlesPwn

...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-06-2008, 04:03 PM #8447
okay i changed playrandomsong() to PlayRandomSong(), and it still wont work, i dont know why, but it is getting really annoying trying to fix this
Zitat von FaT3oYCG
My Projects
[URL="http://www.megaupload.com/?d=Q860B1VV"]BUMPER HARVEST MOD - PEGGLE DELUXE BETA 1[/URL]
working on Zuno, an uno like game
[QUOTE=FreePlay]It's a picture of a monkey. There, I spoiled it for you.[/QUOTE]
-
04-06-2008, 04:10 PM #8448words 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
ifiwere1337 - Post your usage, and keep in mind how bumper harvest's program flow is (it might have nested inifinite loops, etc. keeping it from running)

...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-06-2008, 04:33 PM #8449
kk just a minute
Zitat von SG57
code removed due to lengthGeändert von ifiwere1337 (04-06-2008 um 05:34 PM Uhr)
My Projects
[URL="http://www.megaupload.com/?d=Q860B1VV"]BUMPER HARVEST MOD - PEGGLE DELUXE BETA 1[/URL]
working on Zuno, an uno like game
[QUOTE=FreePlay]It's a picture of a monkey. There, I spoiled it for you.[/QUOTE]
-
04-06-2008, 05:18 PM #8450words 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
ifiwere1337... I didn't say post the entire source, I said post the usage of it. And strangely enough you aren't even using it. I highly suggest you learn a little more before you do stuff like this, it makes alot of people's head aches less frequent when that happens. I made you a function, you have yet to actually call it / use it.

...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-06-2008, 05:27 PM #8451QJ Gamer Bronze

- Registriert seit
- Jul 2006
- Beiträge
- 550
- Points
- 5.381
- Level
- 47
- Downloads
- 1
- Uploads
- 0
Umm, you need to call it from somewhere...
Zitat von ifiwere1337
EDIT: Beaten.
-
04-06-2008, 05:32 PM #8452
ah damnit, lol sorry a newb mistake, ill try and fix it, sorry for the waste of time, im only learning
Zitat von SG57
---edit---
now i have a prob, i added a line to call the function PlayRandonSong() and all i get is an error on lua player, what i am wondering is if i need to put anything in the parentheses or not?Geändert von ifiwere1337 (04-06-2008 um 06:01 PM Uhr)
My Projects
[URL="http://www.megaupload.com/?d=Q860B1VV"]BUMPER HARVEST MOD - PEGGLE DELUXE BETA 1[/URL]
working on Zuno, an uno like game
[QUOTE=FreePlay]It's a picture of a monkey. There, I spoiled it for you.[/QUOTE]
-
04-06-2008, 06:15 PM #8453words 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
Paste the error... seems like common sense when something goes wrong doesn't it? ;)

...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-07-2008, 11:06 AM #8454
oops sorry on the lua player screen it says this
Zitat von SG57
Error: index.lua:24 : attempt to call field 'stop' (a nil value)My Projects
[URL="http://www.megaupload.com/?d=Q860B1VV"]BUMPER HARVEST MOD - PEGGLE DELUXE BETA 1[/URL]
working on Zuno, an uno like game
[QUOTE=FreePlay]It's a picture of a monkey. There, I spoiled it for you.[/QUOTE]
-
04-07-2008, 11:10 AM #8455
- Registriert seit
- Apr 2008
- Beiträge
- 5
- Points
- 2.588
- Level
- 30
- Downloads
- 0
- Uploads
- 0
i think it is the way you put it like when you put "stop" is should be "Stop" or something.
Zitat von ifiwere1337
but i dont know because im new to this. i only started learning today but i had to register to see these threads, which are very helpful by the way thank you qj'ers.
have fun
wolfy
-
04-07-2008, 11:15 AM #8456
never thought to check that, i seen stop, but didnt think Stop
Zitat von Lone_Wolf_O_o
--edit--
no it is Stop, but i took the media engine off and ill try that
--edit--
nope its not the media engine thats stopping itMy Projects
[URL="http://www.megaupload.com/?d=Q860B1VV"]BUMPER HARVEST MOD - PEGGLE DELUXE BETA 1[/URL]
working on Zuno, an uno like game
[QUOTE=FreePlay]It's a picture of a monkey. There, I spoiled it for you.[/QUOTE]
-
04-07-2008, 11:21 AM #8457
- Registriert seit
- Apr 2008
- Beiträge
- 5
- Points
- 2.588
- Level
- 30
- Downloads
- 0
- Uploads
- 0
hmm ok then maybe it is this bit
maybe you cant stop it before loading or playing itCode:Mp3me.Stop() Mp3me.load(mp3List[math.random(1,table.getn(mp3List))].name) --load a random mp3 from the list Mp3me.play()
-
04-07-2008, 11:30 AM #8458
okay that got rid of that error, but now i have a new error
Zitat von Lone_Wolf_O_o
the problem is that the player thinks that the song is in the game folder, and i want it to recognize it in the PSP/MUSIC folder.Error: index.lua : 25: can't open sound file ms0/PSP/GAME/Bumper Harvest-pegglemod/Led Zepplin - Led Zeppelin - Rock and Roll.mp3.
any help?My Projects
[URL="http://www.megaupload.com/?d=Q860B1VV"]BUMPER HARVEST MOD - PEGGLE DELUXE BETA 1[/URL]
working on Zuno, an uno like game
[QUOTE=FreePlay]It's a picture of a monkey. There, I spoiled it for you.[/QUOTE]
-
04-07-2008, 11:41 AM #8459
- Registriert seit
- Apr 2008
- Beiträge
- 5
- Points
- 2.588
- Level
- 30
- Downloads
- 0
- Uploads
- 0
i think that should beCode:mp3List = System.listDirectory("ms0:/PSP/MUSIC/")
because i have just looked at a file browser example and that is what it was likeCode:System.currentDirectory("ms0:/PSP/MUSIC/") mp3List = System.listDirectory()
-= Double Post =-
wait i just looked at another one and that is fine so i dont think its that
but it says its a problem loading.
wouldn't that just load the song file from the current directory ?
couldn't you just add a bit on
Code:Mp3me.load(ms0:/PSP/MUSIC/mp3List[math.random(1,table.getn(mp3List))].name) --load a random mp3 from the list
Geändert von Lone_Wolf_O_o (04-07-2008 um 12:02 PM Uhr) Grund: Automerged Doublepost
-
04-07-2008, 12:16 PM #8460
OMG NOW IT WORKS, the only problem is that it is choppy, but the framerate of the game stays the same
Zitat von Lone_Wolf_O_o
--edit--
thanks all who helped, i will add you to my credits
also if anyone can help me with a problem, i want to load a config file, called config.cfg
say i want redballscore=20
i put
config 1
12
config 2
123
config ...
1337
redballscore
20
in the config file, and under redball score i put redballscore=config line8
or something similar, is this possible with lua?Geändert von ifiwere1337 (04-07-2008 um 12:29 PM Uhr)
My Projects
[URL="http://www.megaupload.com/?d=Q860B1VV"]BUMPER HARVEST MOD - PEGGLE DELUXE BETA 1[/URL]
working on Zuno, an uno like game
[QUOTE=FreePlay]It's a picture of a monkey. There, I spoiled it for you.[/QUOTE]


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