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 ahrimanes hii there people, im makings some test, and i im in a way to make more eficient ...
-
04-18-2007, 02:04 PM #6931
at the beginning of the script, set var2 = to a function:
Zitat von ahrimanes
var2 = function() return var1 end
with this, var2 should always be the same as var1
you should also be able to use a variation of this for your var3
-
04-18-2007, 02:10 PM #6932
No, var2() will return the value of var1.
Zitat von Merick
And ahrimanes you should experiment with tables, as they are always pointers.
IE:
a = {5}
b = a
b[1] = 4
...now a[1] is 4.牧来栠摩琠敨映汩獥
PSN: youresamFrom Earth the Frozen Ipaqs shall rise and be silenced and all will live free.
--Mike Hollingsworth
-
04-18-2007, 02:15 PM #6933
yeah, sorry that's what I meant
Can someone give me, or point me to, and explanation of how "self" works?
-
04-18-2007, 02:21 PM #6934
Its used in OOP, it returns a pointer to the object before the colon.
Zitat von Merick
牧来栠摩琠敨映汩獥
PSN: youresamFrom Earth the Frozen Ipaqs shall rise and be silenced and all will live free.
--Mike Hollingsworth
-
04-18-2007, 02:36 PM #6935
Thanks, that helps a lot actually. Well, enough to know it's the OOP tuts I needed to look into. Got what I wanted to do figured out now.
-
04-18-2007, 02:51 PM #6936
ok i have tested that ad works prety well but... what i need is:
Zitat von Yonathan_Jantis
soo when i change a[1] = 0 i want the b[1][2] to be 0... thats what i need. but this just take the value and not a pointer..... is there a way to do that ?Code:white = Color.new(255,255,255) a = {5,5} b = {} b[1] = {0,a[1],a[2],0} a[1] = 0 while true do screen:clear() screen:print(0,0,b[1][2],white) screen.waitVblankStart() screen.flip() end
-
04-18-2007, 02:53 PM #6937
No. But I *think* that if you pass the table a as part of table b it will be a pointer. So..
Zitat von ahrimanes
a = {5}
b = {a}
b[1][1] = 4
..does a[1] now equal 4? I think so, not sure.
But just add another line of code to change it, its not worth all this pointer complicity.牧来栠摩琠敨映汩獥
PSN: youresamFrom Earth the Frozen Ipaqs shall rise and be silenced and all will live free.
--Mike Hollingsworth
-
04-18-2007, 02:59 PM #6938
hooo noooooooooooooooooooooooo ooo... isnt there a wayy daaammm, i need to change soomuch values and if i change one per one that will bee a lot of time lose... im actually redefinig the b table each an a value changes.. and that took some time...
-
04-18-2007, 03:22 PM #6939QJ Gamer Blue
- Registriert seit
- Jul 2006
- Ort
- Upstate, NY USA
- Beiträge
- 121
- Points
- 4.349
- Level
- 41
- Downloads
- 0
- Uploads
- 0
Zitat von KleptoOne
Fair enough. But can you at least tell me this?
How do I check flash0 space? I found how to do it on the ms, but nothing on the flash.
-
04-18-2007, 03:52 PM #6940words 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
Well, how would you do it on the memory stick? A sneaky way to do it would be to unassign ms0:, unassign flash0:, reassign flash0: as ms0:, get file space using method, unassign ms0:, reassign flash0: to flash0:, reassign ms0: to ms0:
?
...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-18-2007, 04:06 PM #6941
But...why?
牧来栠摩琠敨映汩獥
PSN: youresamFrom Earth the Frozen Ipaqs shall rise and be silenced and all will live free.
--Mike Hollingsworth
-
04-18-2007, 04:24 PM #6942QJ Gamer Gold
- Registriert seit
- Nov 2006
- Ort
- ...
- Beiträge
- 2.080
- Points
- 11.942
- Level
- 71
- Downloads
- 0
- Uploads
- 0
ok im still stuck with this destroying stuff, cause even though the image doesnt show, when the 2 objects collide it still restarts the game, how do i stop this????????????????
-
04-18-2007, 04:36 PM #6943Developer

- Registriert seit
- Oct 2006
- Ort
- San Diego
- Beiträge
- 177
- Points
- 4.205
- Level
- 41
- Downloads
- 0
- Uploads
- 0
We would have to see your code to properly debug, also what error are you getting when luaplayer restarts?
Zitat von Urameshi
-
04-18-2007, 04:43 PM #6944
lol
Zitat von Urameshi
Learn how coding works first牧来栠摩琠敨映汩獥
PSN: youresamFrom Earth the Frozen Ipaqs shall rise and be silenced and all will live free.
--Mike Hollingsworth
-
04-18-2007, 04:45 PM #6945QJ Gamer Gold
- Registriert seit
- Nov 2006
- Ort
- ...
- Beiträge
- 2.080
- Points
- 11.942
- Level
- 71
- Downloads
- 0
- Uploads
- 0
i dont get an error at all, and dont laugh at my code, cause i know im killing memory:
Code:white=Color.new(255,255,255) ball=Image.load("./Images/ball.png") Sball=Image.load("./Images/Spike Ball.png") square=Image.load("./Images/10x10.jpg") bigSquare=Image.load("./Images/30x30.jpg") stick=Image.load("./Images/190x23.jpg") lvl=Image.load("./Images/backgrounds/silkwave black.png") menu=Image.load("./Images/menu.png") next=Image.load("./Images/next level.png") stick2=Image.load("./Images/23x190.png") ball:width() ball:height() screenwidth=480-ball:width() screenheight=272-ball:width() Player={x=40,y=25,w=40,h=40,img=ball} Enemy={x=0,y=0,w=30,h=30,img=bigSquare,} Square={x=0,y=0,w=10,h=10,img=square} Stick={x=0,y=0,w=190,h=23,img=stick} Stick2={x=0,y=0,w=23,h=190,img=stick2} --------------------------------------------------------------------------functions function menu1() pad=Controls.read() screen:blit(0,0,menu) if pad:cross() then level1() end end ------------------------------------------------------lvl1 function level1() while true do screen:clear() Enemy.x=100 Enemy.y=100 if collision(Player,Enemy) then screen:blit(0,0,next) screen.flip() screen.waitVblankStart(90) level2() end movePlayer() screen:blit(0,0,lvl,true) screen:blit(Player.x,Player.y,Player.img) screen:blit(Enemy.x,Enemy.y,Enemy.img) screen.waitVblankStart() screen.flip() end end ---------------------------------------------------lvl2 function level2() while true do screen:clear() Enemy.x=300 Enemy.y=50 if collision(Player,Enemy) then screen:blit(0,0,next) screen.flip() screen.waitVblankStart(90) level3() end movePlayer() screen:blit(0,0,lvl,true) screen:blit(Player.x,Player.y,Player.img) screen:blit(Enemy.x,Enemy.y,Enemy.img) screen.waitVblankStart() screen.flip() end end ---------------------------------------------------lvl3 function level3() nbc=0 ncc=2 while true do screen:clear() Enemy.x=400 Enemy.y=50 Stick.x=117 Stick.y=234 Stick2.x=230 Stick2.y=0 if collision(Player,Enemy) then screen:blit(0,0,next) screen.flip() screen.waitVblankStart(90) level4() end if collision(Player,Stick) then nbc=nbc+1 end if nbc>ncc then dofile("br.lua") end if collision(Player,Stick2) then nbc=nbc+1 end if nbc>ncc then dofile("br.lua") end 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(Stick2.x,Stick2.y,Stick2.img) screen.waitVblankStart() screen.flip() end end -------------------------------------------------------------------------level4 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 screen:blit(Stick2.x,Stick2.y,Stick2.img) if collision(Player,Stick) then nbc=nbc+1 end if nbc>ncc then dofile("br.lua") end if collision(Player,Square) then Player.img=Sball end if collision(Player,Stick2) then nbc=nbc+1 end if nbc>ncc then dofile("br.lua") end if Player.img == Sball and collision(Player,Stick2) then *Im Stuck here* end 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 --------------------------------------------------------------------------Other Function function collision(ob1,ob2) if (ob1.x + ob1.w > ob2.x) and (ob1.x < ob2.x + ob2.w) and (ob1.y + ob1.h > ob2.y) and (ob1.y < ob2.y + ob2.h) then return true else return false end end function movePlayer() pad=Controls.read() if pad:right() then Player.x=Player.x +4 end if pad:left() then Player.x=Player.x - 4 end if pad:down() then Player.y=Player.y + 4 end if pad:up() then Player.y=Player.y - 4 else if not pad:up() then Player.y=Player.y + 7 end end end falling=false ------------------------------------------------------------------------Main loop while true do screen:clear() menu1() screen.waitVblankStart() screen.flip() end
-
04-18-2007, 04:58 PM #6946
You're not killing memory, the code just doesnt flow in a very efficient way.
Zitat von Urameshi
牧来栠摩琠敨映汩獥
PSN: youresamFrom Earth the Frozen Ipaqs shall rise and be silenced and all will live free.
--Mike Hollingsworth
-
04-18-2007, 05:00 PM #6947QJ Gamer Gold
- Registriert seit
- Nov 2006
- Ort
- ...
- Beiträge
- 2.080
- Points
- 11.942
- Level
- 71
- Downloads
- 0
- Uploads
- 0
you posted to say that, and not even give a piece of advice or a step into the right direction!!!!!
-
04-18-2007, 05:06 PM #6948
..rewrite your code, the way you have it set up is very bad.
Zitat von Urameshi
牧来栠摩琠敨映汩獥
PSN: youresamFrom Earth the Frozen Ipaqs shall rise and be silenced and all will live free.
--Mike Hollingsworth
-
04-18-2007, 05:19 PM #6949QJ Gamer Gold
- Registriert seit
- Nov 2006
- Ort
- ...
- Beiträge
- 2.080
- Points
- 11.942
- Level
- 71
- Downloads
- 0
- Uploads
- 0
but im still stuck with it making it restart when they collide, what part of that do you not understand
-
04-18-2007, 06:09 PM #6950QJ Gamer Blue
- Registriert seit
- Jul 2006
- Ort
- Upstate, NY USA
- Beiträge
- 121
- Points
- 4.349
- Level
- 41
- Downloads
- 0
- Uploads
- 0
Fajita - I wanted to check flash0 space, for a simple theme flasher I've wrote. A friend tried it, and he didn't have enough flash0 space. Nothing bad happened, but it stopped writing files when the flash0 space ran out. So parts of the theme didn't show up. (click sounds).
I just wanted to check flash space, so my app would dummy some unneeded font files at boot, if you didn't have say, at least 2mb free. But I have actually found a way to check flash0 space. so i'm all set now :)
-
04-18-2007, 07:31 PM #6951Developer

- Registriert seit
- Oct 2006
- Ort
- San Diego
- Beiträge
- 177
- Points
- 4.205
- Level
- 41
- Downloads
- 0
- Uploads
- 0
what level is it reseting at?
Zitat von Urameshi
-
04-18-2007, 07:36 PM #6952QJ Gamer Gold
- Registriert seit
- Nov 2006
- Ort
- ...
- Beiträge
- 2.080
- Points
- 11.942
- Level
- 71
- Downloads
- 0
- Uploads
- 0
in level 3 and 4 when Player collides with Stick and Stick2 than its supposed to reset, but in level 4 when Player.img=Sball i dont want it to reset when it collides with Stick and Stick2, i want it to make Stick and Stick2 disappear
-
04-18-2007, 07:51 PM #6953Developer

- Registriert seit
- Oct 2006
- Ort
- San Diego
- Beiträge
- 177
- Points
- 4.205
- Level
- 41
- Downloads
- 0
- Uploads
- 0
Ok, the problem is hardcoding. You are hardcoding your collision checks with both sticks. it would be better to place the sticks into a table ie
Zitat von Urameshi
enemylist = {}
enemylist[1] = stick1
enemylist[2] = stick2
then when you check collision set a for loop to cycle through your enemy list ie
Then once table.getn(enemylist) == 0. you can have victory or whatever.Code:for i = 1,table.getn(enemylist) do -- 1 to the end of your table if collision(player, enemylist[i]) then if player == sball then table.remove(enemylist, i) else --your other code here end end end
-
04-18-2007, 07:54 PM #6954QJ Gamer Gold
- Registriert seit
- Nov 2006
- Ort
- ...
- Beiträge
- 2.080
- Points
- 11.942
- Level
- 71
- Downloads
- 0
- Uploads
- 0
thanks for helpin, unlike youresam
-
04-18-2007, 08:54 PM #6955
...
Zitat von Fajita
...
Zitat von KleptoOne
...*sigh*
Zitat von Urameshi
牧来栠摩琠敨映汩獥
PSN: youresamFrom Earth the Frozen Ipaqs shall rise and be silenced and all will live free.
--Mike Hollingsworth
-
04-18-2007, 08:58 PM #6956QJ Gamer Gold
- Registriert seit
- Nov 2006
- Ort
- ...
- Beiträge
- 2.080
- Points
- 11.942
- Level
- 71
- Downloads
- 0
- Uploads
- 0
so what if he said the same thing, i got more help from him than you
-
04-18-2007, 09:05 PM #6957
Yes, but based on what you said, I didnt help at all, which wasnt totally the case ;)
Zitat von Urameshi
Besides, reading through that code gave me a headache
牧来栠摩琠敨映汩獥
PSN: youresamFrom Earth the Frozen Ipaqs shall rise and be silenced and all will live free.
--Mike Hollingsworth
-
04-18-2007, 09:30 PM #6958QJ Gamer Gold
- Registriert seit
- Nov 2006
- Ort
- ...
- Beiträge
- 2.080
- Points
- 11.942
- Level
- 71
- Downloads
- 0
- Uploads
- 0
you wanna know what would give you a headache, here's a question for ya:
how do you blit an image i tried everyting here's my code:
Code:akl=Image.load("Images/akl.jpg") while true do --------------------------clear the screen:clear() scree:blit(0,0,akl,true) screenflip() screenwaitVblankstart() end end
-
04-18-2007, 11:20 PM #6959Monster Masher
- Registriert seit
- Jun 2006
- Ort
- Behind you...
- Beiträge
- 265
- Points
- 5.084
- Level
- 45
- Downloads
- 0
- Uploads
- 0
Why the two ends?
akl=Image.load("./Images/akl.jpg")
while true do
screen:clear
screen:blit(0,0,akl,true)
screen.flip()
screen.waitVblankstart()
end
-
04-19-2007, 12:23 AM #6960QJ Gamer Green
- Registriert seit
- Jan 2007
- Ort
- beside my PC
- Beiträge
- 520
- Points
- 6.446
- Level
- 52
- Downloads
- 0
- Uploads
- 0
mm i use this
Zitat von SG57
so does it mean i need to change all of it?Code:if pad:up() and oldpad:up() ~= pad:up() then current = current-1 end


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