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; What's the command to make a new file and the command to paste ? TP's idea sounded right to me, ...
-
02-03-2007, 09:23 PM #5521QJ Gamer Blue
- Registriert seit
- Aug 2006
- Ort
- Sydney, Australia
- Beiträge
- 117
- Points
- 4.210
- Level
- 41
- Downloads
- 0
- Uploads
- 0
What's the command to make a new file and the command to paste ?
TP's idea sounded right to me, but it didn't work (see post above Shroom's)
-
02-03-2007, 09:27 PM #5522lol

- Registriert seit
- Aug 2006
- Ort
- Whittier, CA
- Beiträge
- 5.791
- Points
- 20.859
- Level
- 91
- Downloads
- 0
- Uploads
- 0
He just copies the stuff inside a file and paste it inside another file, It doenst make a new file.
His is like copy and overwrite.
-
02-03-2007, 09:31 PM #5523QJ Gamer Blue
- Registriert seit
- Aug 2006
- Ort
- Sydney, Australia
- Beiträge
- 117
- Points
- 4.210
- Level
- 41
- Downloads
- 0
- Uploads
- 0
I think it actually creates the file if it doesn't exist.
Anyway, what is that error !? What does it mean ?
-
02-03-2007, 09:33 PM #5524QJ Gamer Gold
- Registriert seit
- Aug 2006
- Beiträge
- 1.633
- Points
- 11.629
- Level
- 70
- Downloads
- 0
- Uploads
- 0
No, you can make a new file, itll automatically create the file you write to if it isnt there. And thats basically the only way to do it. And by .ext i mean .extension, whatever the extension is.
-
02-03-2007, 09:35 PM #5525lol

- Registriert seit
- Aug 2006
- Ort
- Whittier, CA
- Beiträge
- 5.791
- Points
- 20.859
- Level
- 91
- Downloads
- 0
- Uploads
- 0
Ah, I didn't know that it would automatically make the file, Well im always learning.
-
02-03-2007, 09:35 PM #5526QJ Gamer Blue
- Registriert seit
- Aug 2006
- Ort
- Sydney, Australia
- Beiträge
- 117
- Points
- 4.210
- Level
- 41
- Downloads
- 0
- Uploads
- 0
Lol yeah I know that ext is the extension of the file. I need to know how to fix the error lol ! :)
EDIT: I seem to have fixed that error, a file now appears in the directory I've indicated, however, it is only 1KB in size and contains only 2F6E 0C20 0B20 0220 2F6E (/n . . . /n). I'm not so sure what's wrong...
Zitat von Code
Geändert von TheBressman (02-03-2007 um 11:00 PM Uhr)
-
02-03-2007, 11:22 PM #5527words are stones in my <3

- Registriert seit
- Jul 2005
- Ort
- Spokane
- Beiträge
- 5.008
- Points
- 35.274
- Level
- 100
- My Mood
-
- Downloads
- 1
- Uploads
- 0
I found an interesting set of functions, it allows you to load and save tables to and from files:
http://lua-users.org/wiki/SaveTableToFile
If what your planning on in the end is to save and load tables, as if you were loading a saved game (like level, map, guns, ammo, etc.), than use this.
If not, than your problem there is, im guessing, is 'lines' is simply the hex offset of what line your on... Also, if your tring to copy exactly the same as the file you loaded in, there is no need for hte '\n', as file:read also reads in the newline character, so youd actually be double spacing whatever file your triyng to copy ;)
Try that...Code:function backup( ) System.currentDirectory(" c:/scripts") copy = io.open("something.dat"," r") paste = io.open("something.dat"," w") System.currentDirectory(" c:/") for line in copy:lines( ) do paste:write(line) end end
If it doesnt work, ill take the time to write a working one (im searching ebay for some stuff, but i can take a break ;))
...at what speed must I live.. to be able to see you again?...
Projects
You can support my Open World 3D RPG for PSP by voting for it here
-
02-03-2007, 11:42 PM #5528QJ Gamer Silver

- Registriert seit
- Oct 2006
- Ort
- Pimp'en in the US F#
- Beiträge
- 1.254
- Points
- 7.278
- Level
- 56
- Downloads
- 0
- Uploads
- 0
hey TP,
Im trying to make it so that in a browser, if you click on a directory that contains "index.lua" then it runs that file., Would you, (or any body else) know how to do that?NEWMy New BLOG!NEWThe Wentire Worls in two Sectors....When did I get dev statz?
Spoiler for my PSP homebrewReleases:Spoiler for Great Quotes:
-
02-04-2007, 12:20 AM #5529QJ Gamer Blue
- Registriert seit
- Aug 2006
- Ort
- Sydney, Australia
- Beiträge
- 117
- Points
- 4.210
- Level
- 41
- Downloads
- 0
- Uploads
- 0
@SG57: Cheers, but now I get the same error as before

(error: Attempt to index global 'copy' (a nil value))
EDIT: Lol, this is getting crazy. I fixed it again by getting rid of some stupid spaces I put in, but the file created consists of 4C4F 434B FFFF 32 (LOCK..2).
-
02-04-2007, 12:34 AM #5530words are stones in my <3

- Registriert seit
- Jul 2005
- Ort
- Spokane
- Beiträge
- 5.008
- Points
- 35.274
- Level
- 100
- My Mood
-
- Downloads
- 1
- Uploads
- 0
BlackShark - look at gpack v.2, as TP made that one. But honestly, its not all that hard... This is basically what you are asking for:
Very simpleand easy to make, dont be fooled now.Code:fileSystem = System.listDirectory("ms0:/") file = 1 oldpad = Controls.read() while true do pad = Controls.read() if pad ~= oldpad then if pad:up() and file > 1 then file = file - 1 elseif pad:down() and file < table.getn(fileSystem) then file = file + 1 end if pad:cross() and fileSystem[file].name == "index.lua" then dofile(fileSystem[i].name) end end screen:clear() for i=1,table.getn(fileSystem) do screen:print(10,i*10,fileSystem[i].name,Color.new(255,255,255)) end screen:print(11,file*10,fileSystem[file].name,Color.new(0,255,0)) screen.waitVblankStart() screen.flip() oldpad = pad end
-= Double Post =-
TheBressman - post exactly what you have, as Id like to work with your exact code so I know its not YOU making hte mistake during hte copy&paste.Geändert von SG57 (02-04-2007 um 12:34 AM Uhr) Grund: Automerged Doublepost

...at what speed must I live.. to be able to see you again?...
Projects
You can support my Open World 3D RPG for PSP by voting for it here
-
02-04-2007, 12:38 AM #5531QJ Gamer Blue
- Registriert seit
- Aug 2006
- Ort
- Sydney, Australia
- Beiträge
- 117
- Points
- 4.210
- Level
- 41
- Downloads
- 0
- Uploads
- 0
Alright then.
PS: Weird forum editing is putting a space between " and c in "c:/registry" and "c:/"
Zitat von Code
-
02-04-2007, 02:14 AM #5532QJ Gamer Green
- Registriert seit
- Jul 2006
- Ort
- Middle Europe
- Beiträge
- 1.281
- Points
- 11.800
- Level
- 71
- Downloads
- 0
- Uploads
- 0
the strange thing is, that System.getFreeMemory / 1024 / 1024 will get number 18, but my free memory is 288..... strange o_O
Zitat von TacticalPinguin
[1 Year QJ Member]
[LUA Coder and C Learner]
[Ball Revamped Clone v0.1]
[Phil's Shooting Range v0.3]
[HideFile PRX v2]
[SSR PRX v1.1]
-
02-04-2007, 02:40 AM #5533words are stones in my <3

- Registriert seit
- Jul 2005
- Ort
- Spokane
- Beiträge
- 5.008
- Points
- 35.274
- Level
- 100
- My Mood
-
- Downloads
- 1
- Uploads
- 0
TheBressman - Try this:
Instead of what you have.Code:System.currentDirectory ("c:/registry/")
...at what speed must I live.. to be able to see you again?...
Projects
You can support my Open World 3D RPG for PSP by voting for it here
-
02-04-2007, 03:43 AM #5534QJ Gamer Green
- Registriert seit
- Jul 2006
- Ort
- Middle Europe
- Beiträge
- 1.281
- Points
- 11.800
- Level
- 71
- Downloads
- 0
- Uploads
- 0
PLS can anyone test:
System.getFreeMemory()
in his PSP ????????
does this get free memory on memory stick???
[1 Year QJ Member]
[LUA Coder and C Learner]
[Ball Revamped Clone v0.1]
[Phil's Shooting Range v0.3]
[HideFile PRX v2]
[SSR PRX v1.1]
-
02-04-2007, 03:49 AM #5535words are stones in my <3

- Registriert seit
- Jul 2005
- Ort
- Spokane
- Beiträge
- 5.008
- Points
- 35.274
- Level
- 100
- My Mood
-
- Downloads
- 1
- Uploads
- 0
myschoo - System.getFreeMemory returns the number of bytes free on the memory card. To get kilobytes, divide it by 1000. To get megabytes, divide it by 1000000. So...
Does this or does this not print out how much space you have free, if not, than your memory stick must have some weird formatting or be fake or something...Code:screen:print(0,0,System.getFreeMemory/1000000 .. "megabytes",Color.new(255,0,0))
Geändert von SG57 (02-04-2007 um 04:04 AM Uhr)

...at what speed must I live.. to be able to see you again?...
Projects
You can support my Open World 3D RPG for PSP by voting for it here
-
02-04-2007, 04:23 AM #5536QJ Gamer Green
- Registriert seit
- Dec 2005
- Ort
- Here
- Beiträge
- 2.715
- Points
- 13.310
- Level
- 75
- Downloads
- 0
- Uploads
- 0
it gives you the free space of ram, not the memory stick. lol
edit - i double posted...lolGeändert von EminentJonFrost (02-04-2007 um 05:45 AM Uhr) Grund: Automerged Doublepost
[CENTER][IMG]http://img148.imageshack.us/img148/6985/siglw8.jpg[/IMG][/CENTER]
-
02-04-2007, 04:41 AM #5537QJ Gamer Green
- Registriert seit
- Jul 2006
- Ort
- Middle Europe
- Beiträge
- 1.281
- Points
- 11.800
- Level
- 71
- Downloads
- 0
- Uploads
- 0
omg
i thought so... Lol !
because i have SanDisk Ultra II 100% percent not fake...
thx for explanation Eminent ;)[1 Year QJ Member]
[LUA Coder and C Learner]
[Ball Revamped Clone v0.1]
[Phil's Shooting Range v0.3]
[HideFile PRX v2]
[SSR PRX v1.1]
-
02-04-2007, 05:17 AM #5538words are stones in my <3

- Registriert seit
- Jul 2005
- Ort
- Spokane
- Beiträge
- 5.008
- Points
- 35.274
- Level
- 100
- My Mood
-
- Downloads
- 1
- Uploads
- 0
Hmm... to get free space from memory, maybe... First get how much memory has been used on the memory stick by adding up all the sizes of the files found through a recursive scan of 'ms0:/' and add that to the amount able to be written. So - write to a file, one byte at a time, or 100 bytes at a time, or some interval for how accurate you want to be, until it cant write anymore. Thats my theory...

...at what speed must I live.. to be able to see you again?...
Projects
You can support my Open World 3D RPG for PSP by voting for it here
-
02-04-2007, 05:48 AM #5539QJ Gamer Silver
- Registriert seit
- Oct 2006
- Ort
- 貴方
- Beiträge
- 1.159
- Points
- 7.371
- Level
- 57
- Downloads
- 0
- Uploads
- 0
how to unload images from ram?
-
02-04-2007, 06:09 AM #5540words are stones in my <3

- Registriert seit
- Jul 2005
- Ort
- Spokane
- Beiträge
- 5.008
- Points
- 35.274
- Level
- 100
- My Mood
-
- Downloads
- 1
- Uploads
- 0
headshot - To free anything from RAM, set it's value to nil.
Code:image = Image.load("blah.png") -- allocate memory for image and store image data image = nil -- free image data from ram sound = Sound.load("blah.wav") -- allocate memory for sound and store it sound = nil -- free sound data from memory
...at what speed must I live.. to be able to see you again?...
Projects
You can support my Open World 3D RPG for PSP by voting for it here
-
02-04-2007, 10:35 AM #5541QJ Gamer Silver

- Registriert seit
- Jun 2006
- Ort
- UK
- Beiträge
- 2.326
- Points
- 10.263
- Level
- 67
- Downloads
- 0
- Uploads
- 0
Slightly incorrect. You have to 'nil' or remove all references to the data in RAM.
Zitat von SG57
Code:Blah = Image.load("blah.png"); -- allocate memory for image and store image data Blah2 = Blah; Blah = nil; -- blah.png not flagged for removal for the garbarge collection because Blah2 still references to it Blah2 = nil -- blah.png is now flagged for removel for the garbarge collection because no variables reference to it[Blog] [Portfolio]
[Homebrew Illuminati - Serious Homebrew Development Forums]
[I want to make Homebrew FAQ] [How I broke into the Games Industry]
[Programming Book List] [Programming Article List]
-
02-04-2007, 01:29 PM #5542QJ Gamer Green
- Registriert seit
- Dec 2005
- Ort
- Here
- Beiträge
- 2.715
- Points
- 13.310
- Level
- 75
- Downloads
- 0
- Uploads
- 0
but what if Blah2 wasnt there in the first place? THEN would SG be "fully" correct?
Zitat von yaustar
[CENTER][IMG]http://img148.imageshack.us/img148/6985/siglw8.jpg[/IMG][/CENTER]
-
02-04-2007, 01:34 PM #5543QJ Gamer Silver

- Registriert seit
- Jun 2006
- Ort
- UK
- Beiträge
- 2.326
- Points
- 10.263
- Level
- 67
- Downloads
- 0
- Uploads
- 0
No, he will be partially correct.
Zitat von EminentJonFrost
[Blog] [Portfolio]
[Homebrew Illuminati - Serious Homebrew Development Forums]
[I want to make Homebrew FAQ] [How I broke into the Games Industry]
[Programming Book List] [Programming Article List]
-
02-04-2007, 02:50 PM #5544
- Registriert seit
- Sep 2006
- Beiträge
- 484
- Points
- 8.718
- Level
- 62
- Downloads
- 0
- Uploads
- 0
When i start this it just shows the black screen from when the loop starts. But how come the if statment doesnt worK!!??
-= Double Post =-Code:white =Color.new(255,255,255) red =Color.new(255,0,0) background =Image.load("Background.png") man =Image.load("Man.png") x,y = 240,136; screen:clear() screen:print(0,0,"Connecting...",Color.new(255,0,0)) screen.flip() dofile("netlib.lua") netlib_server = "66.25.53.65" Wlan.init() Wlan.useConnectionConfig(1) System.sleep(50) screen.flip() screen:print(0,10,"Connecting to netlib...",Color.new(255,255,255)) screen.flip() netconnect() System.sleep(50) screen.flip() y = 0 p1 = y netsend("p1",y,"w") netget("p1") while true do screen:clear() netrecv() buffer = netvalue("p1") if buffer == "0" then screen:print(0,0,buffer,red) end screen.waitVblankStart(); screen.flip() end
That is just pat of my game by the way
-= Double Post =-
Anyone??Geändert von pspfreak9 (02-04-2007 um 02:50 PM Uhr) Grund: Automerged Doublepost
-
02-04-2007, 03:07 PM #5545QJ Gamer Green
- Registriert seit
- Dec 2005
- Ort
- Here
- Beiträge
- 2.715
- Points
- 13.310
- Level
- 75
- Downloads
- 0
- Uploads
- 0
maybe cause 'buffer' does not equal zero...lol
from what you posted, it looks like theres something going in netlib.lua affecting 'buffer'.
(but i cant tell since buffer doesnt even show up anywhere in the script you put up before that 'if' loop)[CENTER][IMG]http://img148.imageshack.us/img148/6985/siglw8.jpg[/IMG][/CENTER]
-
02-04-2007, 03:13 PM #5546
- Registriert seit
- Sep 2006
- Beiträge
- 484
- Points
- 8.718
- Level
- 62
- Downloads
- 0
- Uploads
- 0
Buffer is netvalue("p1") and i sent 0 to p1 read from the begining
-
02-04-2007, 03:17 PM #5547QJ Gamer Green
- Registriert seit
- Dec 2005
- Ort
- Here
- Beiträge
- 2.715
- Points
- 13.310
- Level
- 75
- Downloads
- 0
- Uploads
- 0
if by some slim chance, your problem wasnt from net coding, i mightve been able to help. but i'm no use here since it is.

sorry.[CENTER][IMG]http://img148.imageshack.us/img148/6985/siglw8.jpg[/IMG][/CENTER]
-
02-04-2007, 03:22 PM #5548
- Registriert seit
- Sep 2006
- Beiträge
- 484
- Points
- 8.718
- Level
- 62
- Downloads
- 0
- Uploads
- 0
ok thx for trying anyone have experinece coding with netlib
-
02-04-2007, 10:17 PM #5549words are stones in my <3

- Registriert seit
- Jul 2005
- Ort
- Spokane
- Beiträge
- 5.008
- Points
- 35.274
- Level
- 100
- My Mood
-
- Downloads
- 1
- Uploads
- 0
pspfreak - Your comparing "0" to buffer. Your saying you sent the value 0, not the char '0', so it shouldnt run as 0x00 is differnent than 0x30.

...at what speed must I live.. to be able to see you again?...
Projects
You can support my Open World 3D RPG for PSP by voting for it here
-
02-05-2007, 12:24 AM #5550QJ Gamer Silver

- Registriert seit
- Oct 2006
- Ort
- Pimp'en in the US F#
- Beiträge
- 1.254
- Points
- 7.278
- Level
- 56
- Downloads
- 0
- Uploads
- 0
Aright, im Editing TP's browser, and want to make it so that if you click on a directory with "index.lua" inside it then it launches the index.lua.
This is what I have so far?
if pad:cross() and oldpad:cross() ~= pad:cross() and bfold == true and fl[s].directory == true then
System.currentDirectory(f l[s].name)
s = 1
fl=System.listDirectory()
nf=table.getn(fl)
elseif pad:cross() and oldpad:cross() ~= pad:cross() and bfold == true and fl[s].directory == true and string.lower(fl[s].name) == "index.lua" then
dofile("index.lua")
System.currentDirectory(" ./../..")
endNEWMy New BLOG!NEWThe Wentire Worls in two Sectors....When did I get dev statz?
Spoiler for my PSP homebrewReleases:Spoiler for Great Quotes:


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