Advertising (This ad goes away for registered users. You can Login or Register)

[LUA] Need help with code plz

Forum rules
Forum rule Nº 15 is strictly enforced in this subforum.
qwikrazor87
Guru
Posts: 2874
Joined: Sat Apr 21, 2012 1:23 pm
Location: The North Pole

Re: [LUA] Need help with code plz

Post by qwikrazor87 »

Here is your code from the fifth post on the second page.

Code: Select all

--Created by dragonxtamer596

--On the 10/25/12


Room_width = 480 
Room_height = 272 
player1x =240
player1y =136
---Load Sprites --- 
background =Image.load ("images/Background.PNG")
player1=Image.load("images/Player1.PNG")

------functions 
function checkcontrols()
pad = Controls.read()
if pad:start() then
return false
end

if pad:right() then
player1x = player1x +2
end

if pad:left() then
player1x = player1x -2
end

if pad:up() then
player1y = player1y  -2
end

if pad:down() then
player1y = player1y +2
end
end

function drawall() 
screen:blit (0,0,background)
screen:blit(player1x,player1y,player1)
screen.waitVblankStart()
screen.flip()
end

-- MAIN LOOP 
while true do 
end
In the last one you made some loops inside the functions. When you run the code the program will stayed looped on the first function you call until you break the loop.
Here is your code that I revised.

Code: Select all

CODE: SELECT ALL
--Created by dragonxtamer596

--On the 10/25/12


Room_width = 480 
Room_height = 272 
player1x =240
player1y =136
---Load Sprites --- 
background =Image.load ("images/Background.PNG")
player1=Image.load("images/Player1.PNG")

------functions 
function checkcontrols()
pad = Controls.read()
if pad:start() then
  break
end

if pad:right() then
player1x = player1x +2
end

if pad:left() then
player1x = player1x -2
end

if pad:up() then
player1y = player1y  -2
end

if pad:down() then
player1y = player1y +2
end
end

function drawall() 
screen:blit (0,0,background)
screen:blit(player1x,player1y,player1)
screen.waitVblankStart()
screen.flip()
end 

-- MAIN LOOP 
while true do 
checkcontrols()
drawall()
end
In the checkcontrols() function you can see that I added break inside the pad:start() statement. That will break the loop inside Game.txt and return back to your menu.
You can see that I added your functions to the while true do loop.
The only time you use "function" is when you are creating one, you do not use it when running it.

You are doing very good, all you had to do was place your functions in the loop.
Advertising
PSP 2001 - TA-085 - 6.61 PRO-C2
PS Vita 3G - PCH-1101 - 3.65 HENkaku Ensō
Alcatel phone - Android 8.1.0
Laptop - Toshiba Satellite L305D-S5974 - Ubuntu 16.04 LTS
dragonxtamer596
Posts: 188
Joined: Wed Oct 24, 2012 11:49 pm
Contact:

Re: [LUA] Need help with code plz

Post by dragonxtamer596 »

qwikrazor87 wrote:Here is your code from the fifth post on the second page.

Code: Select all

--Created by dragonxtamer596

--On the 10/25/12


Room_width = 480 
Room_height = 272 
player1x =240
player1y =136
---Load Sprites --- 
background =Image.load ("images/Background.PNG")
player1=Image.load("images/Player1.PNG")

------functions 
function checkcontrols()
pad = Controls.read()
if pad:start() then
return false
end

if pad:right() then
player1x = player1x +2
end

if pad:left() then
player1x = player1x -2
end

if pad:up() then
player1y = player1y  -2
end

if pad:down() then
player1y = player1y +2
end
end

function drawall() 
screen:blit (0,0,background)
screen:blit(player1x,player1y,player1)
screen.waitVblankStart()
screen.flip()
end

-- MAIN LOOP 
while true do 
end
In the last one you made some loops inside the functions. When you run the code the program will stayed looped on the first function you call until you break the loop.
Here is your code that I revised.

Code: Select all

CODE: SELECT ALL
--Created by dragonxtamer596

--On the 10/25/12


Room_width = 480 
Room_height = 272 
player1x =240
player1y =136
---Load Sprites --- 
background =Image.load ("images/Background.PNG")
player1=Image.load("images/Player1.PNG")

------functions 
function checkcontrols()
pad = Controls.read()
if pad:start() then
  break
end

if pad:right() then
player1x = player1x +2
end

if pad:left() then
player1x = player1x -2
end

if pad:up() then
player1y = player1y  -2
end

if pad:down() then
player1y = player1y +2
end
end

function drawall() 
screen:blit (0,0,background)
screen:blit(player1x,player1y,player1)
screen.waitVblankStart()
screen.flip()
end 

-- MAIN LOOP 
while true do 
checkcontrols()
drawall()
end
In the checkcontrols() function you can see that I added break inside the pad:start() statement. That will break the loop inside Game.txt and return back to your menu.
You can see that I added your functions to the while true do loop.
The only time you use "function" is when you are creating one, you do not use it when running it.

You are doing very good, all you had to do was place your functions in the loop.
Oh, I see now thanks a lot. :) Is it possible to make a certain area of the map/picture bring you to a new map/picture? Also is it possible to make a collision of one player to another so the opposite player is it, like tag, and make it show who's it, the tagger?
Advertising
qwikrazor87
Guru
Posts: 2874
Joined: Sat Apr 21, 2012 1:23 pm
Location: The North Pole

Re: [LUA] Need help with code plz

Post by qwikrazor87 »

dragonxtamer596 wrote:Oh, I see now thanks a lot. :) Is it possible to make a certain area of the map/picture bring you to a new map/picture? Also is it possible to make a collision of one player to another so the opposite player is it, like tag, and make it show who's it, the tagger?
Yes all those are possible, you can code anything you want within the limitations of Lua. :)
PSP 2001 - TA-085 - 6.61 PRO-C2
PS Vita 3G - PCH-1101 - 3.65 HENkaku Ensō
Alcatel phone - Android 8.1.0
Laptop - Toshiba Satellite L305D-S5974 - Ubuntu 16.04 LTS
dragonxtamer596
Posts: 188
Joined: Wed Oct 24, 2012 11:49 pm
Contact:

Re: [LUA] Need help with code plz

Post by dragonxtamer596 »

What is the best luaplayer for this?
qwikrazor87
Guru
Posts: 2874
Joined: Sat Apr 21, 2012 1:23 pm
Location: The North Pole

Re: [LUA] Need help with code plz

Post by qwikrazor87 »

dragonxtamer596 wrote:What is the best luaplayer for this?
I would suggest using LuaDEV R0.
LuaDEV R0 EBOOT.PBP
Make a newfolder inside "ms0:/PSP/GAME/" and place the eboot there.
Here is the LuaDEV R0 manual.chm which is in Spanish.
LuaDEV R0 manual.chm

You can find the undocumented functions here.

The reason I like LuaDEV is that most of the functions are lower cased with the exception of color.R(), color.G(), color.B() and color.A().
It has the best mp3 compatibility out of all the ones I tested. I tested VBR mp3 songs which all worked.
It has a very good graphics engine which I use to make the background and eboot images for my apps.

You can also use PGE Lua 0.02. But I would suggest LuaDEV R0 over this because you have to work a little more to get things working . You can check it out too to see which one you like better.
PSP 2001 - TA-085 - 6.61 PRO-C2
PS Vita 3G - PCH-1101 - 3.65 HENkaku Ensō
Alcatel phone - Android 8.1.0
Laptop - Toshiba Satellite L305D-S5974 - Ubuntu 16.04 LTS
Different55
Posts: 130
Joined: Thu Jun 07, 2012 9:28 pm

Re: [LUA] Need help with code plz

Post by Different55 »

Thanks for those links, quik. *downloads everything*
qwikrazor87
Guru
Posts: 2874
Joined: Sat Apr 21, 2012 1:23 pm
Location: The North Pole

Re: [LUA] Need help with code plz

Post by qwikrazor87 »

Different55 wrote:Thanks for those links, quik. *downloads everything*
You're welcome. :)
I forgot to mention that you need to place "script.lua" in the folder where the eboot is located.
PSP 2001 - TA-085 - 6.61 PRO-C2
PS Vita 3G - PCH-1101 - 3.65 HENkaku Ensō
Alcatel phone - Android 8.1.0
Laptop - Toshiba Satellite L305D-S5974 - Ubuntu 16.04 LTS
dragonxtamer596
Posts: 188
Joined: Wed Oct 24, 2012 11:49 pm
Contact:

Re: [LUA] Need help with code plz

Post by dragonxtamer596 »

qwikrazor87 wrote:
dragonxtamer596 wrote:What is the best luaplayer for this?
I would suggest using LuaDEV R0.
LuaDEV R0 EBOOT.PBP
Make a newfolder inside "ms0:/PSP/GAME/" and place the eboot there.
Here is the LuaDEV R0 manual.chm which is in Spanish.
LuaDEV R0 manual.chm

You can find the undocumented functions here.

The reason I like LuaDEV is that most of the functions are lower cased with the exception of color.R(), color.G(), color.B() and color.A().
It has the best mp3 compatibility out of all the ones I tested. I tested VBR mp3 songs which all worked.
It has a very good graphics engine which I use to make the background and eboot images for my apps.

You can also use PGE Lua 0.02. But I would suggest LuaDEV R0 over this because you have to work a little more to get things working . You can check it out too to see which one you like better.
TY, also can you tell me what those 3 apps of yours do?
qwikrazor87
Guru
Posts: 2874
Joined: Sat Apr 21, 2012 1:23 pm
Location: The North Pole

Re: [LUA] Need help with code plz

Post by qwikrazor87 »

dragonxtamer596 wrote:TY, also can you tell me what those 3 apps of yours do?
PSPBPacker edits eboots, you can use it to add, change or remove files from the eboot, rename the title and all that.
PSPID3Editor, you can add or edit mp3 ID3 tags, title, artist, album, genre and album art.
PSPlaylister, you can use it to make playlists that you can listen to in the XMB, you can also import playlists from SensMe channels.

For more information you can check the link in my signature. :)
PSP 2001 - TA-085 - 6.61 PRO-C2
PS Vita 3G - PCH-1101 - 3.65 HENkaku Ensō
Alcatel phone - Android 8.1.0
Laptop - Toshiba Satellite L305D-S5974 - Ubuntu 16.04 LTS
Different55
Posts: 130
Joined: Thu Jun 07, 2012 9:28 pm

Re: [LUA] Need help with code plz

Post by Different55 »

PSPBPacker is my favorite one.
Post Reply

Return to “Programming and Security”