help a noob

Discuss using and improving Lua and the Lua Player specific to the PSP.

Moderators: Shine, Insert_witty_name

Post Reply
Iximon
Posts: 5
Joined: Thu Sep 08, 2005 6:16 am

help a noob

Post by Iximon »

i have just started to play whit lua and have done the hello world. but i cant use it on my psp because i have 1.52 :( so i use the win emu. i have also made the animation tutorial, but i have a problem whit my own program i have started with. ist very simpel. but i cant compile it. here is the code:

Code: Select all

background = Image.load("background.png")
player = Image.load("player.png")

while true do
	screen:blit(0, 0, background, 0, 0, background:width(), background:height(), false)

	x = 200
	y = 135

	screen:blit(x, y, player)
	end

	pad = Controls.read()
	if pad:right() then
	x = x + 1
	end

	if pad:left() then
	x = x - 1
	end

	if pad:up() then
	y = y + 1
	end

	if pad:down() then
	y = y - 1
	end

	screen:waitVblankStart()
	screen:flip()

end
when i try to compile i get a error: <eof> expected near 'end' and i have no ide how to fix it. can u please tell me what i have done wrong.
zhaD
Posts: 5
Joined: Wed Sep 07, 2005 5:28 am
Location: Québec/Canada

Post by zhaD »

<eof> expected near 'end'

guess it means it expected the end of the script file instead of 'end' (on last line).

looking at your code Id say you should remove the 'end' under :

x = 200
y = 135

screen:blit(x, y, player)
end <---

as it doesnt seem to be related to any if or while
ksilvert
Posts: 5
Joined: Tue Sep 06, 2005 12:02 am

Post by ksilvert »

If you're trying to have the 'player' move around based on the D pad selection, you'll need to move these two lines above the beginning of the while loop or your image won't move.

x = 200
y = 135
LuMo
Posts: 410
Joined: Sun Aug 21, 2005 2:45 am
Location: Austria
Contact:

Post by LuMo »

Code: Select all

while not Controls.read&#40;&#41;&#58;start&#40;&#41; do 
would enable to leave the program again (eg for use in lowser)
F34R
Posts: 29
Joined: Thu Jul 28, 2005 1:11 pm

Post by F34R »

Here's a little code that I wrote to control an object moving with the dpad. It also tells you what direction you are pressing, along with the buttons (circle, square, cross, triangle) that you are pressing.

Code: Select all

-- Activate USB Mode
System.usbDiskModeActivate&#40;&#41;

-- Get colors for text
white = Color.new&#40;255, 255, 255&#41;
red = Color.new&#40;255, 0, 0&#41;

-- Load images
square = Image.load&#40;"square.png"&#41;  -- This is the object we'll be controlling


-- Set starting X/Y positions
x = 200
y = 100 


while true do
pad = Controls.read&#40;&#41;

-- This all should be relatively easy to follow from here

if pad&#58;up&#40;&#41; then
	screen&#58;clear&#40;&#41;
	screen&#58;print&#40;200,1, "You Pressed Up", white&#41; 
	y = y - 5
	if y < -4 then
		y = -4
	end
end


if pad&#58;down&#40;&#41; then
	screen&#58;clear&#40;&#41;
	screen&#58;print&#40;200,1, "You Pressed Down", white&#41;
	y = y + 5
	if y > 230 then
		y = 230
	end
end


if pad&#58;left&#40;&#41; then
	screen&#58;clear&#40;&#41;
	screen&#58;print&#40;200,1, "You Pressed Left", white&#41;
	x = x - 5
	if x < -4 then
		x = -4
	end
	
end


if pad&#58;right&#40;&#41; then
	screen&#58;clear&#40;&#41;
	screen&#58;print&#40;200,1, "You Pressed Right", white&#41;
	x = x + 5
	if x > 440 then
		x = 440
	end
	
end


if pad&#58;cross&#40;&#41; then
	screen&#58;clear&#40;&#41;
	screen&#58;print&#40;200,1, "You Pressed &#91;CROSS&#93;", white&#41;
end


if pad&#58;triangle&#40;&#41; then
	screen&#58;clear&#40;&#41;
	screen&#58;print&#40;200,1, "You Pressed &#91;TRIANGLE&#93;", white&#41;
end


if pad&#58;square&#40;&#41; then
	screen&#58;clear&#40;&#41;
	screen&#58;print&#40;200,1, "You Pressed &#91;SQUARE&#93;", white&#41;
end


if pad&#58;circle&#40;&#41; then
	screen&#58;clear&#40;&#41;
	screen&#58;print&#40;200,1, "You Pressed &#91;CIRCLE&#93;", white&#41;
end

if pad&#58;start&#40;&#41; then
		break
	end

-- Draw my little square

screen&#58;blit&#40;x, y, square&#41; -- Draws to offscreen
screen.flip&#40;&#41; -- flips offscreen to onscreen

end
Iximon
Posts: 5
Joined: Thu Sep 08, 2005 6:16 am

Post by Iximon »

i have made some progres, but i have a problem. my images dont turn invisible. the color i dont want in my game, show up. i have lookt at other games images and i have taken the same color. 255, 0, 255 but it wont disepere. i also wondering hor to make a array. is there any tutorials for the array making. sorry for my english. :( here is the code:

Code: Select all

background = Image.load&#40;"images/background.png"&#41;
-- ladda bakgrundsbild
player = Image.load&#40;"images/marioright2.png"&#41;
-- ladda spelarbild
board = Image.load&#40;"images/board.png"&#41;
-- ladda animation
moveright1 = Image.load&#40;"images/marioright1.png"&#41;
moveright2 = Image.load&#40;"images/marioright2.png"&#41;
moveright3 = Image.load&#40;"images/marioright3.png"&#41;

moveleft1 = Image.load&#40;"images/marioleft1.png"&#41;
moveleft2 = Image.load&#40;"images/marioleft2.png"&#41;
moveleft3 = Image.load&#40;"images/marioleft3.png"&#41;

player = moveright1
-- ladda board
playerx = 100
playery = 100
move = 0
-- var x och y kordinaterna ska vara ifrån start
speed = 1
-- bestämmer hastigheten på player
green = Color.new&#40;0, 255, 0&#41;
-- delkarera green till färgen grön

bPressOnce1 = 0
bPressOnce2 = 0

while true do
	pad = Controls.read&#40;&#41; -- kontrollerna
	if pad&#58;left&#40;&#41; then
		if bPressOnce1 == 0 then
			move= 0
		end
		
		bPressOnce1 = true;
		playerx = playerx - speed
		move = move + 1
		
		if move == 1 then
			player = moveleft1			
		end
		if move == 8 then
			player = moveleft2
		end		
		if move == 15 then
			player = moveleft3
			move = 0
		end
	end

	if pad&#58;left&#40;&#41; == 0 then
		bPressOnce1 = false
	end


	if pad&#58;right&#40;&#41; then
		if bPressOnce2 == 0 then
			move = 0
		end		
		
		bPressOnce2 = true;
		playerx = playerx + speed
		move = move + 1
		
			if move == 1 then
			player = moveright1			
		end
		if move == 8 then
			player = moveright2
		end		
		if move == 15 then
			player = moveright3
			move = 0
		end
	end
		if pad&#58;right&#40;&#41; == 0 then
		bPressOnce2 = false
	end
	if pad&#58;up&#40;&#41; then
		playery = playery - speed
	end

	if pad&#58;down&#40;&#41; then
		playery = playery + speed
	end
	
	if pad&#58;cross&#40;&#41; then
		break
	end
	
	if pad&#58;triangle&#40;&#41; then
		speed = speed + 0.5
	end
	
	if pad&#58;square&#40;&#41; then
		speed = speed - 0.5
	end
	
	if playerx > 448 then -- blockera så att den inte kan åka utanför skärmen &#58;&#41;
		playerx = 448
	end
	
	if playerx < 0 then
		playerx = 0
	end
	
	if playery > 240 then
		playery = 240
	end
	
	if playery < 0 then
		playery = 0
	end				--här sluta blockeringen
	
	screen&#58;blit&#40;0, 0, background, 0, 0, background&#58;width&#40;&#41;, background&#58;height&#40;&#41;, false&#41;
	-- blitta bakgrunden till skärmen
	screen&#58;blit&#40;playerx, playery, player&#41;
	--blitta player till skärmen
	screen&#58;blit&#40;0, 0, board&#41;
	screen&#58;print&#40;4, 4, "Speed&#58;", green&#41;
	screen&#58;print&#40;50, 4, speed, green&#41;
	screen&#58;print&#40;4, 14, "X pos&#58;", green&#41;
	screen&#58;print&#40;50, 14, playerx, green&#41;
	screen&#58;print&#40;4, 24, "Y pos&#58;", green&#41;
	screen&#58;print&#40;50, 24, playery, green&#41;
	-- skriver ut speed, Y och X  värden i vänstra hörnet på skärmen
	screen.waitVblankStart&#40;&#41;
	screen.flip&#40;&#41;
	-- vänd skärmen så att man ser allt.
end
Post Reply