QJ.NET | Videos | Forums | iPhone | MMORPG | Nintendo DS | Wii | PlayStation 3 | PSP | Xbox 360 | PC | Downloads | Contact Us
Forums | Gaming News | Videos | Downloads | Today's Posts | Mark Forums Read | Chat | FAQ | Members List | Contact

QJ.net Game Discussion - PSP, Xbox, Wii, PS3, PSP Homebrew, and PSP Guides

Go Back   QJ.net Game Discussion - PSP, Xbox, Wii, PS3, PSP Homebrew, and PSP Guides > Developers Corner > PSP Development, Hacks, and Homebrew > PSP Development Forum
The above video goes away if you are a member and logged in, so log in now!

A few more questions about Lua...

This is a discussion on A few more questions about Lua... within the PSP Development Forum forums, part of the PSP Development, Hacks, and Homebrew category; Hey all, It's me. Again. I'm having some trouble with tables. There's just something about them that I'm not getting. ...

Reply
 
LinkBack Thread Tools
Old 02-17-2008, 09:34 PM   #1
 
spykr's Avatar
 
Join Date: Feb 2008
Posts: 8
Trader Feedback: 0
Default A few more questions about Lua...

Hey all,
It's me. Again.
I'm having some trouble with tables. There's just something about them that I'm not getting. If y'all knew of any good tutorials for tables used in conjunction with for loops, please let me know.
Also, is using lua less RAM-efficient than compiling an EBOOT file using C/C++?
If so, how much?

Thanks for all the help, y'all,
spykr


(I just had to fit that smilie in here somewhere. Haha.)
spykr is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 02-18-2008, 06:34 AM   #2
 
bumuckl's Avatar
 
Join Date: Jul 2007
Location: Bavaria!
Posts: 162
Trader Feedback: 0
Default

Whats your Problem with tables?

white = Color.new(255,255,255)
table = {"h","a","l","l","o"}


while true do
for i=1, table.getn(table) do
screenrint(10,10*i,tabl e[i],white)
end
screen.flip()
screen.waitVblankStart()
end
bumuckl is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 02-18-2008, 06:46 AM   #3
 
EminentJonFrost's Avatar
 
Join Date: Dec 2005
Location: Here
Posts: 2,715
Trader Feedback: 0
Default

Quote:
Originally Posted by bumuckl
Whats your Problem with tables?

white = Color.new(255,255,255)
table = {"h","a","l","l","o"}


while true do
for i=1, table.getn(table) do
screenrint(10,10*i,tabl e[i],white)
end
screen.flip()
screen.waitVblankStart()
end
Just gonna explain that a bit more.

Code:
table.getn(table)
That means the # of variables in table "table"

The For loop repeats the instructions for all the values starting from 1 to the number of variables in the table.

Code:
screen:print(10,10*i,table[i],white)
So it will print the 1st letter at (10, 10), then the 2nd letter at (10, 20) (see the "10*i" in the Y coordinate?), 3rd at (10, 30), so on.

The result will look like this:

h.........a.........l.... .....l.........o (pretend the periods aren't there)
__________________
[CENTER][IMG]http://img148.imageshack.us/img148/6985/siglw8.jpg[/IMG][/CENTER]
EminentJonFrost is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 02-18-2008, 06:58 AM   #4
Ænima
 
Judas's Avatar
 
Join Date: Sep 2007
Posts: 587
Trader Feedback: 0
Default

Don't forget that tables can contain multiple dimensions and any type.
Code:
table = {}
table[1] = "First Entry In Table"
table[2] = 492.19

table[3] = {}
table[3][1] = "Table[3] is a table on it's own"
table[3][2] = Image.load("Image.png")

table[3][3] = {}
table[3][3][1]"As many dimensions as you want"
table[3][3][2] = Color.new(255,0,0)

table[3][3][3] = {}
table[3][3][1] = "They get confusing after they get so big though"
table[3][3][2] = table[2] * 42
-= Double Post =-
Oh, and yes, Lua usually takes up more RAM, as it's loading every function Lua can handle, even if you're not using it.
__________________
[IMG]http://upload.wikimedia.org/wikipedia/commons/thumb/c/c5/Zoso.svg/744px-Zoso.svg.png[/IMG]

Looking for some good C programming tutorials for the PSP? Look no further! [URL="http://psp-coding.com/"]PSP-Coding.com[/URL] is your source for all your PSP coding needs.

Last edited by Judas; 02-18-2008 at 07:00 AM.. Reason: Automerged Doublepost
Judas is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 02-18-2008, 08:35 AM   #5
 
Join Date: Jan 2008
Posts: 612
Trader Feedback: 0
Default

http://lua-users.org/wiki/TutorialDirectory
TurtlesPwn is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 02-18-2008, 10:19 AM   #6
 
spykr's Avatar
 
Join Date: Feb 2008
Posts: 8
Trader Feedback: 0
Default

Quote:
Originally Posted by Judas
Don't forget that tables can contain multiple dimensions and any type.
Code:
table = {}
table[1] = "First Entry In Table"
table[2] = 492.19

table[3] = {}
table[3][1] = "Table[3] is a table on it's own"
table[3][2] = Image.load("Image.png")

table[3][3] = {}
table[3][3][1]"As many dimensions as you want"
table[3][3][2] = Color.new(255,0,0)

table[3][3][3] = {}
table[3][3][1] = "They get confusing after they get so big though"
table[3][3][2] = table[2] * 42
-= Double Post =-
Oh, and yes, Lua usually takes up more RAM, as it's loading every function Lua can handle, even if you're not using it.
Ah! now I see. I just couldn't get my mind around the concept for some reason. What I really needed is a multi-level table that contains the positions of each object to be printed to the screen.

And would it be worth it to rewrite my code in c/c++ for the extra RAM? Because I'm afraid that this program will take up too much of the mem.

Last edited by spykr; 02-18-2008 at 11:45 AM..
spykr is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Tags
lua , questions

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off



All times are GMT -8. The time now is 02:46 PM.



Use of this Web site constitutes acceptance of the TERMS & CONDITIONS and PRIVACY POLICY
Copyright © 2009, QJ.NET. All Rights Reserved.
Contact Us