Ok thanks i will try this - but this only checks if the file exists, right? I'm trying to make sure that the image can actually be used (ie. PNG's over 512x512)
Printable View
Ok thanks i will try this - but this only checks if the file exists, right? I'm trying to make sure that the image can actually be used (ie. PNG's over 512x512)
i never did this before, but looking at this list, i'd say this is how to do it:Zitat:
Zitat von Yongobongo
please correct if i am wrong thoughCode:test = Image.load("test.png")
testX = test.width()
testY = test.height()
if testX*testY >= 512*512 then
[blah blah]
end
if the image can't be loaded then using Image.load on it will cause the script to break and show the error message, but from what I understand what Yongo wants to do is check to see if an image can be loaded in order to avoid having Image.load break the script
There are two ways that I can see for doing this. The first would be to do research on the format of the .png header and write a function that could open it as a data file to read the image dimensions and other stuff from the header. The second would be to get into the lua player source and either add a new function to check if the image can be loaded, or else change the Image.load function to prevent it from throwing the error
O.k. I've put the code to recall the random numbers after the correct/incorrect message is shown. Now there is a random bug where I only press the button once, but I get about 2-5 incorrect/correct messages. E.G. I could press left once but the screen shows correct then correct then incorrect then correct again.
PS The code is the same except after scren.flip() i've added RanNumber = math.random(1,11)
PPS If anyone doesn't know what code i'm talking about go to page 784. It isn't hard to find. ;)
Your problem is that the button is being pressed for more than one loop. You could use timers, and pause it after a question, or you could use this:
Code:oldpad = Controls.read()
while true do
pad = Controls.read()
if (pad:left() ~= oldpad:left()) and pad:left() then
bla bla bla
end
oldpad = pad
end
P.S. Can anyone point me to a non-pixel based, circle-rectangle collision algorithm that works with a diagonal rectangle? It would save me some time.
I've tried putting in what you suggested but it doesn't make a difference.Zitat:
Zitat von Nielkie
[EDIT]
I've decided to remake the game from scratch. I've keep getting bug after bug after bug and it's completely useless.
[EDIT]
I've redone the code. I now have an error saying bad argument #1 to 'len' (string expected, got nil). Any ideas how to fix this?
Code:math.randomseed(os.time());
NUM_QUESTIONS = 12
NUM_ANSWERS = 12
question = {}
question[1] = { name = "What countries did Vikings originate from?", answer = {"A: Germany, England and Iceland","B: Greenland, Germany and Iceland","C: Denmark, Sweden and Norway","D: Iceland, Sweden, Norway"}, correctAnswer = 3 }
question[2] = { name = "Why did the Vikings originally travel to other countries?", answer = {"A: To trade","B: To plunder","C: To kill","D: To sieze power"}, correctAnswer = 1 }
question[3] = { name = "Vikings had a reputation for being what in battle?", answer = {"A: Couragous","B: Random","C: Strong","D: Skilled"}, correctAnswer = 4 }
question[4] = { name = "What weapons were used by the Vikings?", answer = {"A: Bows, Rifles and Swords","B: Sword, Double-Axe and Spear","C: Cannons, Arrows and Bows","D: Sword, Arrows and Canons"}, correctAnswer = 2 }
question[5] = { name = "What was the common name of the plague in medieval Europe?", answer = {"A: Black Plague","B: Dark Plague","C: Black Death","D: Bubonic Death"}, correctAnswer = 3 }
question[6] = { name = "How long did the Hundred Years' War last?", answer = {"A: 100","B: 116","C: 84","D: 136"}, correctAnswer = 2 }
question[7] = { name = "What spread the Bubonic Plague?", answer = {"A: Rats","B: Ticks","C: Fleas","D: Beavers"}, correctAnswer = 3 }
question[8] = { name = "What objects were Vikings buried in?", answer = {"A: Their Ships","B: Graves","C: Crypts","D: Their Homes"}, correctAnswer = 1 }
question[9] = { name = "What was another name for Vikings", answer = {"A: Plunderers","B: Norsemen","C: Wolfmen","D: They didn't have other names"}, correctAnswer = 2 }
question[10] = { name = "What countries did Vikings originate from?", answer = {"A: Denmark, Sweden and Norway","B: Greenland, Iceland and Norway","C: Iceland, Germany and Norway","D: Germany, England and Iceland"}, correctAnswer = 1 }
question[11] = { name = "Knights fought on what?", answer = {"A: Slaves","B: Cows","C: Horses","D: Their Feet"}, correctAnswer = 3 }
question[12] = { name = "What 4 empires existed prior to the Dark Ages?", answer = {"A: Roman, Persian, English and American","B: Roman, Guptan, Persian and Barbarian","C: Japanese, Chinese, Guptan and Roman","D: Roman, Guptan, Persian and Chinese"}, correctAnswer = 4 }
function printCentered(y,text,color)
local length = string.len(text)
local x = 240 - ((length*8)/2)
screen:print(x,y,text,color)
end
currentQuestion = math.random(1, NUM_QUESTIONS)
correct = 0
incorrect = 0
oldQuestion = 0
oldpad = Controls.read()
while true do
pad = Controls.read()
if oldpad ~= pad then
if pad:left() then
if question[currentQuestion].correctAnswer == 1 then
correct = correct + 1
else
incorrect = incorrect + 1
end
oldQuestion = currentQuestion
while currentQuestion == oldQuestion do
currentQuestion = math.random(1,12)
end
elseif pad:right() then
if question[currentQuestion].correctAnswer == 2 then
correct = correct + 1
else
incorrect = incorrect + 1
end
oldQuestion = currentQuestion
while currentQuestion == oldQuestion do
currentQuestion = math.random(1,12)
end
elseif pad:square() then
if question[currentQuestion].correctAnswer == 3 then
correct = correct + 1
else
incorrect = incorrect + 1
end
oldQuestion = currentQuestion
while currentQuestion == oldQuestion do
currentQuestion = math.random(1,12)
end
elseif pad:circle() then
if question[currentQuestion].correctAnswer == 4 then
correct = correct + 1
else
incorrect = incorrect + 1
end
oldQuestion = currentQuestion
while currentQuestion == oldQuestion do
currentQuestion = math.random(1,12)
end
end
end
oldpad = pad
screen:clear()
if correct + incorrect == 50 then
break
end
printCentered(140,question[currentQuestion].name, Color.new(255,255,255))
for i=1,NUM_ANSWERS do
printCentered(160 + i*15,question[currentQuestion].answer[i], Color.new(200,200,200))
end
printCentered(10,"Correct: " .. correct .. " Incorrect: " .. incorrect, Color.new(255,255,255))
screen.waitVblankStart()
screen.flip()
end
I made lua program, now I want to know How I can make EBOOT from my lua program. It isn't very funny to start lua player every time, before starts my program.
I am sorry for my bad english.
To compile an eboot you need cygwin (linux emulator for windows) and psptoolchain. However, because you used Lua as a programming language, you can't compile it into an eboot file.Zitat:
Zitat von ISO-B
@drag_93: NUM_ANSWERS should be 4.
P.S. Save some space:
@ISO-B: See http://www.forums.evilmana.com/index.php?topic=861.0Code:if oldpad ~= pad then
if pad:left() then
answer = 1
elseif pad:right() then
answer = 2
elseif pad:square() then
answer = 3
elseif pad:circle() then
answer = 4
end
end
if question[currentQuestion].correctAnswer == answer then
correct = correct + 1
oldQuestion = currentQuestion
while currentQuestion == oldQuestion do
currentQuestion = math.random(1,12)
end
answer = 0
elseif answer ~= 0 then
incorrect = incorrect + 1
oldQuestion = currentQuestion
while currentQuestion == oldQuestion do
currentQuestion = math.random(1,12)
end
answer = 0
end
You can make an EBOOT file that runs LUA scripts. Not sure how though.Zitat:
Zitat von drag_93
Theres a few ways. If you know C, you can program a 'lua player' that has converted all of the lua scrip to Lua commands within the app so it's completely unknown as you'd have to reverse engineer the EBOOT. the other method is embedding the Lua script iwthin the eboot which has been done but is still readable via opening the EBOOT. Not sure what oyu want to compile it for however.
but then again, if you have no clue what you are doing really, you could do this (the easiest method i believe there is):
delete applications folder and everything in it. go to system, delete library folder. copy and paste everything from your game in the main luaplayer folder. rename the folders to whatever you want "name" and "name%" and there you go. :)
theres an app that allows you to modify the eboot, but i dont know it. :( as long as the eboot remains like it is, it'll come up as 'luaplayer' in the xmb but it will actually be your creation.
yes eminent is right, thats the easiest way. what you need to change what the eboot says and looks like is PSPBrew i think, i will check real quick and then send a link here
-= Double Post =-
okay it is, here is the link
I have a problem with my menu.
Basically i have an image with three options on it, and i have an image for an arrow to display which one is highlighted.
I can and have the code for just the arrow to move between each option by pressing up/down, but i want to go a bit more advanced. i want the arrow to move slightly from side to side like
in first half second
->
2nd:
. ->
3rd
... -> [ignoring the full stops]
and back then and repeat that.
so i made a nother integer , arrow1 (one signifying that it's highlighting the 1st option) and thin int can be 1,2 or 3 which displays it moving.
Only problem is it doesnt work, the menu gets glitchy and gets linely in places
I've only tried it for the first option, i hope to have arrow2 and 3 ints if i can get the 1st one to workPHP-Code:
oldpad = Controls.read()
screen:clear()
menu = Image.load("menu.png")
arrow = Image.load("arrow.jpg")
intmenu = 1
while true do
pad = Controls.read()
if pad:down() and oldpad:down() ~= pad:down() then
intmenu = intmenu + 1
end
if pad:up() and oldpad:up() ~= pad:up() then
intmenu = intmenu - 1
end
if intmenu >= 4 then
intmenu = 1
end
if intmenu <= 0 then
intmenu = 3
end
if intmenu == 1 then
arrow1 = 1
screen.waitVblankStart(3)
arrow1 = arrow1 + 1
if arrow1 >= 4 then
arrow1 = 1
end
if arrow1 <= 0 then
arrow1 = 3
end
if arrow1 == 1 then
screen:clear()
screen:blit(0, 0, menu)
screen:blit(3, 105, arrow)
end
if arrow1 == 2 then
screen:clear()
screen:blit(2, 105, arrow)
end
if arrow1 == 3 then
screen:clear()
screen:blit(1, 105, arrow)
end
screen:flip()
if pad:cross() then
dofile("character.lua")
end
end
if intmenu == 2 then
screen:clear()
screen:blit(0, 0, menu)
screen:blit(3, 172, arrow)
if pad:cross() then
dofile("credits.lua")
end
end
if intmenu == 3 then
screen:clear()
screen:blit(0, 0, menu)
screen:blit(3, 240, arrow)
if pad:cross() then
dofile("credits.lua")
end
end
screen:flip()
oldpad = pad
end
I have a feeling that i have a blit in the wrong places but tried different ways and didnt work properly
Anyone see a problem(s)??
i havent really looked too much into the code, but try defining arrow1 outside all if statements. (and loops.) instead of in a while statement, like it is now.
Way to many screen:clear() calls, only use one right at the start of your loop and just make sure you build your screen image in the correct order. also you shouldn't have to make new variables for the cursor movement... use the same one. Try to find the algorithms in everything you do, keeps your code a lot cleaner and easier to debug. For instanceZitat:
Zitat von DtotheK
anyways, you get the jist (written out of memory so I appologize for any slight syntax errors). If you keep it all in tables it makes it alot easier to unload when switching between game modes to free up memory.Code:
menu = {}
menu.selection = 1
menu.max = 3
menu.rowHeight = 70
menu.cursor = image.load(<IMAGE>)
menu.cursorSwayMax = 5
menu.cursorSway = 0
while true do
screen:clear()
pad = Controls.read()
if pad:up() then
menu.selection = menu.selection - 1
if menu.selection <= 0 then
menu.selection = menu.max
end if
end if
if pad:down() then
menu.selection = menu.selection + 1
if menu.selection > menu.max then
menu.selection = 1
end if
end if
if menu.cursorSwayMax > 0 then
menu.cursorSway = menu.cursorSway + 1
else
menu.cursorSway = menu.cursorSway - 1
end if
if menu.cursorSway == menu.cursorSwayMax then
menu.cursorSwayMax = menu.cursorSwayMax * -1
end if
screen:blit(10 - menu.cursorSway, menu.rowHeight*menu.selection, menu.cursor)
screen.flip()
end
yes! works and looks great! just a few lines needed slight changing, and i'll change the control detection thing cause when you hold down/up down it flys through the options like mad. and i'll stick in the actual backround of the menu.
Thankyou !!!
i'll post up the code when i fix it up incase anyone wants it.
-= Double Post =-
here it is, works perfectly!
just have to match up the heights of option and arrow
and what to do when menu.selection = 1,2 and 3!
:Punk:PHP-Code:oldpad = Controls.read()
menu = {}
menu.selection = 1
menu.max = 3
menu.rowHeight = 70
menu.cursor = Image.load("arrow.jpg")
menu.back = Image.load("menu.png")
menu.cursorSwayMax = 5
menu.cursorSway = 0
while true do
screen:clear()
while true do
pad = Controls.read()
if pad:up() and oldpad:up() ~= pad:up() then
menu.selection = menu.selection - 1
end
if menu.selection <= 0 then
menu.selection = menu.max
end
if pad:down() and oldpad:down() ~= pad:down() then
menu.selection = menu.selection + 1
end
if menu.selection > menu.max then
menu.selection = 1
end
if menu.cursorSwayMax > 0 then
menu.cursorSway = menu.cursorSway + 1
else
menu.cursorSway = menu.cursorSway - 1
end
if menu.cursorSway == menu.cursorSwayMax then
menu.cursorSwayMax = menu.cursorSwayMax * -1
end
screen:blit(0, 0, menu.back)
screen:blit(10 - menu.cursorSway, menu.rowHeight*menu.selection, menu.cursor)
screen.flip()
oldpad = pad
end
end
does anyone know if there is a do-while loop in lua? if so how would you construct it. i have been looking and couldn't find it so i figured i'd ask here.
Zitat:
Zitat von emericaska8r
Learn basic lua syntax here:Code:repeat
<code>
until condition
Program in Lua
DtotheK:
whats the real point of this:
while true do
screen:clear()
while true do
pad = Controls.read()
??????????????????? o_O
to the point i would like to know how i would go about creating my own font or getting one that is curretly available could someone please help if they know
thanks
at the top of this page it will tell you how to make or load an existing font. Then, to use this font use:
Code:screen:fontPrint( font, x, y, string, color )
but its very slow... you will see yourself ;)
http://www.pspro.co.uk/forums/index.php/topic,55.0.html
For True Type Fonts.
thanks that helped a load
No problem (if that was directed to me).
i dunno bout the first 2 lines , they were in the code for the swaying arrows i gas given, and i never removed them, but it works fine with them so i just left them in for no reason...Zitat:
Zitat von myschoo
and the 2 last lines as far as i knew are necessary to keep checking what controls are pressed, and are in all the tutorials i have read as far as i remember..... and the code works with them there!
but now that you question them...
They were not in the original code. Go back a page and read carefully, it should beZitat:
Zitat von DtotheK
The way it is now, you are actually never calling screen:clear() but your background is hiding your old screen every cycle so it still works fine, but if you were to break the inner loop (for program exit as an example) you'll be stuck in an infinite black screen loop, so be careful.Code:while true do
screen:clear()
pad = Controls.read()
...rest of code
My bad, got mixed up when i added in all the oldpad stuff...Zitat:
Zitat von KleptoOne
will do, thanks for pointing that out!Zitat:
Zitat von KleptoOne
I got a error for somthing likeAny help im running luaplayer for windows on windows 98, and im just trying to run a simple menu, Any HelpZitat:
C:/luaplayer> luaplayer script.lua:58 error then expected near "="