Judas is right. It is already in write mode.
Printable View
Judas is right. It is already in write mode.
ok i need some help with reading and writing files, so far i have got it to write out the player's X andY values and read it but nothing else, how would u do it so that when i come out of a pause screen it will read that file and using those X and Y values???
instead off starting again.
writing:
reading:Code:file_variable = io.open(filepath)
file_variable:write("x = " .. x_coordinate)
file_variable:write("x = " .. x_coordinate)
file_variable:close()
untested but looks like it will work to meCode:dofile(filepath)
x_coordinate = x
y_coordinate = y
Having to write variables to a file is a clear sign of bad program structure. You can go on and do what FatBoy suggests, but I am warning you, it is considered bad practice. You should rather consider re-organizing your program (Use some kind of state system).Zitat:
Zitat von dan369
is there a command to shutdown or standby?
thanks in advance.
he asked how using files so i answered i dint say it was ant good, i do agree with you and to do it a better way you could set some more variables up that hold the x and y values while you change the state or, set up a second state system, which is the best way for a pause menu or inventory, so you would have something like ss1.a ss1.b ss1.c where ss.b is your game or something and set up another state system inside of that like this ss1.a ss1.b ss2.a ss2.b ss1.c where ss2.a is the game and ss2.b is the pause menu or inventory, this way any data held in the main state system is kept while entering the second level state systemZitat:
Zitat von Nielkie
i have got state's!!!
good idea but how would u store the players X and Y ???
would u use something like an btw my variable is Link.x and .y
i use this
Code:Link.x = oldx
Link.y = oldy
I dont see what that achieves.
to make it easy you can use two state tables one inside another state, so you have your main file with all of your states and stuff inZitat:
Zitat von dan369
e.g.
Code:if game_state == state.game then
-- -*-
link.x = ?
link.y = ?
state_table_for_in_game = { in_game = 1, in_pause = 2}
in_game_state = state_table_for_in_game.in_game
if in_game_state == state_table_for_in_game.in_game then
-- whatever the controlls and screen display for the game is
if pad:up() then
link.y = link.y - 1
end
-- and so on
-- this will change the link.x and link.y outside of the states -*-
if pad:start() then
in_game_state = state_table_for_in_game.in_pause
end
elseif in_game_state == state_table_for_in_game.in_pause then
-- whatever you have in your pause
if pad:start() then
in_game_state = state_table_for_in_game.in_game
end
-- when you retun to the game the x and y should stay
end
end
keeping link in his correct x and y positions after the game has been pausedZitat:
Zitat von eldiablov
ok i'm on my ps3 using an wirless keyboard!!!!
so i have states like this:
like that i've tried writing files to hold the players x and y values in my case Link.x and .yCode:state = "Game"
state = "Credits"
state = "Inventory"
i also have a statement that holds the players x and y values and stores them into an variable that holds them during collisions etc.
like this
like that it stores it's previous x and y postition useful for collisions like i said, anyway the game starts and you have to press START to load the Inventory screenCode:Link.x = oldx
Link.y = oldy
so then when i exit it will load the file which is the first level but of course it has the same starting postition so it would start from where u began!!!
I would like to know how to make the store the player's X and Y values and when you want to return from the Inventory menu and the place where u pressed start that would be where u would be placed when you exit the Inventory screen????????????????
do you loose state all the time that you need to save variables like that? I'm not sure why you would loose the interpreter state, but I dont use luaplayer, i just embed my own modified lua interpreter (no doubles/floats for speed, and other patches).
if they are global vars, you should be ok, unless your code is really bad and you clobber your global vars in functions that shouldnt be touching them... (this is why local exists!)..
you could always do state inside lua's _G[] table.
I assume your doing loadfile/loadstring/dofile etc.. but I dont see why lua player would be killing your lua_State* that you need to write out links x/y position..
something very wrong here if you need to be doing that just to show a pause screen.
also since you've limited memory (its a good practice) to not use strings if you dont really need to, you could define state modes as; even tho the global string table holds only 1 copy of a string.. waste not want not.
state_Game = 1
state_Credits = 2
state_Inventory = 3
state = state_Game
something sounds totally wrong with your code based on your above statements.... or you are correct and my knowledge of lua is wrong in its implementation in luaplayer...
as i said you need states inside states and it is not good practice to use dofiles that is why people like me created state snippets so you dont have to, and files dont have to be loaded
so now to tell you what i said before
you need to have a main state system
containing
game
credits
and inside the game state of the fist state system you need another
containing
main_game
inventory
then it will be set out something like this
- game
-- main_game
-- inventory
- credits
which is what my example before showed
then the variables for links x and y positions need to be inside the first state system under game but outside of the other state system, like so
- game
- links x and y variables
-- main_game
-- inventory
- credits
this way when you enter game you have links x and y co ordinates
when you enter main_game you also have links x and y co ordinates
and finally when you enter inventory you have links x and y co ordinates
now seen as you should only be changing links x and y co ordinates inside main_game if you swap to and from inventory the x and y co ordinates will be kept and when you actually do exit from the inventory link will be in the same position at the same point in the game
if you still dont understand it will be because of one or more of these three reasons
1. you are relatively new to coding
2. the structure of your game is just plain bad
3. you do not understand how states work properly
so i have to do some IF statements????
i am relatively new
all i would link to know is how to store Link's X and Y when START is pressed then use the numbers given to be used AS the players X and Y???
out side of all game states above while true do make two new variables,
link_x_store = 0
link_y_store = 0
then inside the state that you swap to, save them to that
so when in the game state
if pad:start() then
link_x_store = link.x
link_y_store = link.y
-- swap state to inventory state
end
-- inside inventory state
if pad:start() then
-- swap to game state
link.x = link_x_store
link.y = link_y_store
end
i understand :tup:
thanks 4 being patient with me i do understand it now
Rotating a 2d image using the gu ? Is it possible?
Check out this:
http://www.forums.evilmana.com/index.php?topic=676.0
Haven't tried it, but looks good enough.
Hi to all, I am using LUA for this homebrew. Im trying to play music on a homebrew game so I am using this command:
Music.playFile(”music.it” , true), the music file is 12.5 MB in size, so when I try to load the game calling the music the PSP shows the MS light then it stops and hangs and then turns off the PSP. How do I add some music to the homebrew?
Thanks to all in advance!
JOY - you don't think 12.5mb worth of compressed music + anyother of your resources could maybe exceed the 24mb RAM limit? (especially in Lua as it takes away atleast 3mb of RAM alone...)
Ok, well I got it to be 1.57 MB in size but still cant find the way to make the music play :(.
Ok, is there a limit in size for the music files? I still get the same hang on the PSP.
1. .wav files are better
2. it needs a low kbps rate and bit rate to work
3. if you send me a copy in .wav form ill convert it 4 u
if it still doesn't work it is because the file is still too big, or is corrupted or something else that we dont know the reason for
how do i run an eboot.pbp file??? i've used luaplayer HM but nothing happens! plz help
because of the kernel the function used has some problems loading eboot files, its trying to be fixedZitat:
Zitat von nickdagamer
oh ok! i hope it is fixed quickly!
Nielkie-san help me no need for this post :P
Short answer: You need to use "==" instead of "=". "=" sets a value, while "==" reads a value. You are also assigning your page values as both a image and a booleen.
Long answer: You need to change your coding style. Use indenting and tables, and do not repeat code. Here is what I think your code should look more like:
Code:--learn japanese
white = Color.new(255,255,255)
graphics = {}
graphics.page = {Image.load("images/lesson1/page1.png"),
Image.load("images/lesson1/page2.png"),
Image.load("images/lesson1/page3.png"),
Image.load("images/lesson1/page4.png"),
Image.load("images/lesson1/page5.png"),
Image.load("images/lesson1/page6.png"),
etc...}
graphics.menu = Image.load("images/menu.png")
graphics.lesson1menu = Image.load("images/lesson1menu.png")
graphics.lessoncomplete = Image.load("images/lessoncompletedefault.png ")
states = {}
states.page = {}
states.page.n = 1
states.menuon = true
states.lessondone = false
while true do
screen:clear(white)
pad = Controls.read()
if states.menuon then
if pad:cross() and states.menuon then
screen:clear(white)
states.menuon = false
end
elseif states.lessondone then
if pad:cross() then dofile quiz1.lua() end
if pad:circle() then dofile menu.lua() end
else
if pad:r() then
screen:clear(white)
states.page.n = states.page.n + 1
end
if pad:l() then
screen:clear(white)
states.page.n = app.states.page.n - 1
end
if states.page.n < 1 then
states.page.n = 1
elseif states.page.n > table.getn(graphics.page) then
states.page.n = table.getn(graphics.page)
end
screen:blit(0,0,graphics.page[states.page.n])
end
screen:blit(0,0,graphics.menu)
screen:blit(183,88,graphics.lesson1menu)
screen.waitVblankStart()
screen.flip()
end
thank you very much Nielkie-san! i am very glad you helped me.
I have learned more functions thanks to you! This style is much cleaner. thank you!
No problem, if you want to know more (e.g. functions, usage, etc) There are some great resources around.
For Library definitions, I greatly recommend http://lua-users.org/wiki/TutorialDirectory
Just throwing this out there - Nielkie - '==' doesn't 'read' a value, it's a comparing operator ;)
hey everyone, i am working on a lua project, and i would like to add support to play mp3 music from the memorystick, i do not know how to do this, can i get some help, also which version of lua player hm will i need
Use the latest Luaplayer HM all the Mp3 stuport functions are in the read me
okay, i dont know what function to use to load up a random song from a folder, how do i do this?Zitat:
Zitat von dan369
Zitat:
Mp3me.load()
Mp3me.play()
Mp3me.Stop()
Mp3me.eos() (EndOfStream)
Mp3me.getTime()
Mp3me.percent()
Mp3me.pause()
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
end
you lost me at think logically, i am a newb to lua and i only understood about half of thatZitat:
Zitat von SG57
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.
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 )
do you mean a scroll map?Zitat:
Zitat von dan369
yes, which only scrolls left but doesn't move any off the images Blitted (apart from the player image )
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 you
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