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.
dragonxtamer596
Posts: 188
Joined: Wed Oct 24, 2012 11:49 pm
Contact:

Re: [LUA] Need help with code plz

Post by dragonxtamer596 »

qwikrazor87 wrote:Don't give up so soon. I was just where you are. You will go through a lot of trial and error when programming. Don't overwhelm yourself by trying to make a big project at first, take some time to learn what each function does and experiment with it.
You won't learn everything in a short amount of time, it requires a lot of patience. Consider taking a look at the tutorials I linked.
I will look at the links, but I'm quitting this and moving to my first lua program i made a make changes there.
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:I will look at the links, but I'm quitting this and moving to my first lua program i made a make changes there.
A fresh start sounds like a good idea.
Whatever problems you run across I will try my best to help you out.
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:
dragonxtamer596 wrote:I will look at the links, but I'm quitting this and moving to my first lua program i made a make changes there.
A fresh start sounds like a good idea.
Whatever problems you run across I will try my best to help you out.
Okay I have an actual game this time and not a program.
error game lua 46 end expected to close function at line 15 near <eof>
code- also if you see any other errors can you please point them out as well and explain why they were errors.

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

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

-- MAIN LOOP 
while true do 
end
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 »

You forgot to end the checkcontrols() function. Right before drawall() is where you should end the function.

Code: Select all

end

function drawall()
Looking at the controls the left and right are inverted. If you press right the image will move left, press left then the image will move right. I don't know if you intended that but if you didn't then you may want to change it.
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 »

like that? okay I have no errors but from the menu I click game and nothing happens what now?

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

Code: Select all

blue = Color.new(0, 50, 175)
white = Color.new(255,255,255)

ms = 1
mms = 4

oldpad = Controls.read()

while true do
screen:clear()
pad = Controls.read()

if pad:up() and oldpad:up() ~= pad:up() then
ms = ms - 1
end
if pad:down() and oldpad:down() ~= pad:down() then
ms = ms + 1
end
if ms > mms then
ms = 1
elseif ms <= 0 then
ms = mms
end

mc = { white,white,white,white,white }
mc[ms] = blue
screen:print(98,107,"Game",mc[1])
screen:print(98,117,"Option 2",mc[2])
screen:print(98,127,"Option 3",mc[3])
screen:print(98,137,"Option 4",mc[4])
screen:print(98,147,"Option 5",mc[5])

if pad:cross() and not oldpad:cross() and ms == 1 then
dofile("Game.lua")
end

if pad:cross() and not oldpad:cross() and ms == 2 then
end

if pad:cross() and not oldpad:cross() and ms == 3 then
end

if pad:cross() and not oldpad:cross() and ms == 4 then
end

if ms <= 0 then
ms = 4
end

if ms >= 5 then
ms = 1
end

screen.waitVblankStart()
screen.flip()
oldpad = pad
end
Last edited by dragonxtamer596 on Mon Oct 29, 2012 1:18 am, edited 3 times in total.
Different55
Posts: 130
Joined: Thu Jun 07, 2012 9:28 pm

Re: [LUA] Need help with code plz

Post by Different55 »

You'd probably want to put all that inside the main loop, otherwise those all get executed once and then it goes into the looping forever doing nothing, and you never want an empty loop. Put a screen.waitVblankStart() inside a loop that would otherwise be empty.

But other than the loop, yeah, looks good from over here.
dragonxtamer596
Posts: 188
Joined: Wed Oct 24, 2012 11:49 pm
Contact:

Re: [LUA] Need help with code plz

Post by dragonxtamer596 »

Different55 wrote:You'd probably want to put all that inside the main loop, otherwise those all get executed once and then it goes into the looping forever doing nothing, and you never want an empty loop. Put a screen.waitVblankStart() inside a loop that would otherwise be empty.

But other than the loop, yeah, looks good from over here.
So?

Code: Select all

while true do
-- game code here
end
and?

Code: Select all

while true do
screen.waitVblankStart()
end
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 »

Inside the loop place the functions that you created.

Code: Select all

while true do
checkcontrols()
drawall()
end
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 »

EDIT:
*erase*
What quik said.
Right now your script defines some variables, loads two images, defines some functions, and sets off an on endless journey to nowhere.
dragonxtamer596
Posts: 188
Joined: Wed Oct 24, 2012 11:49 pm
Contact:

Re: [LUA] Need help with code plz

Post by dragonxtamer596 »

Different55 wrote:EDIT:
*erase*
What quik said.
Right now your script defines some variables, loads two images, defines some functions, and sets off on an endless journey to nowhere.
So what's your point? If you have some useful info to give me post it.
Anyway Is this good?

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()
while true do
screen:clear()
pad = Controls.read()

if pad:start() then
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
end

while true do
function drawall() 
screen:blit (0,0,background)
screen:blit(player1x,player1y,player1)
screen.waitVblankStart()
screen.flip()
end
end 
and when I had it like this it didn't work. As in when I pressed Game in menu it didn't load the game but the game has no errors.

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()
while true do
screen:clear()
pad = Controls.read()

if pad:start() then
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
end

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

Return to “Programming and Security”