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!

Small LUA question

This is a discussion on Small LUA question within the PSP Development Forum forums, part of the PSP Development, Hacks, and Homebrew category; If i have variables named 1, 2, 3, 4, and 5 how can i make it print one of those ...

Reply
 
LinkBack Thread Tools
Old 03-16-2006, 06:14 AM   #1

Gutya
 

 
Join Date: Feb 2006
Posts: 2,398
Trader Feedback: 0
Default Small LUA question

If i have variables named 1, 2, 3, 4, and 5 how can i make it print one of those variables at random when x is pressed.
__________________
D:
Gutya is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 03-16-2006, 06:15 AM   #2

Gutya
 

 
Join Date: Feb 2006
Posts: 2,398
Trader Feedback: 0
Default

Oh sorry, forgot about the LUA help sticky, just close this.
__________________
D:
Gutya is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 03-16-2006, 06:40 AM   #3

total-Z
 
youresam's Avatar
 
Join Date: Jul 2005
Location: texas
Posts: 2,803
Trader Feedback: 0
Default

Code:
if Controls.read():cross() then
randomnumber = math.random(1,5)
if randomnumber == 1 then
print(var1)
elseif randomnumber == 2 then
print(vars)
elseif randomnumber == 3 then
print(var3)
elseif randomnumber == 4 then
print(var4)
elseif randomnumber == 5 then
print(var5)
end
end
Of course, it would be much smaller if they were in a table.

Code:
if Controls.read():cross() then
print(var[math.random(1,5)])
end
This requires you to have a table, var, with 5 variables in it.
__________________
牧来栠摩琠敨映汩獥
PSN: youresam
From Earth the Frozen Ipaqs shall rise and be silenced and all will live free.
--Mike Hollingsworth
youresam is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 03-16-2006, 06:55 AM   #4

Gutya
 

 
Join Date: Feb 2006
Posts: 2,398
Trader Feedback: 0
Default

Thanks, i can't seem to get my program to work, im a noob and this is my first program. Sorry

THis is what i have:

Code:
--Define Colors
black = Color.new(0,0,0)
white = Color.new(255,255,255)

--Table
Answers = {}
Answers[1] = "Go ahead, it might be your lucky day!"
Answers[2] = "Seems a bit risky to me"
Answers[3] = "Are you crazy?!"

--Load
screen:print(194,136,"Loading 0%",white)
screen.flip()
background = Image.load("background.png")
screen:clear()
screen:print(194,136,"Loading 50%",white)
screen.flip()
screen:clear()
screen:print(194,136,"Loading 100%",white)
screen.flip()
screen.waitVblankStart(60)

--Show Background
while true do
screen:blit(0,0,background,false)

--Main Game
pad = Controls.read()
if Controls.read():cross() then
screen:clear
print (120,190,Answers[math.random(1,3)],black)
screen.flip()
screen.waitVblankStart()
end
__________________
D:
Gutya is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 03-16-2006, 06:59 AM   #5

total-Z
 
youresam's Avatar
 
Join Date: Jul 2005
Location: texas
Posts: 2,803
Trader Feedback: 0
Default

Code:
--Define Colors
white = Color.new(255,255,255)

--Table
Answers = {}
Answers[1] = "Go ahead, it might be your lucky day!"
Answers[2] = "Seems a bit risky to me"
Answers[3] = "Are you crazy?!"

--Load
screen:clear()
screen:print(194,136,"Loading",white)
screen.flip()
background = Image.load("background.png")
screen:blit(0,0,background,false)
screen.flip()

--Main Game
while true do
pad = Controls.read()
if pad:cross() then
screen:clear
screen:blit(0,0,background,false)
screen:print(120,190,Answers[math.random(1,3)])
screen.flip()
screen.waitVblankStart(7)
end
if pad:start() then break end
end
I bolded some changes, but I also edited away a lot of your code and changed a few things. Oh, and ignore the odd spaces, its a forum bug.
__________________
牧来栠摩琠敨映汩獥
PSN: youresam
From Earth the Frozen Ipaqs shall rise and be silenced and all will live free.
--Mike Hollingsworth

Last edited by youresam; 03-16-2006 at 07:15 AM..
youresam is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 03-16-2006, 07:02 AM   #6

Gutya
 

 
Join Date: Feb 2006
Posts: 2,398
Trader Feedback: 0
Default

Still doesnt want to work.
__________________
D:
Gutya is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 03-16-2006, 07:04 AM   #7

total-Z
 
youresam's Avatar
 
Join Date: Jul 2005
Location: texas
Posts: 2,803
Trader Feedback: 0
Default

Quote:
Originally Posted by Gutya
Still doesnt want to work.
try it now. I keep editing it because your code was... weird.
remember, "background" and "Answers" are 2 words, the forum bug adds spaces.
__________________
牧来栠摩琠敨映汩獥
PSN: youresam
From Earth the Frozen Ipaqs shall rise and be silenced and all will live free.
--Mike Hollingsworth
youresam is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 03-16-2006, 07:13 AM   #8

Gutya
 

 
Join Date: Feb 2006
Posts: 2,398
Trader Feedback: 0
Default

It needs to have the background there all the time from the very start, then if you press x it prints the random statements on top.

But it wont work in the windows player.
__________________
D:
Gutya is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 03-16-2006, 07:15 AM   #9

total-Z
 
youresam's Avatar
 
Join Date: Jul 2005
Location: texas
Posts: 2,803
Trader Feedback: 0
Default

Quote:
Originally Posted by Gutya
It needs to have the background there all the time from the very start, then if you press x it prints the random statements on top.

But it wont work in the windows player.
Try it now
__________________
牧来栠摩琠敨映汩獥
PSN: youresam
From Earth the Frozen Ipaqs shall rise and be silenced and all will live free.
--Mike Hollingsworth
youresam is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 03-16-2006, 07:21 AM   #10

Gutya
 

 
Join Date: Feb 2006
Posts: 2,398
Trader Feedback: 0
Default

Still will not play, i try to run the script and it just closes the player.
__________________
D:
Gutya is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 03-16-2006, 07:57 AM   #11

total-Z
 
youresam's Avatar
 
Join Date: Jul 2005
Location: texas
Posts: 2,803
Trader Feedback: 0
Default

Quote:
Originally Posted by Gutya
Still will not play, i try to run the script and it just closes the player.
It closes the player? OH... your using the windows version... I dont know... I use my PSP to run scripts.
__________________
牧来栠摩琠敨映汩獥
PSN: youresam
From Earth the Frozen Ipaqs shall rise and be silenced and all will live free.
--Mike Hollingsworth
youresam is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 03-16-2006, 08:01 AM   #12

Gutya
 

 
Join Date: Feb 2006
Posts: 2,398
Trader Feedback: 0
Default

The windows version closes the player when it cannot run a script.
__________________
D:
Gutya is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Tags
lua , question , small

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 12:51 PM.



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