Nothing I can do about that. Looks like LuaPlayer syncs to the memory card when the file is closed whcih ensures that the data is written to card and flushes the buffer. I wouldn't have thought it be 10 secs though.
Printable View
Nothing I can do about that. Looks like LuaPlayer syncs to the memory card when the file is closed whcih ensures that the data is written to card and flushes the buffer. I wouldn't have thought it be 10 secs though.
i now just need to know, when the game ends, and it says game over, how to i make triangle make the game restart? what tells the game to restart?
-= Double Post =-
nah thats sorted.Zitat:
Zitat von head_54us
-= Double Post =-
finished game...
restart button
put this in/near your game over function/loop
Code:if pad:triangle() then
dofile(".index.lua")
end
I keep getting this weird error:
Heres my code:
Heres my error:Zitat:
-- Alien Cross Hair Menu Screen
-- Create Colors
white = Color.new(255,255,255)
red = Color.new(255,69,0, 195)
-- Load Background
Background_Menu = Image.load("./Images/back_menu.png")
-- Load Arrow Image
arrow = Image.load("./Images/arrow_down.png")
-- The Loop
while true do
screen:blit(0,0,Backgroun d_Menu)
screen:blit(208,193,arrow )
oldpad = Controls.read()
pad = Controls.read()
-- Prints our 4 menu options
screen:print(208,96,"Star t Game",white)
screen:print(128,144,"Cre dits",white)
screen:print(208,192,"How To Play",white)
screen:print(288,144,"Exi t To XMB",white)
-- These make it so when the variable "current" changes
-- so does the current menu selection
if current == 1 then
screen:print(208,96,"Star t Game",red)
screen:blit(208,97,arrow)
end
if current == 2 then
screen:print(128,144,"Cre dits",red)
screen:blit(128,145,arrow )
end
if current == 3 then
screen:print(208,192,"How To Play",red)
end
if current == 4 then
screen:print(288,144,"Exi t To XMB",red)
screen:blit(288,145,arrow )
end
if pad:up then
current = 1
end
if pad:left then
current = 2
end
if pad:down then
current = 3
end
if pad:right then
current = 4
end
screen.waitVblankStart()
screen.flip()
oldpad = pad
end
Error: menu.lua:45: function arguments expected near /then/
??????
if pad:down() then
if pad:left() then
if pad:right() then
if pad:left() then
You have to have function arguments after buttons.
-= Double Post =-
http://evilmana.com/tutorials/codebase/simple_menu.php
I would use that to make a menu. It's much better.
Hey guys, sorry for that long code, I figured out the problem, I just forgot to put the () infront of my pads :D
LOL, aha.
EDIT:
aww, someone beat me to it.
Hold on, I have another question.
Whats the correct coding for getting back to the XMB?
there is no code to get back to XMB from luaplayer. but you can the eboot from the modded luaplayer and use the System.Quit() command as LMelior stated before.. PM me if you need help with that.
where does it actually define the variable 'current'?
ok...
you know how when u screen:blit it makes the image show up?
well is there a way you can do the opposite?
like i want it so when i press r my first image dissapeers and a new one comes up.
i have thing sort of working but when i press r the new image shows up just on top of the old one. and they both continue to like they are spossed too.
please tell me what i have to do to make the original dissapear when r is pressed. here is my code..
Player = { }
Player[1] = { x = 200, y = 197 }
while true do
pad = Controls.read()
screen:clear()
screen:blit(Player[1].x,Player[1].y,player)
if pad:l() and Player[1].x > 0 then
Player[1].x = Player[1].x - 2
end
if pad:r() and Player[1].x < screenwidth then
Player[1].x = Player[1].x + 2
screen:blit(Player[1].x,Player[1].y,player2)
end
@ Jamz, when you blit an image it isnt actually written to the screen. Its written to the buffer. When flip.Screen is executed the buffer is drawn to the screen. So you put what you want blitted in an if loop. I dont know lua, but ill try.
Code:
if playerblit = 1 then
//* Blit code for player.
end
//* Then set up a pad input so that if R is pressed playerblit equals 0
ok thnx ill try that
how do you display text on a coordinate and keep it their while on another coordinate, display text and keep changing it? get what im saying?
ok nutterbuter i did what u said but now when i press "r" the value of player is permannently changed to zero. is there a way to temporarily change the value so it is zero only when r is pressed
EDIT: nvm i fixed it
Yay, i actually used my skills for good!Zitat:
Zitat von jamz1825
When you screen:print text is there a way to automatically skip a certain amount of pixels down once the text has filled the screen. If you need any more details please post... Any help would be really appreciated. Im looking for a way to make a paragraph without alot of hassle.
There is no way to automatically go to the next line. The best way to do it is as follows.
1. Open up Photoshop or the Gimp
2. Open up you picture
3. Write the text on the picture
4. Save it as a .PNG file
Unless string.gfind is implemented in the latest LuaPlayer, this is the best I can do (Note the chopping of text at the end of the line). Probably really slow as well. Press left and right to narrow widen the text width.
http://i7.tinypic.com/24o3o5e.pngCode:WHITE = Color.new(255, 255, 255);
BLACK = Color.new(0, 0, 0);
-- Just wrapping text round a screen. Problem. Chops words
Str_BigStringOfTextFromFile = "I can't tell you all how great it is to finally talk about what we've really been building in the XNA team. At GDC this year we showed off managed code running on an Xbox 360. We positioned it as a tool to help the professional industry, which it is. I expect it to be an excellent environment for casual games of all types and it will make inroads into FPS and other big games over time."
Int_TextWidth = 40;
Int_StartLineY = 1;
Int_LineHeight = 9;
while true do
PspPadState = Controls.read();
if PspPadState:start() then
break;
end
if PspPadState:left() and Int_TextWidth > 1 then
Int_TextWidth = Int_TextWidth - 1;
end
if PspPadState:right() and Int_TextWidth < 60 then
Int_TextWidth = Int_TextWidth + 1;
end
screen:clear(WHITE);
-- Get the current length of the screen
local Int_LengthOfString = string.len(Str_BigStringOfTextFromFile);
-- Get the number of lines in the string
local Int_NumberOfLines = math.abs(Int_LengthOfString / Int_TextWidth);
Int_CurrentLine = 0;
for i=0,Int_NumberOfLines do
local Str_Line = string.sub(Str_BigStringOfTextFromFile, (i*Int_TextWidth)+1, ( (i+1)*Int_TextWidth) );
screen:print(1, (Int_StartLineY+(Int_LineHeight*Int_CurrentLine)), Str_Line);
Int_CurrentLine = Int_CurrentLine + 1;
end
screen.waitVblankStart();
screen.flip();
end
I wrote a function to do this a while ago, it might help you. There are tons of comments, so read the ones at the top (just below the function definition) and see if it fits your application. It looks pretty cluttered with all of the in-code comments, but they explain what the code is doing so it should be easy to modify.Zitat:
Zitat von Dr.Gringo
Code:function printMLtext(x, y, str, color, maxlen, vspacing, maxlines)
-- DESCRIPTION
-- Divides strings to allow for easy multiline printing. Designed to be similar in syntax
-- to the screen:print command, and actually can be used as a replacement for the
-- command entirely. Note that this has been tested for the default font and default
-- text size only, although it should work with any mono-spaced font and text size.
-- LMelior 7/18/2006
--
-- INPUTS
-- "x" and "y" - the horizontal and vertical pixel location of the first character.
-- "str" - the input string
-- "color" - the color of the text
-- "maxlen" (optional, but you probably want to set this) - maximum number of
-- -- characters you want to allow on one line.
-- -- -- The default value is 60 (it is the maximum number of characters that will fit on the
-- -- -- -- PSP screen when using the PSP's default font).
-- "vspacing" (optional) - vertical spacing, in pixels, between consecutive lines of text
-- -- The default value is 15 pixels.
-- "maxlines" (optional) - allows you to define the maximum number of lines of text that
-- -- you want to display, and it will wait for player input to continue to the next line. If
-- -- -- the input string exceeds these parameters, it will only print the first screen, but it
-- -- -- -- will return the remainder of the string, so you can easily run it through again
-- -- -- -- -- (see Example 2).
-- -- -- -- -- -- The default value is 18 lines, because along with the other defaults, this
-- -- -- -- -- -- -- will fill up the entire PSP screen with text.
-- Note: if you want to define "vspacing" or "maxlines," you must define the
-- -- parameter(s) before it!
--
-- EXAMPLES
-- Example 1:
-- -- stra="This string is too long to fit on one line if the "
-- -- strb="maximum length of the line is 30 characters."
-- -- printMLtext(230, 10, stra .. strb, Color.new(255,255,255), 30)
--
-- Example 2:
-- str=(very long string)
-- while true do
-- screen:clear()
-- pad=Controls.read()
-- nextpage=printMLtext(230, 10, str, Color.new(255,255,255), 30, 15, 10)
-- if pad:cross() and nextpage~=nil then
-- screen.waitVblankStart(8)
-- str=nextpage
-- end
-- screen.waitVblankStart()
-- screen.flip()
-- end
-- Check for optional input
if maxlen==nil then
maxlen=60
end
if vspacing==nil then
vspacing=15
end
if maxlines==nil then
maxlines=18
end
-- Initialize remainder (will be overwritten if remainder exists)
local remainder=nil
if string.len(str)<=maxlen then -- you didn't need to use this!
screen:print(x,y,str,color)
else
local laststr=str -- initialize variable to hold reduced string
local strk=0 -- loop counter
local substr={} -- initialize substring table
while string.len(laststr)>maxlen do
strk=strk+1
-- Chop off string at the max length plus one and reverse it (if there's a space at maxlen+1 it's OK!)
-- -- This doesn't work on Luaplayer 0.14 for Windows, but it probably works in Luaplayer 0.20:
-- local revstr=string.reverse(string.sub(laststr,1,maxlen))
-- -- This works on Luaplayer 0.14 for windows:
local tmp=string.sub(laststr,1,maxlen+1) -- chops off string at maxlen+1
local revstr="" -- initialize revstr and then build it
for k=1,string.len(tmp) do
revstr=revstr .. string.sub(tmp,-k,-k)
end
tmp=maxlen+1-string.find(revstr," ") -- find the index of last space
-- use index to define the substring
substr[strk]=string.sub(laststr,1,tmp)
-- chop off the first substring to get ready for next loop
laststr=string.sub(laststr,tmp+2)
end
-- add the last part of the string to the table (loop terminates before this step)
strk=strk+1
substr[strk]=laststr
-- check of number of lines will fit on the screen in one printing (remainder = nil)
if strk<=maxlines then
for k=1,strk do
screen:print(x,y+(k-1)*vspacing,substr[k],color)
end
else -- print first screen and then build up remainder string from the unused substrings
for k=1,maxlines do
screen:print(x,y+(k-1)*vspacing,substr[k],color)
end
remainder=substr[maxlines+1]
for k=2,strk-maxlines do
remainder=remainder .. " " .. substr[maxlines+k]
end
end
return remainder
end
end
Thanks guys your help is really appreciated! Sorry to ask such a common question but how do i make the text bigger like 12pts to 16pts...
--Thanks
You can't do that with the in-built font, but if you use your own font you must specify the size.Zitat:
Zitat von Dr.Gringo
Okay, heres my code:
And my error:Code:-- Alien Crosshair Game Screen
-- Completally Coded by Mailas Gonrai
-- Most errors fixed by pjspeedy and yaustar
-- Colors
black = Color.new(0,0,0)
blue = Color.new(191, 255, 195)
yellow = Color.new(255, 255, 0, 200)
green=Color.new(0,255,0, 195)
white = Color.new(255,255,255)
red = Color.new(255,69,0, 195)
-- ETC Variables
displayTime = math.random(2,5)
counter = 0
speed = 1
offscreen = false
pad = Controls.read()
-- Functions
function RandomPoint()
end
math.randomseed(os.time())
-- Images
back = Image.load("./Images/back_game.png")
crosshair = Image.load("./Images/crosshair.png")
border = Image.load("./Images/game_border.png")
alienimage = Image.load("./Images/alien.png")
-- Music
Music.playFile("./Music/grmus.it")
-- Objects
Player = {}
Player.x = 208
Player.y = 112
alien = {}
alien.x = math.random(1,3)
alien.y = math.random (1,3)
alien = {x = 0, y = 200}
x_point = 23
y_point = 83
-- Health Equivelent Options
Player.health = 100
healthbar = {}
healthbar.y = 10
function movePlayer()
if pad:left() then
Player.x = Player.x - 4
end
if pad:right() then
Player.x = Player.x + 4
end
if pad:down() then
Player.y = Player.y + 4
end
if pad:up() then
Player.y = Player.y - 4
end
end
function perimeterSize()
if Player.x > 480 - 64 then
Player.x = 480 - 64
end
if Player.x < 0 then
Player.x = 0
end
if Player.y > 272 - 64 then
Player.y = 272 - 64
end
if Player.y < 0 then
Player.y = 0
end
end
-- THE LOOP!----------------------------------------------------------
while true do
screen:clear()
x_point = math.random(1,480)
y_point = math.random(1,272)
AlienMove()
if alien.x < x_point then
alien.x = alien.x + 2
end
if alien.x > x_point then
alien.x = alien.x - 2
end
if alien.y < y_point then
alien.y = alien.y + 2
end
if alien.y < y_point then
alien.y = alien.y - 2
end
if alien.x == x_point and alien.y == y_point then
RandomPoint()
end
counter = counter + 1
if counter >= displayTime then
alien.x = math.random(1,3)
alien.y = math.random (1,3)
end
if alien.x == 1 then
alien.x = 224
alien.y = 182
end
if alien.x == 2 then
alien.x = 60
alien.y = 132
end
if alien.x == 3 then
alien.x = 404
alien.y = 154
end
displayTime = math.random(500,2000)
counter = 0
end
screen:blit(0,0,back)
screen:blit(alien.x,alien.y,alienimage)
screen:blit(Player.x,Player.y,crosshair)
screen:blit(0,0,border)
screen:fillRect(320,240,Player.health,healthbar.y,green)
screen:print(320,230,Player.health,blue)
movePlayer()
perimeterSize()
alienscreenSize()
if pad:l() then
dofile("menu.lua")
end
screen.waitVblankStart()
screen.flip()
end
Zitat:
error: ./game.lua:159: /<eof>/ expected near /end/
The 'end' there is messing your script up. Remove it.Zitat:
displayTime = math.random(500,2000)
counter = 0
end
Technically, its the end at the very end. Putting that mis-placed end where he does have it, closes the main loop, and until something breaks it, everything beyond it is useless... Removing hte ending end would also solve it ;) Just not how you would want it.
Yes, I assumed he wanted a solution that would help him.Zitat:
Zitat von SG57
Could anyone tell me how to make it so...in the end of your code when if it sais like..press x how do i make it read another text document...
so how do i make it read another text thing after i press abuton...code please =-)
dofile("path.lua")
@ Gonrai
If you wanted you could improve your code's efficiency by combining the functions movePlayer() and perimeterSize() like this:
It's a small improvement, sure, but if your project becomes large, it's the little things like this that you have to watch for and improve.Code:function movePlayer()
if pad:left() and Player.x > 0 then
Player.x = Player.x - 4
end
if pad:right() and Player.x < 480 - 64 then
Player.x = Player.x + 4
end
if pad:down() and Player.y < 272 - 64 then
Player.y = Player.y + 4
end
if pad:up() and Player.y > 0 then
Player.y = Player.y - 4
end
end
@ altunozara
The variable "documenttext" will be one long string containing all of the characters in your text file, including possibly the character representations of escape sequences. Be aware that unless your file is essentially one line (e.g. you didn't press Enter while you were making the text file), you may have some funky characters like that.Code:file=io.open("yourfile.txt","r")
documenttext=file:read("*a")
file:close()
is it possible to clear some part of the screen and not everything
I think it is, but i forgot how.
Heres what I did:
I looked at what emulator guy said and was kinda confused because
1. the math.random on displayTime is 2,5, not 200,5000
2. There is no end under the counter variable.
THen, I looked at SG57's post and I removed the end so it looks like this:
At the end of my script. But heres what happened:Code:if pad:l() then
dofile("menu.lua")
end
screen.waitVblankStart()
screen.flip()
When I loaded my game on my menu script, it just froze.
@hallo007
I'm not sure what you mean...just stop blitting whatever it is to screen? But you could always cheat and make a rectangle to cover up part of the screen.Zitat:
Zitat von hallo007
To cover up the left half. Many coders use a separate image variable that they "build up" and then they only have to blit that to screen. I call mine "prescreen" but you may have seen "offscreen" in some codes:Code:coverup=Image.createEmpty(240,272)
screen:blit(0,0,coverup)
I've been told this is faster than blitting everything directly to the screen buffer, though I've never actually tested this. It just seems cleaner so I always do it.Code:prescreen=Image.createEmpty(480,272)
-- (blit everything to prescreen)
coverup=Image.createEmpty(240,272)
prescreen:blit(0,0,coverup)
screen:blit(0,0,prescreen)
@ Gonrai
Direct from your post above (with indentations left in):Zitat:
Zitat von Gonrai
Sure looks like it to me, and besides SG57 even told you that it wouldn't work (he teases Lua coders for kicks :p).Code:displayTime = math.random(500,2000)
counter = 0
end
index.lua:2: error loading sound? help?!
edit. heres the code
iyk = Sound.load("iyk.wav")
iyk:play()
Music.volume(128)
actually, that presreen thing will use more RAM and be slower, because it has to create the image
i dont get it. why am i getting an error?Zitat:
Zitat von xsorifc28
My code:
It now gives me this error:Code:-- Alien Crosshair Game Screen
-- Completally Coded by Mailas Gonrai
-- Most errors fixed by pjspeedy and yaustar
-- Colors
black = Color.new(0,0,0)
blue = Color.new(191, 255, 195)
yellow = Color.new(255, 255, 0, 200)
green=Color.new(0,255,0, 195)
white = Color.new(255,255,255)
red = Color.new(255,69,0, 195)
-- ETC Variables
displayTime = math.random(2,5)
counter = 0
speed = 1
offscreen = false
pad = Controls.read()
-- Functions
function RandomPoint()
end
math.randomseed(os.time())
-- Images
back = Image.load("./Images/back_game.png")
crosshair = Image.load("./Images/crosshair.png")
border = Image.load("./Images/game_border.png")
alienimage = Image.load("./Images/alien.png")
-- Music
Music.playFile("./Music/grmus.it")
-- Objects
Player = {}
Player.x = 208
Player.y = 112
alien = {}
alien.x = math.random(1,3)
alien.y = math.random (1,3)
alien = {x = 0, y = 200}
x_point = 23
y_point = 83
-- Health Equivelent Options
Player.health = 100
healthbar = {}
healthbar.y = 10
function movePlayer()
if pad:left() then
Player.x = Player.x - 4
end
if pad:right() then
Player.x = Player.x + 4
end
if pad:down() then
Player.y = Player.y + 4
end
if pad:up() then
Player.y = Player.y - 4
end
end
function perimeterSize()
if Player.x > 480 - 64 then
Player.x = 480 - 64
end
if Player.x < 0 then
Player.x = 0
end
if Player.y > 272 - 64 then
Player.y = 272 - 64
end
if Player.y < 0 then
Player.y = 0
end
end
-- THE LOOP!----------------------------------------------------------
while true do
screen:clear()
x_point = math.random(1,480)
y_point = math.random(1,272)
AlienMove()
if alien.x < x_point then
alien.x = alien.x + 2
end
if alien.x > x_point then
alien.x = alien.x - 2
end
if alien.y < y_point then
alien.y = alien.y + 2
end
if alien.y < y_point then
alien.y = alien.y - 2
end
if alien.x == x_point and alien.y == y_point then
RandomPoint()
end
counter = counter + 1
if counter >= displayTime then
alien.x = math.random(1,3)
alien.y = math.random (1,3)
end
if alien.x == 1 then
alien.x = 224
alien.y = 182
end
if alien.x == 2 then
alien.x = 60
alien.y = 132
end
if alien.x == 3 then
alien.x = 404
alien.y = 154
end
screen:blit(0,0,back)
screen:blit(alien.x,alien.y,alienimage)
screen:blit(Player.x,Player.y,crosshair)
screen:blit(0,0,border)
screen:fillRect(320,240,Player.health,healthbar.y,green)
screen:print(320,230,Player.health,blue)
movePlayer()
perimeterSize()
alienscreenSize()
if pad:l() then
dofile("menu.lua")
end
screen.waitVblankStart()
screen.flip()
end
Code:error: ./game.lua:95: attempt to call a global /ALienMove/ ( a nil value)
Error: No script file found.
Press start to Restart.
Alienmove isnt classed as a function
-= Double Post =-
You never did function Alienmove()
You just did Alienmove()
-= Double Post =-
Have you checked that the sound file is not too big or too long for Lua PlayerZitat:
Zitat von xsorifc28
ok heres the deal..
i need some code to make my character shoot a bullet at wherever my crosshair image is. ive tried ALOT and cant get anything working
my character scrolls left to right at the bottom of my screen. The crosshair can go anywhere by using the directional buttons.
so could someone tell me how to do this?
trust me ive studied that, it just shoots them left right up or down
i need mine to shhot to wherever the crosshair is (that could be any x,y position)
make the cross hairs position x and y.
Then just have the bullets final location as X and Y