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_ (You posted twice ^^) I see that now, but I was in a hurry and right after ...
-
04-20-2007, 01:45 PM #6991
Zitat von PSPJunkie_
I see that now, but I was in a hurry and right after I posted that my browser crapped out on me so I couldn't tell
-
04-20-2007, 02:25 PM #6992Developer

- Registriert seit
- Oct 2006
- Ort
- San Diego
- Beiträge
- 177
- Points
- 4.205
- Level
- 41
- Downloads
- 0
- Uploads
- 0
This code is flawed and I wish people would stop sharing it.
Zitat von TMNT
math.abs(ax) <-32 will never be true, math.abs() will return the absolute value of a number, so math.abs(-50) will equal 50.
-
04-20-2007, 02:27 PM #6993
Thanks guys i will go to the forums
-
04-20-2007, 02:31 PM #6994QJ Gamer Silver

- Registriert seit
- May 2006
- Ort
- Behind you.
- Beiträge
- 1.814
- Points
- 10.921
- Level
- 69
- Downloads
- 0
- Uploads
- 0
Wow, i really have to stop posting. At least i wasn't spamming (whew*). Anyways, thanks for pointing that out. :)
Zitat von KleptoOne
Calypso - Enjoy the excellent 2D space shooter:
http://dl.qj.net/Calypso-v1-PSP-Home...6542/catid/195
"Quoting yourself in your signature means you love to masterbate while looking at the mirror." -me (oh, wait...)
-
04-20-2007, 03:32 PM #6995Developer

- Registriert seit
- Oct 2006
- Ort
- San Diego
- Beiträge
- 177
- Points
- 4.205
- Level
- 41
- Downloads
- 0
- Uploads
- 0
By all means, post as much as you like, just make sure you know the code before you share it, because if you don't it can lead to 50 more questions.
Zitat von TMNT
-
04-20-2007, 07:12 PM #6996
hy there people, is there a luaplayer mod thas includes:
System.setCpuSpeedVHigh() --Sets CPU to 333 Mhz
System.setCpuSpeedHigh() --Sets CPU to 300 Mhz
System.setCpuSpeedMed() --Sets CPU to 266 Mhz
System.setCpuSpeedReg() --Sets CPU to 222 Mhz
System.setCpuSpeedLow() --Sets CPU to 200 Mhz
System.setCpuSpeedVLow() --Sets CPU to 100 Mhz
and
Gum.lookAt
i see the lua player v0.20mod
it have the cpuspeed, but not the gum.lookat
-
04-20-2007, 07:18 PM #6997lol

- Registriert seit
- Aug 2006
- Ort
- Whittier, CA
- Beiträge
- 5.791
- Points
- 20.859
- Level
- 91
- Downloads
- 0
- Uploads
- 0
That would be cools lua player mod 2
-
04-20-2007, 07:38 PM #6998
waaa thankss.. i found it thankss thanksss.. oo by the way. i read that in the mod 3 cools has remover the speed functions cos it myght me dangerous is that true ??? using the cloock speed could damage psp ?
Zitat von Anti-QJ
-
04-20-2007, 07:46 PM #6999QJ Gamer Silver

- Registriert seit
- May 2006
- Ort
- Behind you.
- Beiträge
- 1.814
- Points
- 10.921
- Level
- 69
- Downloads
- 0
- Uploads
- 0
No. Overclocking does NOT damage the psp (well, it depends on how much you "overclock" it). I don't think that there is homebrew that overclocks above 333MHz (correct me if i am wrong; it can be done though?). Having the Cpu speed 333MHz is proven that Sony designed the psp to be like that. Overclocking the psp does NOT damage the psp (333MHz). However, it does reduce play time because it consumes quite a lot of battery.
Zitat von ahrimanes
Calypso - Enjoy the excellent 2D space shooter:
http://dl.qj.net/Calypso-v1-PSP-Home...6542/catid/195
"Quoting yourself in your signature means you love to masterbate while looking at the mirror." -me (oh, wait...)
-
04-20-2007, 08:03 PM #7000QJ Gamer Green
- Registriert seit
- Dec 2006
- Ort
- main();
- Beiträge
- 1.071
- Points
- 11.300
- Level
- 70
- Downloads
- 0
- Uploads
- 0
The PSP was meant to run at 333, Sony just had to compete with the battery life of Nintendo's DS. Technically, you really aren't overclocking since Sony underclocked it.
-
04-20-2007, 08:18 PM #7001Your Fate is Grim...

- Registriert seit
- Oct 2005
- Beiträge
- 2.269
- Points
- 11.640
- Level
- 70
- Downloads
- 0
- Uploads
- 0
rofl.
Zitat von TMNT
also, that is not the correct usage of the analog. you're using it as an alternative to the d-pad, which it should be. the analog is meant for pressure sensitivity. use it to your advantage.
-= Double Post =-
there is a 30% chance of bricking when you overclock. JK!! (before i get banned)
Zitat von ahrimanes
to add on to the 2 peeps above me, overclocking is not dangerous, but it has two bad sides:
1. reduces your battery life. not sure how much, but i know its not a tiny bit
2. its a very cheap way to get better performance. people use to make up for their ghey optimization skills.Geändert von Grimfate126 (04-20-2007 um 08:20 PM Uhr) Grund: Automerged Doublepost
--------------------------------------------------------------------------------------
-
04-20-2007, 08:27 PM #7002
well ok thanks every one. for this explanation, i think i will go trhowth the optimization way :P
-
04-20-2007, 09:07 PM #7003words 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
Grimfate - FYI, the PSP is no Alienware, and although no PSP homebrew optimized to the fullest would require overclocking, its still a useful way to hlep your framerate along when your still a youngin' not knowing how to use C++ to the fullest (templates ftw)

...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-20-2007, 09:12 PM #7004QJ Gamer Gold
- Registriert seit
- Nov 2006
- Ort
- ...
- Beiträge
- 2.080
- Points
- 11.942
- Level
- 71
- Downloads
- 0
- Uploads
- 0
how come this doesnt work, even though i thought it would:
Code:function level4() nbc=0 ncc=3 showblock=false lol=true while true do screen:clear() Enemy.x=40 Enemy.y=50 Stick.x=117 Stick.y=234 Stick2.x=230 Stick2.y=0 Square.x=480 Square.y=45 if collision(Player,Stick2) then lol=true else if collision(Player,Stick2) and Player.img == Sball then lol=false end end if lol then dofile("br.lua") end if collision(Player,Square) then Player.img = Sball end screen:blit(Stick2.x,Stick2.y,Stick2.img) movePlayer() screen:blit(0,0,lvl,true) screen:blit(Player.x,Player.y,Player.img) screen:blit(Enemy.x,Enemy.y,Enemy.img) screen:blit(Stick.x,Stick.y,Stick.img) screen:blit(Square.x,Square.y,Square.img) screen.waitVblankStart() screen.flip() end end
-
04-20-2007, 09:20 PM #7005QJ Gamer Green
- Registriert seit
- Feb 2007
- Beiträge
- 17
- Points
- 6.449
- Level
- 52
- Downloads
- 0
- Uploads
- 0
random numbers
This is my function for generating random cards and placing them into my hand (this function just generates the card though).
Code:function drawcard1() randz = math.random(1,6) if randz == 1 then hand1 = Image.load("cards/vector.png") end if randz == 2 then hand1 = Image.load("cards/marshie.png") end if randz == 3 then hand1 = Image.load("cards/ring.png") end if randz == 4 then hand1 = Image.load("cards/luigi.png") end if randz == 5 then hand1 = Image.load("cards/homsar.png") end if randz == 6 then hand1 = Image.load("cards/young_link.png") end end
Is there anyway i can change it so that when a number is chosen it is never picked again? ( or until a new game is started )
-thanks in advance
-
04-20-2007, 10:34 PM #7006words 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
wootguy -
I believe that should work (Although im pretty out of it right now... 420 and all :P)Code:-- Globally used = {} -- Place these 6 lines in your 'NewGame' function for when a new game is started used[1] = false used[2] = false used[3] = false used[4] = false used[5] = false used[6] = false function drawcard1() randz = math.random(1,6) if randz == 1 and used[1] == false then hand1 = Image.load("cards/vector.png") end if randz == 2 and used[2] == false then hand1 = Image.load("cards/marshie.png") end if randz == 3 and used[3] == false then hand1 = Image.load("cards/ring.png") end if randz == 4 and used[4] == false then hand1 = Image.load("cards/luigi.png") end if randz == 5 and used[5] == false then hand1 = Image.load("cards/homsar.png") end if randz == 6 and used[6] == false then hand1 = Image.load("cards/young_link.png") end used[randz] = true 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
-
04-20-2007, 10:40 PM #7007Monster Masher
- Registriert seit
- Jun 2006
- Ort
- Behind you...
- Beiträge
- 265
- Points
- 5.084
- Level
- 45
- Downloads
- 0
- Uploads
- 0
doesnt math.random return with decimal places? dont you need to math.round it or am I stuck in another programming language here.
-
04-20-2007, 10:57 PM #7008words 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
No, Lua Player does it for you. (atleast thats how ive been using it)

...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-21-2007, 03:01 AM #7009
math.random() by itself will return a number greater than 0 but less than 1, put one number in the brackets and it will return a number between 0 and that number, put two numbers in and it will return a number between the two numbers
-
04-21-2007, 09:14 AM #7010QJ Gamer Green
- Registriert seit
- Feb 2007
- Beiträge
- 17
- Points
- 6.449
- Level
- 52
- Downloads
- 0
- Uploads
- 0
random
that seemed to work, but is there a way i can get more realistic random numbers? because every time i start the game, my first hand is always the same.
I know that "math.randomseed(os.time( ))" is supposed to give realistic random numbers, but i'm not sure how to use it.
-
04-21-2007, 09:24 AM #7011
ermm... you use it just like that....
-
04-21-2007, 09:29 AM #7012QJ Gamer Green
- Registriert seit
- Feb 2007
- Beiträge
- 17
- Points
- 6.449
- Level
- 52
- Downloads
- 0
- Uploads
- 0
will it still give random numbers between 1 and 6? and it gives me the error "table index is nil"
-
04-21-2007, 09:34 AM #7013QJ Gamer Gold
- Registriert seit
- Aug 2006
- Beiträge
- 1.633
- Points
- 11.629
- Level
- 70
- Downloads
- 0
- Uploads
- 0
math.randomseed(os.time)
blah = math.random(1,6)
-
04-21-2007, 09:38 AM #7014QJ Gamer Green
- Registriert seit
- Feb 2007
- Beiträge
- 17
- Points
- 6.449
- Level
- 52
- Downloads
- 0
- Uploads
- 0
so i put blah under "math.randomseed(os.time( ))"?
-
04-21-2007, 09:53 AM #7015QJ Gamer Gold
- Registriert seit
- Aug 2006
- Beiträge
- 1.633
- Points
- 11.629
- Level
- 70
- Downloads
- 0
- Uploads
- 0
Dude, if you cant figure that out, please, stop programming.
And yes, you do.
-
04-21-2007, 10:23 AM #7016QJ Gamer Green
- Registriert seit
- Feb 2007
- Beiträge
- 17
- Points
- 6.449
- Level
- 52
- Downloads
- 0
- Uploads
- 0
well the reason i asked was because it wasn't working, but now i know that it's from something else
-
04-21-2007, 10:28 AM #7017words 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 - Its a help forum, he's new, and not everyone knows it must be called only once from the start of hte program, so lay off. So cranky...
Wootguy - Place it at the start of your script (AKA not in your infinite loop)
...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-21-2007, 10:40 AM #7018QJ Gamer Green
- Registriert seit
- Feb 2007
- Beiträge
- 17
- Points
- 6.449
- Level
- 52
- Downloads
- 0
- Uploads
- 0
thanks.
I also have one last question before I'm done here:
what does "table index is nil"" mean? The "index" part kinda threw me off.
-
04-21-2007, 10:50 AM #7019
i hate when peole is like knowit all... poor people. they are lonly.
well i wass testing somthing whith oop, and got this to work:
ok that work good, but im trayingo somthing else and wont work-Code:--ahrimanes oop starfield --usb active System.usbDiskModeActivate() --crear un nuevo objeto de color gris1 = Color.new(100,100,100) gris2 = Color.new(150,150,150) gris3 = Color.new(200,200,200) blanco = Color.new(255,255,255) maxstars = 200 width = 480-1 height = 272-1 timer = 0 bf = Image.createEmpty(480, 272) clsstar = {} metastar = {} math.randomseed(os.time()) function drawRect(x, y, width, height, color, w) w:drawLine(x, y, x+width, y, color) w:drawLine(x, y, x, y+height, color) w:drawLine(x+width, y, x+width, y+height, color) w:drawLine(x, y+height, x+width, y+height, color) end function clsstar:New() x = math.random(width) y = math.random(height) z = math.random(3) if z == 1 then colora = gris1 colorb = gris1 end if z == 2 then colora = gris2 colorb = gris2 end if z == 3 then colora = gris3 colorb = gris3 end return(setmetatable({Position = {X = x, Y = y, Z = z},colora = colora,colorb = colorb}, metastar)) end function clsstar:draw() screen:pixel(self.Position.X,self.Position.Y,self.colora) drawRect(self.Position.X-(self.Position.Z-1)/2,self.Position.Y-(self.Position.Z-1)/2,self.Position.Z-1,self.Position.Z-1,self.colora,screen) self.Position.Y = self.Position.Y + self.Position.Z * 2 if self.Position.Y > height then self.Position.Y = 0 self.Position.X = math.random(width) end end metastar.__index = clsstar starfield = {} for i = 1, maxstars do starfield[i] = clsstar:New() end while true do screen:waitVblankStart() screen:clear() for i = 1, table.getn(starfield) do starfield[i]:draw() end screen:flip() pad = Controls.read() if pad:start() then break end end
soooCode:hero = {} metahero = {} function hero:new() x = 480/2 y = 272/2 dx = 0 dy = 0 angle = 0 oldangle = 0 speed = 0 return(setmetatable({X = x, Y = y, dX = dx, dY = dy, Angle = angle, Oldangle = oldangle, Speed = speed}, metahero)) end function hero:updt() pad = Controls.read() self.dX = pad:analogX() self.dY = pad:analogY() screen:print(0,0,self.dX,white) screen:print(0,20,self.dY,white) screen:print(0,30,self.X,white) screen:print(0,40,self.Y,white) end
ship = hero:new()
then in mainloop
ship.updt()
and i got nil value on this line
screen
rint(0,30,self.X,white)
whats worng?
itseems that the new obj hass all his fields nil wy ?
-
04-21-2007, 11:00 AM #7020Developer

- Registriert seit
- Oct 2006
- Ort
- San Diego
- Beiträge
- 177
- Points
- 4.205
- Level
- 41
- Downloads
- 0
- Uploads
- 0
well at a quick glance, the updt function is called from the hero table, which is where all your classes are stored, but your actual x, y, ect values are stored in the meta hero obj, so when you use self it is accessing the hero template which is the wrong one. I could be wrong though.
*Edit* After reading the first code set, I see that it uses the same structure. The only difference that I'm going to have to research to understand is this command:
Maybe that links the two objects in some way, I'm not sure, but if you can explain it that would be great. I never considered using OOP in lua, as the only reason I code in it is because tables are so easy to manipulate. Plus without true pointers, In my mind, it would be hard to keep your objects truely seperate.Code:metastar.__index = clsstar
Geändert von KleptoOne (04-21-2007 um 11:35 AM Uhr)


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