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; so basically you want to make a random number once as a function in a while true do loop... you ...
-
04-12-2006, 11:13 PM #1501QJ Gamer Blue
- Registriert seit
- Apr 2006
- Ort
- secret underground lair
- Beiträge
- 72
- Points
- 4.390
- Level
- 42
- Downloads
- 0
- Uploads
- 0
so basically you want to make a random number once as a function in a while true do loop...
you cant. only way to do this would be to gen a random number when the program starts in use for this function... only way to do it to use the same number every time...
or...
function whiletruestart()
blah = math.random(1,30)
whiletrue(loop)
use blah somehow
end
end
Geändert von RanDom_ErrOr (04-12-2006 um 11:16 PM Uhr)
-
04-12-2006, 11:53 PM #1502QJ Gamer Blue
- Registriert seit
- Apr 2006
- Ort
- secret underground lair
- Beiträge
- 72
- Points
- 4.390
- Level
- 42
- Downloads
- 0
- Uploads
- 0
I've made a UFA or... i should say, im learning lua through coding what i dont understand so i can learn how to use it... >>; but i've kinda run into an interesting ... bug?
When using Lua Player for Windows, everytime i run this code, the same colors and positions are used when the program starts... its kinda weird... even when using the math.random() function to generate "random" numbers...
is there a reliable random number function that doesnt seem to generate the same exact results each time... /cry
also... unfortunately for the life of me i cant figure out how to compress this code down to a few lines in lua... if this was php i could do this like... real quick...Code:-- Demonstration No-User-App -- Author: RanDom_ErrOr -- Copyright 2006 -- No liscense with this product what so ever. Use at your own risk. I will accept no liability or responsibility if you **** something up. color1 = Color.new(113, 113, 113 ) color2 = Color.new(61, 115, 169 ) color3 = Color.new(39, 75, 112) color4 = Color.new(96,120,238) color5 = Color.new(192,218,250) color6 = Color.new(224,227,254) screenwidth = 480 screenheight = 272 letter = "o" organism = { } organism[1] = { posx = math.random(1,480), posy = math.random(1,272) } organism[2] = { posx = math.random(1,480), posy = math.random(1,272) } organism[3] = { posx = math.random(1,480), posy = math.random(1,272) } organism[4] = { posx = math.random(1,480), posy = math.random(1,272) } organism[5] = { posx = math.random(1,480), posy = math.random(1,272) } organism[6] = { posx = math.random(1,480), posy = math.random(1,272) } screen:print(100,240," User Free Application Demo_Author:RanDom_ErrOr", color3) while true do x1 = organism[1].posx y1 = organism[1].posy screen:print(x1 , y1 , letter, color1) organism[1].posx = organism[1].posx + math.random(-3,3) organism[1].posy = organism[1].posy + math.random(-3,3) if organism[1].posx >= screenwidth or organism[1].posx <= 0 then organism[1].posx = math.random(1,480) end if organism[1].posy >= screenheight or organism[1].posy <= 0 then organism[1].posy = math.random(1,272) end x2 = organism[2].posx y2 = organism[2].posy color = organism[1].color screen:print(x2 , y2 , letter, color2) organism[2].posx = organism[2].posx + math.random(-3,3) organism[2].posy = organism[2].posy + math.random(-3,3) if organism[2].posx >= screenwidth or organism[2].posx <= 0 then organism[2].posx = math.random(1,480) end if organism[2].posy >= screenheight or organism[2].posy <= 0 then organism[2].posy = math.random(1,272) end x3 = organism[3].posx y3 = organism[3].posy color = organism[3].color screen:print(x3 , y3 , letter, color3) organism[3].posx = organism[3].posx + math.random(-3,3) organism[3].posy = organism[3].posy + math.random(-3,3) if organism[3].posx >= screenwidth or organism[3].posx <= 0 then organism[3].posx = math.random(1,480) end if organism[3].posy >= screenheight or organism[3].posy <= 0 then organism[3].posy = math.random(1,272) end x4 = organism[4].posx y4 = organism[4].posy screen:print(x4 , y4 , letter, color4) organism[4].posx = organism[4].posx + math.random(-3,3) organism[4].posy = organism[4].posy + math.random(-3,3) if organism[4].posx >= screenwidth or organism[4].posx <= 0 then organism[4].posx = math.random(1,480) end if organism[4].posy >= screenheight or organism[4].posy <= 0 then organism[4].posy = math.random(1,272) end x5 = organism[5].posx y5 = organism[5].posy color = organism[4].color screen:print(x5 , y5 , letter, color5) organism[5].posx = organism[5].posx + math.random(-3,3) organism[5].posy = organism[5].posy + math.random(-3,3) if organism[5].posx >= screenwidth or organism[5].posx <= 0 then organism[5].posx = math.random(1,480) end if organism[5].posy >= screenheight or organism[5].posy <= 0 then organism[5].posy = math.random(1,272) end x6 = organism[6].posx y6 = organism[6].posy color = organism[6].color screen:print(x6 , y6 , letter, color6) organism[6].posx = organism[6].posx + math.random(-3,3) organism[6].posy = organism[6].posy + math.random(-3,3) if organism[6].posx >= screenwidth or organism[6].posx <= 0 then organism[6].posx = math.random(1,480) end if organism[6].posy >= screenheight or organism[6].posy <= 0 then organism[6].posy = math.random(1,272) end screen.flip() end while true do screen.waitVblankStart() end
on tables is there anyway to dynamically create tables from the program? like using a variable inside on an array instead of just a number or text... is there a special delimiter used when doing this?
im guessing instead that you actually have to use a tableconstructor to use variables like i want to... great... or does that even work? i guess i'll have to try it and see if it will...
also is there a way to do a foreach table[?] do something like table[1]-[5] etc with less code than i've used...
whats funny is that this is the first program i've programmed in Lua, and its kind of restrained, not being able to easily (php is so easy with tables like blah[$vari] = { $blah2 = $blah, etc = $1234, $huh = $great}
)
basically i want code to easily increase the number of dudes >>; course, i could use the buttons, but i'd need an easy way to make new tables... (buttons and crap i can do, its just how to make the tables easier (with variables or with functions... w/e) )
thanks in advance... ^^
EDIT: optimized code a little, but still ugly and bloated... ><Geändert von RanDom_ErrOr (04-13-2006 um 12:34 AM Uhr)
-
04-13-2006, 03:42 AM #1503
Ok thats a lot so im just answering in parts and edit i guess lol.
Ok for a different "random" number each time you should make a seed. I dont know the exact command unfortunately, but its something like this: random.seed(ostime("%c"))
Ok sorry i have to do java programming for my study. One last thing:
could be shorter by using this:Code:organism = { } organism[1] = { posx = math.random(1,480), posy = math.random(1,272) } organism[2] = { posx = math.random(1,480), posy = math.random(1,272) } organism[3] = { posx = math.random(1,480), posy = math.random(1,272) } organism[4] = { posx = math.random(1,480), posy = math.random(1,272) } organism[5] = { posx = math.random(1,480), posy = math.random(1,272) } organism[6] = { posx = math.random(1,480), posy = math.random(1,272) }
Waaaaay shorterCode:organism = { } for i=1,9 do organism[i] = { posx = math.random(1,480), posy = math.random(1,272) } end
Later!LUA manual:
[url]http://www.lua.org/manual/5.0/manual.html[/url]
LUA Wiki:
[url]http://wiki.ps2dev.org/psp:lua_player[/url]
-
04-13-2006, 03:50 AM #1504QJ Gamer Silver
- Registriert seit
- Feb 2006
- Ort
- England
- Beiträge
- 1.038
- Points
- 8.993
- Level
- 63
- Downloads
- 0
- Uploads
- 0
thanks alot man! know I got my game to work fully but am not yet gonna release it!
Zitat von Altair
am soo happy :humped: :humped: :Punk: :icon_smilI own a Playstation 3,PSP and a Wii add me on psn: azazin,
Zitat von TheMasterChef
-
04-13-2006, 10:14 AM #1505QJ Gamer Silver
- Registriert seit
- Jun 2005
- Ort
- Puerto Rico
- Beiträge
- 310
- Points
- 7.109
- Level
- 55
- Downloads
- 0
- Uploads
- 0
Ok now it's half done (pica) disappears when (picb) appears but then (picb) stays printed on the screen.
Zitat von kozine
-
04-13-2006, 10:28 AM #1506QJ Gamer Blue
- Registriert seit
- Apr 2006
- Ort
- secret underground lair
- Beiträge
- 72
- Points
- 4.390
- Level
- 42
- Downloads
- 0
- Uploads
- 0
unfortunately man when trying to do organism[i] it makes it so i is the key / index... so it doesnt work... im actually looking for a way to use a variable(which will be a number) as an index... (so i dont have to hard code all this crap for each organism )
-
04-13-2006, 10:50 AM #150711th Squad Captain
- Registriert seit
- Jun 2005
- Ort
- You are here -----> 名前: アダム | 飲むコー
- Beiträge
- 2.562
- Points
- 26.490
- Level
- 97
- Downloads
- 0
- Uploads
- 0
Once again this works:
Zitat von shadow-evillink
you just need a background knowCode:--Load images bg = Image.load("bg.png") pic = {} pic[1] = Image.load("flapperleft1.png") pic[2] = Image.load("flapperleft2.png") imgpic=pic[1] --Begin the main loop while true do screen:blit(0, 0, bg) pad = Controls.read() if pad:cross() then imgpic=pic[2] else imgpic=pic[1] end screen:blit(0, 0, imgpic) screen.flip() end
.
FAVORITE GAME! - BEER & ANIME! - SO EXICTING!

開発者, 携帯用プログラマー 日本サポータおよび恋人 本名のアダムの鍛冶屋
Currently Working On: - Flashmod V2.50 - Flashmod V2.60
Currently Drinking: Coffee! - 私はコーヒーを飲む
Chao Garden: DEMO v0.6
Chao Garden V0.5b Review!
-
04-13-2006, 11:24 AM #1508Rock Star

- Registriert seit
- Aug 2005
- Ort
- CT| FW: 4.01 M33-2
- Beiträge
- 11.844
- Points
- 70.899
- Level
- 100
- Downloads
- 0
- Uploads
- 0
Care to state what your game is?
Zitat von ct-boy

-
04-13-2006, 11:26 AM #1509QJ Gamer Silver
- Registriert seit
- Feb 2006
- Ort
- England
- Beiträge
- 1.038
- Points
- 8.993
- Level
- 63
- Downloads
- 0
- Uploads
- 0
nope sry lol.
Zitat von TeamOverload
:Punk: :icon_smil ;) but I still need a little help from anyone my msn is ct-trav[email protected]I own a Playstation 3,PSP and a Wii add me on psn: azazin,
Zitat von TheMasterChef
-
04-13-2006, 11:34 AM #1510Rock Star

- Registriert seit
- Aug 2005
- Ort
- CT| FW: 4.01 M33-2
- Beiträge
- 11.844
- Points
- 70.899
- Level
- 100
- Downloads
- 0
- Uploads
- 0
Alright thats cool....ill be anxious to see it when it is released

-
04-13-2006, 11:36 AM #1511
Ok, let's say a = math.random(1, 20). Then i say, print (0,0, a), it prints every number 1, 2, 3, 4, 5, etc... through 20. I just want it to print a single random number
-
04-13-2006, 11:38 AM #1512Quality Haxing Since 1991
- Registriert seit
- Oct 2005
- Ort
- Pennsylvania, USA Fi
- Beiträge
- 6.206
- Points
- 29.255
- Level
- 99
- Downloads
- 0
- Uploads
- 0
It looks like you have a = math.random(1, 20). in your loop. Put it before the loop, then it will only generate one number.
Zitat von ro0kie42
Zitat von Noriko
-
04-13-2006, 11:41 AM #151311th Squad Captain
- Registriert seit
- Jun 2005
- Ort
- You are here -----> 名前: アダム | 飲むコー
- Beiträge
- 2.562
- Points
- 26.490
- Level
- 97
- Downloads
- 0
- Uploads
- 0
TIP:
Zitat von PSPHax0r9
Always put
math.randomseed(os.time() )
before a loop and a "math.random()" function!
This will stop you from gtting the same resualt
on startup of your code.FAVORITE GAME! - BEER & ANIME! - SO EXICTING!

開発者, 携帯用プログラマー 日本サポータおよび恋人 本名のアダムの鍛冶屋
Currently Working On: - Flashmod V2.50 - Flashmod V2.60
Currently Drinking: Coffee! - 私はコーヒーを飲む
Chao Garden: DEMO v0.6
Chao Garden V0.5b Review!
-
04-13-2006, 11:42 AM #1514Quality Haxing Since 1991
- Registriert seit
- Oct 2005
- Ort
- Pennsylvania, USA Fi
- Beiträge
- 6.206
- Points
- 29.255
- Level
- 99
- Downloads
- 0
- Uploads
- 0
Oh yea, I forgot to say all that. Thanks. That should help rookie.
Zitat von c5cha7
Zitat von Noriko
-
04-13-2006, 12:48 PM #1515is not posting very often

- Registriert seit
- Feb 2006
- Ort
- omnipresent
- Beiträge
- 5.162
- Points
- 33.152
- Level
- 100
- Downloads
- 0
- Uploads
- 0
yea, thats something improtant to know, i am going to use a random seed in BPPE
What did we think the world would look like in 2015?
http://forums.qj.net/501501-post26.html
Zitat von Abe
-
04-13-2006, 01:03 PM #1516
The math.random() part is outside the loop. The print part is inside the loop. If I put the print part outside the loop, it doesn't print. If i put the print part inside the loop, it prints all the numbers.
Geändert von ro0kie42 (04-13-2006 um 01:18 PM Uhr)
-
04-13-2006, 04:06 PM #1517Simon Champion!
- Registriert seit
- Mar 2006
- Ort
- Calgary, Alberta, Ca
- Beiträge
- 537
- Points
- 11.489
- Level
- 70
- Downloads
- 0
- Uploads
- 0
is there a way to end a SPECIFIC sound? rather than using voice:stop()?
-
04-13-2006, 04:36 PM #1518Quality Haxing Since 1991
- Registriert seit
- Oct 2005
- Ort
- Pennsylvania, USA Fi
- Beiträge
- 6.206
- Points
- 29.255
- Level
- 99
- Downloads
- 0
- Uploads
- 0
yes....voice is a variable. So give each sound a different name and say voice1:stop...voice2:stop ...etc.
Zitat von Greenskull
Zitat von Noriko
-
04-13-2006, 04:37 PM #1519sceKernelExitGame();
- Registriert seit
- Jan 2006
- Ort
- New York
- Beiträge
- 3.126
- Points
- 19.955
- Level
- 89
- Downloads
- 0
- Uploads
- 0
help!!!!!!! i am a new developer and i am using the tuts by pspmillionare and when i try to test my apps/games on my psp it always says error: no script file found.
does any1 know wat to do?
BTW- i am using luaplayer .16 on a 2.00 psp
-
04-13-2006, 04:38 PM #1520Simon Champion!
- Registriert seit
- Mar 2006
- Ort
- Calgary, Alberta, Ca
- Beiträge
- 537
- Points
- 11.489
- Level
- 70
- Downloads
- 0
- Uploads
- 0
hmm I tried that but it said that "loop in gettable" thing....
Zitat von PSPHax0r9
-
04-13-2006, 04:39 PM #1521QJ Gamer Gold
- Registriert seit
- Jul 2005
- Ort
- Chicago
- Beiträge
- 4.443
- Points
- 20.183
- Level
- 89
- Downloads
- 0
- Uploads
- 0
I get the same exact error, but im using the windows lua player
Zitat von bronxbomber92
-
04-13-2006, 04:39 PM #1522sceKernelExitGame();
- Registriert seit
- Jan 2006
- Ort
- New York
- Beiträge
- 3.126
- Points
- 19.955
- Level
- 89
- Downloads
- 0
- Uploads
- 0
i cant test on my computer becuase i have a mac
-
04-13-2006, 04:42 PM #1523Simon Champion!
- Registriert seit
- Mar 2006
- Ort
- Calgary, Alberta, Ca
- Beiträge
- 537
- Points
- 11.489
- Level
- 70
- Downloads
- 0
- Uploads
- 0
wait, the sound loops so is that what the error means?
-
04-13-2006, 05:27 PM #1524Rock Star

- Registriert seit
- Aug 2005
- Ort
- CT| FW: 4.01 M33-2
- Beiträge
- 11.844
- Points
- 70.899
- Level
- 100
- Downloads
- 0
- Uploads
- 0
What are all the sound formats supported, and are there any size limits?

-
04-13-2006, 05:28 PM #1525sceKernelExitGame();
- Registriert seit
- Jan 2006
- Ort
- New York
- Beiträge
- 3.126
- Points
- 19.955
- Level
- 89
- Downloads
- 0
- Uploads
- 0
can any1 help me get my small app running on my psp?
-
04-13-2006, 05:48 PM #1526Rock Star

- Registriert seit
- Aug 2005
- Ort
- CT| FW: 4.01 M33-2
- Beiträge
- 11.844
- Points
- 70.899
- Level
- 100
- Downloads
- 0
- Uploads
- 0
Post the code and we will try and help you out

-
04-13-2006, 05:52 PM #1527sceKernelExitGame();
- Registriert seit
- Jan 2006
- Ort
- New York
- Beiträge
- 3.126
- Points
- 19.955
- Level
- 89
- Downloads
- 0
- Uploads
- 0
ok heres the code
green = Color.new (0, 255, 0)
Enemy = { }
Enemy[1] = { type = "gargoyle", health = 100 }
Enemy[2] = { type = "vampire", health = 100 }
Enemy[3] = { type = "goomba", health = 100 }
Enemy[4] = { type = "ghost", health = 100 }
Enemy[5] = { type = "zombie", health = 100 }
Player = { }
Player[1] = { weapon = "sword", health = 100 }
Player[2] = { weapon = "knife", health = 100 }
while true do
pad = Controls.read()
screen.clear()
screen
rint(5, 10, "Player 1 Health: ".. Player[1].health,green)
screen
rint(5, 20, "Player 1 Weapon: ".. Player[1].weapon,green)
screen
rint(250,10,"Enemy Health: " .. Enemy[1].health,green)
screen
rint(250,20,"Enemy Type: " .. Enemy[1].type,green)
if pad:cross() then
Enemy[1].health = Enemy[1].health - 5
end
screen.waitVblankStart()
screen.flip()
end
BTW- the smilies where placed in by the forum becuz but remember its really screen
rint
Geändert von Bronx (04-13-2006 um 06:15 PM Uhr)
-
04-13-2006, 05:57 PM #1528sceKernelExitGame();
- Registriert seit
- Jan 2006
- Ort
- New York
- Beiträge
- 3.126
- Points
- 19.955
- Level
- 89
- Downloads
- 0
- Uploads
- 0
oh, and now i get the error of index.lua:1: unexpected symbol near (sumtin, i cant type it on a keyboard)
sry for double post!!!
-
04-13-2006, 06:05 PM #1529Developer

- Registriert seit
- Mar 2006
- Ort
- Guadalajara
- Beiträge
- 958
- Points
- 7.499
- Level
- 57
- Downloads
- 0
- Uploads
- 0
is this???: screen"print(5, 20, "Player 1 Weapon: ".. Player[1].weapon,green)
try: screenprint(5, 20, "Player 1 Weapon: ".. Player[1].weapon,green)
-
04-13-2006, 06:10 PM #1530sceKernelExitGame();
- Registriert seit
- Jan 2006
- Ort
- New York
- Beiträge
- 3.126
- Points
- 19.955
- Level
- 89
- Downloads
- 0
- Uploads
- 0
omg, i cant believe i missed that! thanks! but know i get error: index.lua:1: unexpected symbol near (little backward slash) { (little forward slash).
sry i dont now if i can type those symbols i was describing...


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