its like this:
Code:while true do
pad=controls.read
if pad~=oldpad then
put your control code here
end -- end of the if pad~=oldpad loop
oldpad=pad
end --end of while loop
Printable View
its like this:
Code:while true do
pad=controls.read
if pad~=oldpad then
put your control code here
end -- end of the if pad~=oldpad loop
oldpad=pad
end --end of while loop
Yes. OR use a timer (this way you still have functionality, i.e. the loop continues), OR use screen.waitVblanck() (this way the loop will pause for a given amount of time (60=1 second))Zitat:
Is there anyway to blit an image, wait a set amount of time, then blit another?
Thanks, but now i get this error, what on earth does is mean?
Code:error: index.lua:131: <eof> expected near `end'
You have to much ends, maybe it can also mean that you have to few. Anyway, check your ends.
The oldpad thing doesnt work, heres what i have in my main loop:
Code:--Main Loop
while true do
pad = Controls.read()
if pad~=oldpad then
if pad:down() then
menustatus = 2
end
if pad:up() then
menustatus = 1
end
if pad:cross() and menustatus == 1 then
score = 0
dofile("Jumper.lua")
end
if pad:cross() and menustatus == 2 then
break
end
if pad:right() then
dificulty = dificulty + 1
end
if pad:left() then
dificulty = dificulty - 1
end
if dificulty > 3 then
dificulty = 3
end
if dificulty < 1 then
dificulty = 1
end
if menustatus == 1 then
screen:print(200,248,"Play",green)
screen:print(200,258,"Quit",white)
end
if menustatus == 2 then
screen:print(200,248,"Play",white)
screen:print(200,258,"Quit",green)
end
if dificulty == 1 then
screen:print(160,208,"Easy",green)
screen:print(200,208,"Medium",white)
screen:print(250,208,"Hard",white)
end
if dificulty == 2 then
screen:print(160,208,"Easy",white)
screen:print(200,208,"Medium",green)
screen:print(250,208,"Hard",white)
end
if dificulty == 3 then
screen:print(160,208,"Easy",white)
screen:print(200,208,"Medium",white)
screen:print(250,208,"Hard",green)
end
screen.flip()
screen.waitVblankStart()
end
if pad:right() then
dificulty = dificulty + 1
end
if pad:left() then
dificulty = dificulty - 1
end
if dificulty > 3 then
dificulty = 3
end
if dificulty < 1 then
dificulty = 1
end
if menustatus == 1 then
screen:print(200,248,"Play",green)
screen:print(200,258,"Quit",white)
end
if menustatus == 2 then
screen:print(200,248,"Play",white)
screen:print(200,258,"Quit",green)
end
if dificulty == 1 then
screen:print(160,208,"Easy",green)
screen:print(200,208,"Medium",white)
screen:print(250,208,"Hard",white)
end
if dificulty == 2 then
screen:print(160,208,"Easy",white)
screen:print(200,208,"Medium",green)
screen:print(250,208,"Hard",white)
end
if dificulty == 3 then
screen:print(160,208,"Easy",white)
screen:print(200,208,"Medium",white)
screen:print(250,208,"Hard",green)
end
screen.flip()
screen.waitVblankStart()
oldpad=pad
end
look closer at my post. Anyway, the controls that you want to do something only ones if pressed should be in the "if pad~=oldpad then" and "end" commands. Now you have exactly those outside of them.
I don't understand. :Argh:
you have added the right bits to the controls.
obviously delete the spaces i created there. it's just to show you where to put them. make sure oldpad = pad is at the end, before you have the ends. so in the loop. and make sure you haveZitat:
if pad:------directional button-------() and
oldpad:------directional button-------() ~= pad:------directional button-------() then
(-------sound here-----):play()
end
end
out of the loop at the beginning and finaly, make sure you haveZitat:
oldpad = Controls.read()
at the beginning of the loop.Zitat:
pad = Controls.read()
obviously, change it from the sound play, to whatever you want it to do.
So this would be correct?:
if so it doesnt workCode:if pad:right() and
oldpad:right() ~= pad:right() then
dificulty = dificulty + 1
end
if pad:left() and
oldpad:left() ~= pad:right() then
dificulty = dificulty - 1
end
you spelt dificulty wrong, don't know if that makes a difference. it's difficulty.
i'll take a look at the script if you want.
difficulty is spelt wrong throughout the code, so it's not that.
could you send me the script in an email? i'll take a look at whatever the problem is. [email protected] t.com .
Could anyone tell me about the timer funtion?
How it works, how to implement it etc.
if pad:right() and
oldpad:right() ~= pad:right() then
dificulty=dificulty+1
Cheers paul.
i'm trying to create the custom eboot for my lua app. currently, i am using just someone elses ready made eboot. i don't like doing that kind of thing, so i would prefer to create one myself. i'm not sure how to do it though? i am reading about how to compile lua, but i don't think it's the same thing. i took a look over at the ps2dev forum, and the search function isn't really that good...
any guidance?
If i run enemy 1 by itself its fine, but nothing happens if both enemy 1 and enemy 2 are used. It all looks ok, but the two images are invisible.
Code:--Enemy 1
if enemy.x == 480 then
enemyblit = enemysprite[math.random(1,3)]
end
if enemy.x == 480 then
enemyspeedvar = enemyspeed[math.random(1,3)]
end
if enemy.x > 1 then
enemy.x = enemy.x - enemyspeedvar
end
if enemy.x < 5 then
score = score + 1
end
if enemy.x < 2 then
enemy.x = 480
screen:blit(enemy.x,enemy.y,enemyblit)
end
--Enemy 2
if enemy.x == 480 then
enemy2blit = enemy2sprite[math.random(1,3)]
end
if enemy2.x == 480 then
enemy2speedvar = enemyspeed[math.random(1,3)]
end
if enemy2.x > 1 then
enemy2.x = enemy.x - enemy2speedvar
end
if enemy2.x < 5 then
score = score + 1
end
if enemy2.x < 2 then
enemy2.x = 480
screen:blit(enemy2.x,enemy2.y,enemy2blit)
end
end
you might be missing a waitVblankStart() or even a screen:flip() ? that would be my only guess.
No, it isnt that.
But the werid thing is that my collision detection still works.
This should work. But i dont think your code is working as it are if commands and not while loops, for the 2 seperate menuparts.Code:--Main Loop
while true do
pad = Controls.read()
if pad~=oldpad then
if pad:down() then
menustatus = 2
end
if pad:up() then
menustatus = 1
end
if pad:cross() and menustatus == 1 then
score = 0
dofile("Jumper.lua")
end
if pad:cross() and menustatus == 2 then
break
end
if pad:right() then
dificulty = dificulty + 1
end
if pad:left() then
dificulty = dificulty - 1
end
if dificulty > 3 then
dificulty = 3
end
if dificulty < 1 then
dificulty = 1
end
if menustatus == 1 then
screen:print(200,248,"Play",green)
screen:print(200,258,"Quit",white)
end
if menustatus == 2 then
screen:print(200,248,"Play",white)
screen:print(200,258,"Quit",green)
end
if dificulty == 1 then
screen:print(160,208,"Easy",green)
screen:print(200,208,"Medium",white)
screen:print(250,208,"Hard",white)
end
if dificulty == 2 then
screen:print(160,208,"Easy",white)
screen:print(200,208,"Medium",green)
screen:print(250,208,"Hard",white)
end
if dificulty == 3 then
screen:print(160,208,"Easy",white)
screen:print(200,208,"Medium",white)
screen:print(250,208,"Hard",green)
end
if pad:right() then
dificulty = dificulty + 1
end
if pad:left() then
dificulty = dificulty - 1
end
if dificulty > 3 then
dificulty = 3
end
if dificulty < 1 then
dificulty = 1
end
if menustatus == 1 then
screen:print(200,248,"Play",green)
screen:print(200,258,"Quit",white)
end
if menustatus == 2 then
screen:print(200,248,"Play",white)
screen:print(200,258,"Quit",green)
end
if dificulty == 1 then
screen:print(160,208,"Easy",green)
screen:print(200,208,"Medium",white)
screen:print(250,208,"Hard",white)
end
if dificulty == 2 then
screen:print(160,208,"Easy",white)
screen:print(200,208,"Medium",green)
screen:print(250,208,"Hard",white)
end
if dificulty == 3 then
screen:print(160,208,"Easy",white)
screen:print(200,208,"Medium",white)
screen:print(250,208,"Hard",green)
end
screen.flip()
screen.waitVblankStart()
oldpad=pad
end --this is the end from the if pad~=oldpad check
end -- this is the end from the while loop
Ok i got another question: How does the os.time() command works?
I know this: math.randomseed(os.time() ), but i cant seem to just use the number that os.time() generates.
If anyone is willing have a look at my code, play it in windows player, and have a look on medium mode. As you can see the enemy 1 and 2 x coordinates change, and the collision works, but the image arent there.
http://gutya.psparchive.de/Temp/Jumpertest.rar
Gutya they aren't showing because you blit the images before you blit the background so the background is in front of them...
Edit: this code works. http://www.roflolz.com/Jumper.lua
Thanks for the reply. I have copied it and it worked. Kind of a neat little game too! :razz: Anyways, now I made a new tile set that is bigger (same tile size but just more) and I'm trying to figure out what to change. When I try something it just spreads the tiles out way to much or only shows one. This kind of goes back to my first question. What dose what? What is math.mod/floor? I need to know what to change for a bigger tile set here:Zitat:
Zitat von califrag
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)
Thanks!
P.S. If isnt too much trouble can someone sell me how I would make a game where I make the map from tiles, have my char in the middle and then when I want to move, it moves the background? I heard there is a way to make is generate the tiles needed at the time so it wont lag too much. Thanks!
how would i prompt for a variable
well for bigger tiles you would probably change "16" to whatever the width or height is of your tile image.. so if you have an image with tiles that are 20x20 you would change the 16's the 20's so it will calculate the correct distance to place the tiles. The 17's and 30's are the size of the map (if you look at the table which defines the layout of the tiles/map you see it is 17 rows and 30 columns) so just change those values to however large you want your map to be... I've never built one of these games/programs so don't blame me if I'm wrong ;P
Zitat:
Zitat von Altair
you can also do:
which is easier to make dynamic ;DCode:tblImages = {}
tblImages[1] = Image.load("Images/enemy1.png")
tblImages[2] = Image.load("Images/enemy2.png")
tblImages[3] = Image.load("Images/enemy3.png")
tblImages[4] = Image.load("Images/enemy4.png")
tblImages[5] = Image.load("Images/enemy5.png")
while true do
screen:blit(x, y, tblImages[math.random(1, 5)])
screen.flip()
screen.waitVblankStart()
end
ehhm its exactly the same, only i assign those values in one time whereas you do it for each image seperately.
Thanks for all the help guys, but i have yet another question.
Could anyone explain how the timer function works?
clock=Timer.new([startTime])
clock:start() -- starts the timer and returns the time in milieseconds
clock:time() -- returns the time in miliseconds
clock:stop() -- stops the timer and returns the time in milieseconds
clock:reset([startTime])
where clock is the name of the timer
Cheers mate, that should help me.
So if i have this function:
could i do it like this:Code:function timer1()
enemywait = Timer.new()
enemywait:start()
if enemywait:time() == 1000 then
enemywait:stop()
end
enemywait:reset()
end
Would that do enemya wait 1 second, then do enemyb?Code:enemya()
timer1()
enemyb()
end
no. then just say if enemywait:time()==1000 then enemyb()
Hmm i can't figure it out.
Has anyone been able to load a true-type font yet? I tried the code in the wiki tutorial, but i get a "Font is a nil value" error.
Maybe you could have a look at the example that comes bundled with lua player.
I did. There is no True Type Font being loaded, just the default font being adjusted.
Ah, i appologise.Zitat:
Zitat von PSPHax0r9
how do i get an image to come on for about 2sec, then off for 2sec, then on, repeated
and how do have a commmand, made up of serveral commands,, as if i wanted one button to change the controls, but without going in a new file
Use a function. Just do:Zitat:
Zitat von Sousanator
then later on just call that function again and it will perform whatever is contained in the function. For example:Code:function dosmething()
yourcode here.
end
Hope that helps. For more info and a great tutorial on functions, go to evilmana.com and check the function tutorial.Code:if pad:cross() then
dosomething()
end