Zeige Ergebnis 3.271 bis 3.300 von 10238
Lua Programming Help Thread
This is a discussion on Lua Programming Help Thread within the PSP Development Forum forums, part of the PSP Development, Hacks, and Homebrew category; well have you put a number in the highscore text...
-
08-17-2006, 08:59 AM #3271QJ Gamer Green
- Registriert seit
- Oct 2005
- Ort
- Scotland, UK
- Beiträge
- 571
- Points
- 7.057
- Level
- 55
- Downloads
- 0
- Uploads
- 0
well have you put a number in the highscore text
-
08-17-2006, 09:00 AM #3272QJ Gamer Green
- Registriert seit
- Jun 2006
- Ort
- London
- Beiträge
- 645
- Points
- 6.256
- Level
- 51
- Downloads
- 0
- Uploads
- 0
Im not great with lua but you opened the file with an "r" tag? Wont that mean you can only read?
Zitat von JaSo PsP
[b][center]
[URL="http://forums.qj.net/showthread.php?t=65032"][SIZE="3"][COLOR="Blue"]Omicron[/COLOR] - [COLOR="DeepSkyBlue"]A hacking simulation game for the PSP[/COLOR][/SIZE][/URL]
[url=http://profile.mygamercard.net/dr+nutterbutter][img]http://card.mygamercard.net/gbar/live/dr+nutterbutter.gif[/img][/url][/b][/center]
-
08-17-2006, 09:00 AM #3273Your Fate is Grim...

- Registriert seit
- Oct 2005
- Beiträge
- 2.269
- Points
- 11.640
- Level
- 70
- Downloads
- 0
- Uploads
- 0
NVM, read mark.sarpkys post.
Zitat von JaSo PsP
--------------------------------------------------------------------------------------
-
08-17-2006, 09:07 AM #3274QJ Gamer Green
- Registriert seit
- Apr 2006
- Ort
- England ~¦¦¦|+|¦¦¦~
- Beiträge
- 1.112
- Points
- 9.165
- Level
- 64
- My Mood
-
- Downloads
- 0
- Uploads
- 0
here:
-= Double Post =-Code:levelTimer = Timer.new(100000) levelTimer:start() red = Color.new(255,0,0) background = Image.load("cloud.png") smiley = Image.load("smile.png") sad = Image.load("sad.png") math.randomseed(os.time()) rx = math.random(0,442) ry = math.random(0,234) highscore = io.open("hiscore.txt","r") whighscore = io.open("hiscore.txt","w") theHighScore = highscore:read() boost = 2000 score = 0 x = 0 y = 5 TotalTimeLimit = 130
yes i have, it was 0 but i changed it to 10 and thats all thats there.
Zitat von mark.sparky
cmon help me!!!Geändert von JaSo PsP (08-17-2006 um 09:18 AM Uhr) Grund: Automerged Doublepost
...Just Returned To The Scene...
-
08-17-2006, 09:32 AM #3275QJ Gamer Silver

- Registriert seit
- Jun 2006
- Ort
- UK
- Beiträge
- 2.326
- Points
- 10.263
- Level
- 67
- Downloads
- 0
- Uploads
- 0
The problem here is that when you read from a file, its reading it in as a string, not a number. Therefore you cannot compare a number with the string.
-
08-17-2006, 09:33 AM #3276QJ Gamer Green
- Registriert seit
- Apr 2006
- Ort
- England ~¦¦¦|+|¦¦¦~
- Beiträge
- 1.112
- Points
- 9.165
- Level
- 64
- My Mood
-
- Downloads
- 0
- Uploads
- 0
so how can i save a high score?
Zitat von head_54us
...Just Returned To The Scene...
-
08-17-2006, 09:36 AM #3277QJ Gamer Silver

- Registriert seit
- Jun 2006
- Ort
- UK
- Beiträge
- 2.326
- Points
- 10.263
- Level
- 67
- Downloads
- 0
- Uploads
- 0
At the moment I am looking for a string to number/integer function in Lua (I really don't fancy writing one myself) but can't find any.
-
08-17-2006, 09:42 AM #3278QJ Gamer Green
- Registriert seit
- Apr 2006
- Ort
- England ~¦¦¦|+|¦¦¦~
- Beiträge
- 1.112
- Points
- 9.165
- Level
- 64
- My Mood
-
- Downloads
- 0
- Uploads
- 0
k, im gonna fishish off the game and post it without the hiscore thing.
Zitat von head_54us
-= Double Post =-
what do i write to make the whole thing restart? well?Geändert von JaSo PsP (08-17-2006 um 09:48 AM Uhr) Grund: Automerged Doublepost
...Just Returned To The Scene...
-
08-17-2006, 09:48 AM #3279QJ Gamer Silver

- Registriert seit
- Jun 2006
- Ort
- UK
- Beiträge
- 2.326
- Points
- 10.263
- Level
- 67
- Downloads
- 0
- Uploads
- 0
Note that this code is for a standalone project only. You MUST press start to exit otherwise the file doesn't not get saved:
Code:WHITE = Color.new(255, 255, 255) highscore = io.open("hiscore.txt","r") theHighScore = highscore:read("*number") highscore:close() currentScore = 0 while true do PspPadState = Controls.read(); if PspPadState:start() then break; end if PspPadState:circle() then currentScore = currentScore + 1 end screen:clear(WHITE) screen:print(1,1, "High Score " .. theHighScore) screen:print(1,9, "Current Score " .. currentScore) screen.waitVblankStart(); screen.flip(); end if currentScore > theHighScore then highscore = io.open("hiscore.txt","w") highscore:write(currentScore) highscore:close() end
-
08-17-2006, 10:02 AM #3280QJ Gamer Green
- Registriert seit
- Apr 2006
- Ort
- England ~¦¦¦|+|¦¦¦~
- Beiträge
- 1.112
- Points
- 9.165
- Level
- 64
- My Mood
-
- Downloads
- 0
- Uploads
- 0
it works but the mem stik light keeps flashing, when i exit the app after bout 10 seconds of flashing it has saved the score?
Zitat von head_54us
-= Double Post =-
sorted it out with the flashing..Geändert von JaSo PsP (08-17-2006 um 10:02 AM Uhr) Grund: Automerged Doublepost
...Just Returned To The Scene...
-
08-17-2006, 10:03 AM #3281QJ Gamer Silver

- Registriert seit
- Jun 2006
- Ort
- UK
- Beiträge
- 2.326
- Points
- 10.263
- Level
- 67
- Downloads
- 0
- Uploads
- 0
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.
-
08-17-2006, 10:29 AM #3282QJ Gamer Green
- Registriert seit
- Apr 2006
- Ort
- England ~¦¦¦|+|¦¦¦~
- Beiträge
- 1.112
- Points
- 9.165
- Level
- 64
- My Mood
-
- Downloads
- 0
- Uploads
- 0
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 von head_54us
-= Double Post =-
finished game...Geändert von JaSo PsP (08-17-2006 um 10:29 AM Uhr) Grund: Automerged Doublepost
...Just Returned To The Scene...
-
08-17-2006, 12:23 PM #3283QJ Gamer Bronze
- Registriert seit
- Feb 2006
- Ort
- Earth, UK
- Beiträge
- 457
- Points
- 5.924
- Level
- 49
- Downloads
- 0
- Uploads
- 0
restart button
put this in/near your game over function/loop
Code:if pad:triangle() then dofile(".index.lua") end<<Put A message Here>>
<<Just made another rubbish website visit it here.>>
-
08-18-2006, 08:49 PM #3284QJ Gamer Blue
- Registriert seit
- Aug 2006
- Beiträge
- 145
- Points
- 4.580
- Level
- 43
- Downloads
- 0
- Uploads
- 0
I keep getting this weird error:
Heres my code:
Heres my error:-- 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
rint(208,96,"Start Game",white)
screen
rint(128,144,"Credits",wh ite)
screen
rint(208,192,"How To Play",white)
screen
rint(288,144,"Exit To XMB",white)
-- These make it so when the variable "current" changes
-- so does the current menu selection
if current == 1 then
screen
rint(208,96,"Start Game",red)
screen:blit(208,97,arrow)
end
if current == 2 then
screen
rint(128,144,"Credits",re d)
screen:blit(128,145,arrow )
end
if current == 3 then
screen
rint(208,192,"How To Play",red)
end
if current == 4 then
screen
rint(288,144,"Exit 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/
??????
-
08-18-2006, 08:53 PM #3285I'm Baaaack!

- Registriert seit
- May 2006
- Ort
- Nowhere
- Beiträge
- 2.186
- Points
- 17.067
- Level
- 83
- Downloads
- 0
- Uploads
- 0
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.Geändert von ARza (08-18-2006 um 08:53 PM Uhr) Grund: Automerged Doublepost

-
08-18-2006, 09:42 PM #3286QJ Gamer Blue
- Registriert seit
- Aug 2006
- Beiträge
- 145
- Points
- 4.580
- Level
- 43
- Downloads
- 0
- Uploads
- 0
Hey guys, sorry for that long code, I figured out the problem, I just forgot to put the () infront of my pads

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?
-
08-18-2006, 11:07 PM #3287Developer

- Registriert seit
- Jun 2006
- Ort
- USA, Virginia
- Beiträge
- 580
- Points
- 5.650
- Level
- 48
- Downloads
- 0
- Uploads
- 0
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.
-
08-19-2006, 12:58 AM #3288QJ Gamer Green
- Registriert seit
- Apr 2006
- Ort
- England ~¦¦¦|+|¦¦¦~
- Beiträge
- 1.112
- Points
- 9.165
- Level
- 64
- My Mood
-
- Downloads
- 0
- Uploads
- 0
where does it actually define the variable 'current'?
...Just Returned To The Scene...
-
08-22-2006, 08:42 AM #3289
- Registriert seit
- Jul 2006
- Beiträge
- 36
- Points
- 3.957
- Level
- 40
- Downloads
- 0
- Uploads
- 0
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
-
08-22-2006, 09:00 AM #3290QJ Gamer Green
- Registriert seit
- Jun 2006
- Ort
- London
- Beiträge
- 645
- Points
- 6.256
- Level
- 51
- Downloads
- 0
- Uploads
- 0
@ 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
[b][center]
[URL="http://forums.qj.net/showthread.php?t=65032"][SIZE="3"][COLOR="Blue"]Omicron[/COLOR] - [COLOR="DeepSkyBlue"]A hacking simulation game for the PSP[/COLOR][/SIZE][/URL]
[url=http://profile.mygamercard.net/dr+nutterbutter][img]http://card.mygamercard.net/gbar/live/dr+nutterbutter.gif[/img][/url][/b][/center]
-
08-22-2006, 09:03 AM #3291
- Registriert seit
- Jul 2006
- Beiträge
- 36
- Points
- 3.957
- Level
- 40
- Downloads
- 0
- Uploads
- 0
ok thnx ill try that
-
08-22-2006, 09:20 AM #3292QJ Gamer Silver
- Registriert seit
- Jun 2006
- Ort
- Removable Disk (G:)
- Beiträge
- 1.698
- Points
- 13.092
- Level
- 74
- Downloads
- 0
- Uploads
- 0
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?
[_ıииeя_тυяκ*_]
Turkish Power >_<
-
08-22-2006, 09:29 AM #3293
- Registriert seit
- Jul 2006
- Beiträge
- 36
- Points
- 3.957
- Level
- 40
- Downloads
- 0
- Uploads
- 0
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
-
08-22-2006, 09:44 AM #3294QJ Gamer Green
- Registriert seit
- Jun 2006
- Ort
- London
- Beiträge
- 645
- Points
- 6.256
- Level
- 51
- Downloads
- 0
- Uploads
- 0
Yay, i actually used my skills for good!
Zitat von jamz1825
[b][center]
[URL="http://forums.qj.net/showthread.php?t=65032"][SIZE="3"][COLOR="Blue"]Omicron[/COLOR] - [COLOR="DeepSkyBlue"]A hacking simulation game for the PSP[/COLOR][/SIZE][/URL]
[url=http://profile.mygamercard.net/dr+nutterbutter][img]http://card.mygamercard.net/gbar/live/dr+nutterbutter.gif[/img][/url][/b][/center]
-
08-22-2006, 01:17 PM #3295
When you screen
rint 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.
-
08-22-2006, 05:37 PM #3296I'm Baaaack!

- Registriert seit
- May 2006
- Ort
- Nowhere
- Beiträge
- 2.186
- Points
- 17.067
- Level
- 83
- Downloads
- 0
- Uploads
- 0
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
-
08-22-2006, 05:40 PM #3297QJ Gamer Silver

- Registriert seit
- Jun 2006
- Ort
- UK
- Beiträge
- 2.326
- Points
- 10.263
- Level
- 67
- Downloads
- 0
- Uploads
- 0
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.
Code: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
-
08-22-2006, 06:04 PM #3298Developer

- Registriert seit
- Jul 2006
- Beiträge
- 205
- Points
- 4.318
- Level
- 41
- Downloads
- 0
- Uploads
- 0
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 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
-
08-22-2006, 07:54 PM #3299
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
-
08-22-2006, 09:33 PM #3300Developer

- Registriert seit
- Feb 2006
- Ort
- Tauranga, New Zealand
- Beiträge
- 355
- Points
- 5.162
- Level
- 46
- Downloads
- 0
- Uploads
- 0
You can't do that with the in-built font, but if you use your own font you must specify the size.
Zitat von Dr.Gringo



LinkBack URL
About LinkBacks
Mit Zitat antworten

Hello everyone I am new here and I am glad to be part of this amazing community and I think there...
New to forum