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; Zitat von PSPJunkie_ And? It was the exact same thing... @[email protected] I bet you $10 that if you tried your ...
-
04-24-2007, 06:19 PM #7081QJ Gamer Blue
- Registriert seit
- Jun 2006
- Ort
- Tokoroa, New Zealand
- Beiträge
- 103
- Points
- 4.412
- Level
- 42
- Downloads
- 0
- Uploads
- 0
I bet you $10 that if you tried your code in Luaplayer, it would give you an error.
Zitat von PSPJunkie_
-
04-24-2007, 06:40 PM #7082QJ Gamer Green
- Registriert seit
- Dec 2006
- Ort
- main();
- Beiträge
- 1.071
- Points
- 11.300
- Level
- 70
- Downloads
- 0
- Uploads
- 0
What? The,
I wasn't sure so I looked in the tut's on PSP-Programming for the syntax and that was it...Code:screen:clear(Color.new(0, 0, 0))
-
04-24-2007, 08:33 PM #7083words 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
PSPJunkie_ - screen:clear( [Color] ). Without a parameter, its black. With, it requires a Color class (Color.new(r,g,b[,a])), so yours was correct. However, you have a typo... screenrint(200,100, <snip>)?

...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
-
04-25-2007, 05:02 AM #7084QJ Gamer Gold
- Registriert seit
- Aug 2006
- Beiträge
- 1.633
- Points
- 11.629
- Level
- 70
- Downloads
- 0
- Uploads
- 0
Because they didn't check off "Disable smilies in text" so :p turned into a smiley face.
-
04-25-2007, 07:38 AM #7085
will send wen be on pc
Zitat von emericaska8r
-
04-25-2007, 08:41 AM #7086QJ Gamer Blue
- Registriert seit
- Apr 2007
- Ort
- Relative
- Beiträge
- 135
- Points
- 3.679
- Level
- 38
- Downloads
- 0
- Uploads
- 0
How can I declare a table that doesn't have to be initialized all at once (it should be at runtime) and can be accessed like
Because when I do it likeCode:table[1].arg1 = something table[1].arg2 = something table[2].arg1 = something ...
I get error "attempt to index filed '?' <a nil value>"Code:table = {arg1, arg2}
I don't want to do it like
because I don't know how long the table should be when it is created.Code:table = {{arg1, arg2},{arg1, arg2},{arg1, arg2}...
Basically I want to create something like a class that can just be filled with values latter.
Sorry if the answer is obvious. :)
-
04-25-2007, 09:22 AM #7087Developer

- Registriert seit
- Oct 2006
- Ort
- San Diego
- Beiträge
- 177
- Points
- 4.205
- Level
- 41
- Downloads
- 0
- Uploads
- 0
unlike c, everything in lua is declared at runtime. So once you declare a table, ie table = {} , then you can index it however you like, whenever you like.
-
04-25-2007, 09:39 AM #7088QJ Gamer Blue
- Registriert seit
- Apr 2007
- Ort
- Relative
- Beiträge
- 135
- Points
- 3.679
- Level
- 38
- Downloads
- 0
- Uploads
- 0
So
should work? Because it doesn't.Code:tab = {} for i = 0, 50 do tab[i].arg1 = something tab[i].arg2 = somethingother end
How would I make this work?
-
04-25-2007, 09:50 AM #7089Developer

- Registriert seit
- Oct 2006
- Ort
- San Diego
- Beiträge
- 177
- Points
- 4.205
- Level
- 41
- Downloads
- 0
- Uploads
- 0
each index has to be declared a table if you want to index it further, so
tab = {}
for i =1,50 do
tab[i] = {}
tab[i].arg1 = something
...ect...
end
That would work
-
04-25-2007, 09:58 AM #7090QJ Gamer Blue
- Registriert seit
- Apr 2007
- Ort
- Relative
- Beiträge
- 135
- Points
- 3.679
- Level
- 38
- Downloads
- 0
- Uploads
- 0
Thanks,
while I was waiting for your reply I played with the code around and found that this works
Which is basically same as you said.Code:tab = {} for i = 1, 20 do tab[i] = {arg1 = 7, arg2 = 8} end
-
04-25-2007, 11:44 AM #7091QJ Gamer Green
- Registriert seit
- Dec 2006
- Ort
- main();
- Beiträge
- 1.071
- Points
- 11.300
- Level
- 70
- Downloads
- 0
- Uploads
- 0
It's good there was typo. That why it wasn't as easy as one idiot copying and pasting code. I was trying to help, too. Do people always have an aditude in here?
Zitat von SG57
-
04-25-2007, 02:38 PM #7092QJ Gamer Gold
- Registriert seit
- Nov 2006
- Ort
- ...
- Beiträge
- 2.080
- Points
- 11.942
- Level
- 71
- Downloads
- 0
- Uploads
- 0
well sometimes TP does, and i never seen SG with one, but Youresam does, and that is because he's tired of answering the same question
-
04-25-2007, 02:52 PM #7093QJ Gamer Blue
- Registriert seit
- Jul 2006
- Beiträge
- 132
- Points
- 4.296
- Level
- 41
- Downloads
- 0
- Uploads
- 0
can someone pls help?
Zitat von cruisx
-
04-25-2007, 02:57 PM #7094Developer

- Registriert seit
- Oct 2006
- Ort
- San Diego
- Beiträge
- 177
- Points
- 4.205
- Level
- 41
- Downloads
- 0
- Uploads
- 0
do you want to use pics in your pic folder or have the user stash their pics into your lua folder? This is really simple to do, you might want to look for some tuts on file browsing and controls.
-
04-25-2007, 03:31 PM #7095QJ Gamer Blue
- Registriert seit
- Jul 2006
- Beiträge
- 132
- Points
- 4.296
- Level
- 41
- Downloads
- 0
- Uploads
- 0
Zitat von KleptoOne
i want to use the pics in the lua folder, can someone help me with the code or possiably link me to some tuts so that i can do it =). Thx for the rply Kelp
-
04-25-2007, 03:31 PM #7096Developer

- Registriert seit
- Oct 2006
- Ort
- San Diego
- Beiträge
- 177
- Points
- 4.205
- Level
- 41
- Downloads
- 0
- Uploads
- 0
To be fair to Yoursam, there are a lot of repeated questions that get ask that are super simple to figure out if you stop to think about it for a moment. If really need help, then you should have some code posted showing that you at least made an attempt to figure the problem out. Plus with code, it's alot easier to determine what you are attempting to do.
Zitat von PSPJunkie_
-
04-25-2007, 04:11 PM #7097Developer

- Registriert seit
- Oct 2006
- Ort
- San Diego
- Beiträge
- 177
- Points
- 4.205
- Level
- 41
- Downloads
- 0
- Uploads
- 0
check this out (system portion specifically)
Zitat von cruisx
http://wiki.ps2dev.org/psp:lua_player:functions#system
It would assume a certain level of familiarity with tables. If you can't figure out how to apply it, I know I have a simple file browser programmed somewhere that I'll post, I just have to find it.
-
04-25-2007, 05:15 PM #7098
Hey guys i was wondering if there are any tutorials on making a file browser. I need it for my project i am working on. I want to learn how to make one then make my own to go with what i need. It should end up being a lot different then the tutorial one though.
Thanks Bob Hoil
-
04-25-2007, 05:21 PM #7099lol

- Registriert seit
- Aug 2006
- Ort
- Whittier, CA
- Beiträge
- 5.791
- Points
- 20.859
- Level
- 91
- Downloads
- 0
- Uploads
- 0
I don't think theirs a tutorial but check outs TacticalPenguin's file browser in the lua snippets thread.
-
04-25-2007, 07:07 PM #7100
Ok thanks a lot. I appreciate it a ton.
-
04-25-2007, 07:53 PM #7101QJ Gamer Gold
- Registriert seit
- Aug 2006
- Beiträge
- 1.633
- Points
- 11.629
- Level
- 70
- Downloads
- 0
- Uploads
- 0
NOEZ! That file browser is ancient and horribiblistical. I'll find the much more uberer one I made for my shell tomorrow just remind me and I'll show it to you. (im about ready to go to sleep so not now)
-= Double Post =-
Oh and here's a general idea for the concept of it:
etc then blit the image and just make it so when you press l/r it changes the image and checks that its an image. play with it and see what you can come up with.Code:--get the directory listing blah = System.listDirectory("./pictures") --remove the "." and ".." files table.remove(blah,1) table.remove(blah,1) --get the number of pics for i = 1, table.getn(blah) do if string.lower(string.sub(blah[i].name,-4)) == (".png" or ".jpg") then blah[i].ispic = true else blah[i].ispic = false end end _currentpic = 1 if pad:r() and not oldpad:r() then _currentpic = _currentpic + 1 elseif pad:l() and not oldpad:l() then _currentpic = _currentpic - 1 end if _currentpic ~= _oldcurrentpic and blah[i].ispic then _pic = Image.load("./pictures/"..blah[i].name) elseif _currentpic ~= _oldcurrentpic then _currentpic = _currentpic + (_oldcurrentpic - _currentpic) endGeändert von TacticalPinguin (04-25-2007 um 08:15 PM Uhr) Grund: Automerged Doublepost
-
04-25-2007, 08:21 PM #7102words 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
TP - Have you considered using a OO approach to your programming? Nothing's wrong with what you currently do, but I highly recommend it (that doesnt mean much though, as ive yet to release anything decent using it (anything actually :P) but that will change soon).

...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
-
04-26-2007, 09:57 AM #7103
hi wy math.random is just giving me int values? is there way to get floats?
-
04-26-2007, 12:19 PM #7104
i don't know, i was fiddling with it, but nothing :Cry:
you could use math.random for the integer part, then the decimal part, and then put them together, but that would be stupid
-
04-26-2007, 01:39 PM #7105
im doing this
Zitat von emericaska8r
a=0.5*100
random(a-10,a+10)
a=a/100
soo i got a random float
-
04-26-2007, 02:04 PM #7106
lol, it's easier to just do this:
var = math.random(100)+math.ran dom()
-
04-26-2007, 02:36 PM #7107Developer

- Registriert seit
- Jul 2006
- Beiträge
- 205
- Points
- 4.318
- Level
- 41
- Downloads
- 0
- Uploads
- 0
That might work.Code:function math.randfloat(low, high) x=math.random()*(high-low)+low return x end
-
04-26-2007, 03:31 PM #7108
well the fact is that i have a fl value then ineed a range fl values and my original fl is the center thats wi do that ,now wiLL that function works for me ? im on_psp_far_from_pc so cant test
-
04-26-2007, 05:09 PM #7109
well if you take my version and just use a range in the first section like this:
var = math.random(-10, 10)+math.random()
you will get a float between -10 and 10
if you want to set the range based on your original value, then do it like this:
var = math.random( (orig-10), (orig+10) )+math.random()
-
04-26-2007, 06:55 PM #7110words 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
To make it more portable, here's a function for what you want:
I believe that will work, however, i havent tested it.Code:function randomFloatFromOrigin(center,range) return ( math.random( (center-range), (center+range) )+math.random() ) end
...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


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