Well I dont see it whats your error or prob anyways?Zitat:
Zitat von Urameshi
Printable View
Well I dont see it whats your error or prob anyways?Zitat:
Zitat von Urameshi
well the game runs, but when Urameshi chases the player, he shows no animation what so ever, but i want him to show animation
Zitat:
Zitat von myschoo
hmm can u tell me what did u repair?...
i dont have a psp right now:(
i gave my psp to my bro as a graduation gift:)
only 2 things:
sometimes you used Red and sometimes red in your menu so i changed it all to "red" and then you were flashing font to flash0:/vsh/font/ and thats not right
try either using animLib, or do something like:Zitat:
Zitat von Urameshi
Code:function animateweirdnamedguy()
movingstate = movingstate + 1
if movingstate>= 48 or movingstate<=0 then
movingstate = 0
elseif movingstate < 12 then
player.image = right1
elseif movingstate < 24 then
player.image = right2
elseif movingstate < 36 then
player.image = right3
elseif movingstate < 48 then
player.image = right4
end
end
Zitat:
Zitat von myschoo
u mean i can't flash fonts?
whats wrong with the font script?
Hey, hope someone can help me out on this. I started to learn lua 2 days ago. After going through some tutorials, i thought id start with a pong game.
so i coded everything, did some graphics and now i have one problem:
My game has a menu with 4 choices. 2 player mode, survival mode, credits and quit. (not everything is finished yet).
everytime i start one of the modes, get out of it and try another one, get out of that one and try to start another one the third time, the psp freezes. :Argh:
Why is it doing that? hope someone knows a solution.
Cynical - I havanet looked at your code, but my guessis your not managing your resources correctly. You need to make sure you set ALL variables used in your source to 'nil', without hte quotes, before 'dofile'ing to another script (in your case that is). Than you need to call collectgarbage() to erase all traces of you varaibles from RAM.
ex:
Code:image = Image.load("bg.png")
function Cleanup()
image = nil
collectgarbage()
end
while true do
screen:blit(0,0,image)
pad = Controls.read()
if pad:cross() then
Cleanup()
dofile("game.lua")
end
screen.waitVblankStart()
screen.flip()
end
Yeah, its definately a memory issue, whats happening is you're loading the same images over and over without releasing them. What I usually like to do is set all my loads into a function, i.e.
function loadmultiplayergfx()
(load all your images)
end
and the immediately create an unload function, i.e.
function unloadmultiplayergfx()
(set all your images to null and collect garbage)
end
This way its as easy as calling the load at the beginning of the mode, and unloading as you leave the mode. Plus in your loading function you can blit a loading screen, making your app that much more presentable. Also remember that if you store images into an array of any type, you have to null the array before you collect garbage or lua actually won't free the memory.
Oh - good point. Make sure you free any references to any variable. By this, i mean:
Klepto - I did the same as well in my Call of Duty 2 - PSP Edition. My unload function was quite long asthe Lua doesnt support the multiple variable setting (var1 = var2 = var3 = nil doesnt work). I didnt know about the collectgarbage function until i read the Lua manual. Good thing too *sigh of relief*Code:bg1 = Image.load("bg.png")
-- why waste time reloading the same image? just feed the same image data into a new image variable
bg2 = bg1
...
function Cleanup()
bg1 = nil
-- collectgarbage() <- BOO BOO! bg2 still is referencing to bg1, and freeing bg1 will have bg2 reference to nothing (nothing as in, not an 'Image' type)
bg2 = nil
collectgarbage()
end
font is located in flash0:/font/ not flash0:/vsh/font/ ;)Zitat:
Zitat von ai3gtmc
-= Double Post =-
:(that collectgarbage() function is inside lua player or you have to create it??Zitat:
Zitat von SG57
Zitat:
Zitat von myschoo
oh man thx:) u rock:Punk:
but still does it work?
Zitat:
Zitat von myschoo
hmm i still dont have a psp
ok , tell me then
Zitat:
Zitat von SG57
Oh ok, I kinda suspected it had something to do with the the memory. (at one point I got a "mikmod critical error, out of memory"). Anyways,
should i also do the garbage collecting for variables that contain for examples just integers or strings? or is it only necessary for variables containing images?
I will try some garbage collection right now, thanks for the answers :)
@ Klepto - do you mean it like this:
function loadgfx()
image = Image.load("image.png")
end
function unloadgfx()
image = nil
collectgarbage()
end
loadgfx()
while true do
...
unloadgfx
dofile "..."
end
EDIT:
Now, the problem, that the psp freezes the third time trying to load a mode, is solved. but now i have the problem, that after a few times i try to load a mode, i get the following error:
LuaPlayer's mikmod has a critical error:
_mm_critical 0
_mm_errno 5
Sample load failed - Out of memoy
???
I've been looking into coroutines, can someone tell my why this isn't working?
when the program gets to the coroutine.resume it exits with the error:Code:chain = {}
chain.img = {}
chain.img[1] = Image.load("./gfx/tiles/1.png")
chain.img[2] = Image.load("./gfx/tiles/2.png")
chain.img[3] = Image.load("./gfx/tiles/3.png")
chain.head = {x = 30, y = 30}
chain.anchor = {x = 240, y = 136}
chain.segment = {}
chain.segment[1] = coroutine.create(function (head, anchor)
local newX = ((head.x + anchor.x)/2)+ math.random(-3, 3)
local newY = ((head.y + anchor.y)/2) + math.random(-3, 3)
screen:blit(newX, newY, chain.img[2])
coroutine.yield()
end)
loop = true
while loop do
pad = Controls.read()
if pad:left() and chain.head.x > 10 then chain.head.x = chain.head.x -1 end
if pad:right() and chain.head.x < 470 - chain.img[1]:width() then chain.head.x = chain.head.x +1 end
if pad:up() and chain.head.y > 10 then chain.head.x = chain.head.x -1 end
if pad:down() and chain.head.y < 262 - chain.img[1]:height() then chain.head.x = chain.head.x +1 end
screen:clear()
coroutine.resume(chain.segment[1](chain.head, chain.anchor))
screen:blit(chain.head.x, chain.head.y, chain.img[1])
screen:blit(chain.anchor.x, chain.anchor.y, chain.img[3])
screen:waitVblankStart()
screen:flip()
if pad:start() then loop = false end
end
attempt to call field '?' (a thread value)
From what I read, the benefit of coroutines is that it allows you to stop a function, and resume it at a later time. Concerning your code, when you call the resume, you cannot pass new variables, you simply must pass the thread name, ie.
coroutine.resume(chain.se gment[1])
another problem with your code is that your yield is at the end of your coroutine, so basically once its resumed, it runs through completely and is then killed. You will have to create a new thread if you want to have it run again, so in a sense you have just created a standard function.
Does anyone know how lua handles dead thread by the way?
Actually, according the "Programming in Lua" you can pass arguments. And looking at that page again, I see what I did wrong. I was trying to pass the arguments inside brackets like you would with a normal function, but when resuming coroutines you're already inside a set of brackets so you just use commas, like this:
And as for putting yield at the end, the simple solution too keep the thread from dying is to put the whole code block into a loop.Code:coroutine.resume(chain.segment[1](chain.head, chain.anchor)) -- bad
coroutine.resume(chain.segment[1], chain.head, chain.anchor) -- good
According to what I've read, resuming a coroutine takes up less processor time than calling a regular function so I was thinking that they would be perfect for keeping track of enemy ai
gotcha, the loop makes a lot of sense. I'll have to read up some more on this, any idea as to how much of a performance gain you would achieve by using this method?
No idea really, and in fact it might be possible that I mis-read something.
If I receive data from the ir port, how can I print it to the screen and how do I save it to a file?
Well, I've never used the IR port, but I assume that it's stored in a variable. So, to print it, do something like this:
To write it to a file:Code:foo = IR.read() --not actual function, just used as example
screen:print(10,10,foo,black)
Code:file = io.open("file.txt","w")
file:write(foo)
file:close()
Page 598, IR was discussed a little bit. Heres the link:
Link
Thanks!
-= Double Post =-
OK, but how can I read from a saved file and send the content of this file over ir?
file = io.open("file.txt","r")
System.irdaSend(file:read ("*a"))
file:close()
I forgot the IR function.
I've been struggling with this since yesterday...
What I want to do is have the Move 25 pixels event happen 3 times over a period of 1 second...not have the character move 75 pixels instantly...
I've tried timers and counters and the animation script but I only started coding 4 days ago and still don't know how to get this to work. I wish Lua worked like RPG Maker where you could just go "Wait(100)" for it to wait a second before proceeding...
Code:--MOB COLLISION--
if MobX - 15 <= CleoX and CleoX <= MobX + 10 and MobY - 35 <= CleoY and CleoY <= MobY + 15 then
Kill:play( )
if cleodown then CleoY = CleoY -25 end
if cleoleft then CleoX = CleoX +25 end
if cleoright then CleoX = CleoX -25 end
if cleoup then CleoY = CleoY +25 end
screen:blit(CleoX,CleoY,cleo[direction])
HP = HP - 1
end
screen:waitVblankStart(60 ) will pause the screen for 1 second. just make sure you slip the screen in between each call.Zitat:
Zitat von ClearTranquil
What do you mean slip the screen?
i think he meant flip
yeah, I stuck at typing:Argh:
Ohhh makes sense. Thanks.
That method isn't exactly what I was looking to do...I want it to run independant to the other events that are still moving/displaying things.
create a state - player_hit, and a counter. When the player gets hit, set the state to true. Then set all your player actions inside an if statement. If player_hit == false then you run the normal player controls and stuff. If player hit == true then you block the normal player stuff, and add 1 to the counter variable. when the counter reaches a certain number, you do the + 25 to the position and set the counter to 0, when you've done the + 25 3 times, you set player_hit to false in addition to reseting the counter
It seems everytime I try and create a "count = count +1" it does it infinately high right from the start. As if "count = count + 1000000000" wouldn't make it any different.
how are you doing it?
here's a simple counter, it adds 1 the the count each program cycle then displays the count:
Code:white = Color.new(255,255,255)
count = 0
while true do
count = count +1
screen:clear()
screen:print(10,10,count, white)
screen:flip()
pad = Controls.read()
if pad:cross() then break end
if pad:square() then count =0 end
end
That explains alot for me. I was putting count within an if statement. (noob)
well actually, you do want the count inside an if statement, I.E. if player hit == true then count = count + 1, and then inside that same if statement do if count = (60/3) then +25 to player pos and have another statement - if count >= 60 then count = 0 , player_hit = false
haha, well, this is the lua help thread, and i need lua help.
I want to use a "player" move kind've script but implement it into an image that kind've slides up and down when i press pad up and pad down, i've been going through some ideas and i've had some luck. However, i cannot seem to stop the image at pixels 0 and 512 (in other words, stop the picture from rolling off screen whilst holding up or down. I've had some some luck, but whenever it seems to work i get errors like "loop ungettable".
Any help would be appreciated.
Code:if pad:up() and player.y > 0 then player.y = player.y - someSpeed end
if pad:down() and player.y+player.height < 512 then player.y = player.y + someSpeed end
I'm sure this my codes aren't efficient at all but I'm having some problems with collision. I'm thinking of just redoing it and making each map a separate file because this is just starting to get long and ridiculous.
Basically my problems are:
-When multiple buttons are pressed against a wall it gets REALLY screwed and the character flies in diagonal directions
-When the monster pushes the character against the wall she still goes right through it.
-When you push the monster back into some walls it applies both the X and Y displacement for some reason.
It's really frustrating...I can understand how to do collision based on objects but what I need is outer walls. The code I posted is for this map:
http://i4.photobucket.com/albums/y13...enyPreview.jpg
What I wish I could do is make an image the goes over top of the background and make it the only walkable/unwalkable area...
Code:--MAP 1----------------------------------------------------------------------------
if map == 0 then
if CleoY >= 216 then
map = 1
CleoY = 0
MobX = 350
MobY = 70
end
if CleoY <= 12 then
dontmoveoff = false
CleoY = 12
end
if CleoX <= -18 then
map = 3
CleoX = 440
MobX = 200
MobY = 150
end
if CleoX >= 441 then
map = 5
CleoX = 0
MobX = 150
MobY = 70
end
if CleoX <= 49 and CleoY <=133 then
dontmoveoff = false
if pad:left() then
CleoX = 49
elseif pad:left() and pad:up() then
CleoX = CleoX + 3
CleoY = CleoY + 3
else
CleoY = 133
end
end
if CleoX >= 219 and CleoY <=48 then
dontmoveoff = false
if pad:right() and cleoright then
CleoX = 219
elseif pad:up() and pad:right() then
CleoY = CleoY + 3
CleoX = CleoX + 3
elseif pad:up() and pad:left() then
CleoY = CleoY + 3
CleoX = CleoX - 3
else
CleoY = 48
end
end
if CleoX >= 414 and CleoY <=180 then
dontmoveoff = false
if pad:right( ) then
CleoX = CleoX - 3
else
CleoY = CleoY - 3
end
end
-------------------------------------------------------------
if MobY >= 216 then
MobY = 216
end
if MobY <= 12 then
dontmoveoff = false
MobY = 12
end
if MobX <= -18 then
MobX = -18
end
if MobX >= 441 then
MobX = 441
end
if MobX <= 49 and MobY <=133 then
dontmoveoff = false
if mobwalkleft then
MobX = 49
else
MobY = 133
end
end
if MobX >= 219 and MobY <=48 then
dontmoveoff = false
if mobwalkright then
MobX = 219
elseif mobwalkup then
MobY = 48
end
end
if MobX >= 414 and MobY <=180 then
dontmoveoff = false
if mobwalkright then
MobX = 414
else
MobY = 180
end
end
end --MAP 1 END
ALSO!!!
When I pin a monster against the wall if I hold down X (attack) it keeps doing it....
Code:--ATTACKING---------------------------------------------------------------------------
if not quitting then
if not pad:cross() then
Voicefx.Voicesound = false
end
if pad:cross() and not pad:triangle() and not pad:square() and not pad:circle() then
if pad:cross( ) then
if not Voicefx.Voicesound then
Voice:play( )
Voicefx.Voicesound = true
end
else Voicefx.Voicesound = false
end
buttonpress = 1
screen:blit(340,0,menu[buttonpress])
if cleodown then direction = 5 end
if cleoleft then direction = 6 end
if cleoright then direction = 7 end
if cleoup then direction = 8 end
screen:blit(CleoX,CleoY,cleo[direction])
--ATTACKDAMAGE-----------------------------------------------------------------
if MobX - 40 <= CleoX and CleoX <= MobX + 40 and MobY - 50 <= CleoY and CleoY <= MobY + 40 then
Stab:play( )
if cleoup then
MobY = MobY - 20
elseif cleoleft then
MobX = MobX - 20
elseif cleoright then
MobX = MobX + 20
elseif cleodown then
MobY = MobY + 20
end
end
end
end