QJ.NET | Videos | Forums | iPhone | MMORPG | Nintendo DS | Wii | PlayStation 3 | PSP | Xbox 360 | PC | Downloads | Contact Us
Forums | Gaming News | Videos | Downloads | Today's Posts | Mark Forums Read | Chat | FAQ | Members List | Contact

QJ.net Game Discussion - PSP, Xbox, Wii, PS3, PSP Homebrew, and PSP Guides

Go Back   QJ.net Game Discussion - PSP, Xbox, Wii, PS3, PSP Homebrew, and PSP Guides > Developers Corner > PSP Development, Hacks, and Homebrew > PSP Development Forum
The above video goes away if you are a member and logged in, so log in now!

Lua Help :(

This is a discussion on Lua Help :( within the PSP Development Forum forums, part of the PSP Development, Hacks, and Homebrew category; my code wont work, its spposed to load the menu, push something, and load level. my code: CODE: tiles = ...

Reply
 
LinkBack Thread Tools
Old 12-03-2005, 03:51 PM   #1

Asleep...
 
Join Date: Oct 2005
Posts: 1,382
Trader Feedback: 0
Default Lua Help :(

my code wont work, its spposed to load the menu, push something, and load level. my code:

Quote:
CODE:
tiles = Image.load("data/tiles.png")
figure = Image.load("data/figure.png")
menu = Image.load("data/menu.png")
white = Color.new(255, 255, 255)
-- Menu
onmenu = 1
-- Menu Control
menuy = 100
-- Menu Time
menutime = 0

-- Current Level
level = 1

-- Level Score
levelscore = 0
-- Score
score = 0
function level1()
-- the map
mapSource = {
"mmmmmmmmmmmmmmmmmmmmmmmm m mmmmm",
"meaaaaaaaaaaaaaaaaaaaafa a aaafm",
"mdnnnnbnnnnnnnnnnnnonndn n npnbm",
"mdnonnbnnnnnbnnnnnnnnndn n nnnbm",
"mdnnnnnnnbnnbnnccccccchc c ccnnm",
"mecccccccgnnnnnnnnnnnndn b nnnbm",
"mdnnnnnnnnnnnnnnnnnnnndn b nnnbm",
"mdnnnnnnnnnnnnnnnnbnnndc c nnnbm",
"mdnnecccccccccccnnbnnndn n nnnbm",
"mdnnbnnnnnbnnnnbnnbnnndn n nnnbm",
"mdnnbnnonnbnnonbnnbnnndn n nnnbm",
"mdnnbnnnnnbnnnnbnnbnnndn n nccbm",
"mdnnbnnccccnnnnbnnbnnndn n nnnbm",
"mdnnbnnnnnnnnnnnnnbnnnnn n nnnbm",
"mdnnbnnnnnnnnnnnnnbnnnnn n nnnbm",
"mhccgcccccccccccccgccccc c cccgm",
"mmmmmmmmmmmmmmmmmmmmmmmm m mmmmm"
}
-- offsreen image, where the map will be drawn
board = Image.createEmpty(480, 272)

-- draw one tile on the map
function drawTile(tile, x, y)
tile = string.byte(tile, 1) - string.byte("a")
local tileX = math.mod(tile, 4)
local tileY = math.floor(tile / 4)
board:blit(16 * x, 16 * y, tiles, 17 * tileX + 1, 17 * tileY + 1, 16, 16, false)
end

-- copy the map source to an array for easier access and draw the offscreen board
map = {}
for y = 1, 17 do
line = mapSource[y]
map[y] = {}
for x = 1, 30 do
tile = string.sub(line, x, x)
map[y][x] = tile
drawTile(tile, x - 1, y - 1)
end
end

-- current player position
playerX = 3
playerY = 14

-- current player animation image
animation = 0

-- 1 = animation images increases, -1: decreases
animationDirection = 1

-- animation slowdown counter
animationSlowDown = 0

-- controls the movement speed. At speedStep == 0, the last
-- pad will be evaluated, other steps the pad movements are only
-- saved
speedStep = 0

-- last pad direction
dx = 0
dy = 0

-- current score
score = 0

-- text color
white = Color.new(255, 255, 255)

while true do
-- read current pad
pad = Controls.read()

if pad:start() then
-- exit to lowser, if started from there
break
end
if speedStep == 0 then
-- save old player position
oldPlayerX = playerX
oldPlayerY = playerY

-- add last movement
playerX = playerX + dx
playerY = playerY + dy

-- check new tile
newTile = map[playerY][playerX]

-- if the position is not allowed, restore old player position
if newTile ~= "n" and newTile ~= "p" and newTile ~= "o" then
playerX = oldPlayerX
playerY = oldPlayerY
end

-- if it is a tile which can be eaten, eat it
if newTile == "p" then score = score + 5 end
if newTile == "o" then score = score + 1 end
if newTile == "p" or newTile == "o" then
-- set background tile
map[playerY][playerX] = "n"

-- draw background tile
drawTile("n", playerX - 1, playerY - 1)
end

-- reset last movement
dx = 0
dy = 0
else
-- check pad movement
if pad:up() then
dy = -1
elseif pad:down() then
dy = 1
elseif pad:left() then
dx = -1
elseif pad:right() then
dx = 1
end
end

-- update speed step counter
speedStep = speedStep + 1
if speedStep == 5 then
speedStep = -1
end

-- blit board
screen:blit(0, 0, board, 0, 0, board:width(), board:height(), false)

-- blit current player animation image
screen:blit((playerX - 1) * 16 - 4, (playerY - 1) * 16 - 4, figure, 1 + 25 * animation, 1, 24, 24)

-- calculate next animation image
animationSlowDown = animationSlowDown + 1
if animationSlowDown == 3 then
animationSlowDown = 0
animation = animation + animationDirection
if animation == 4 then
animationDirection = -1
elseif animation == 0 then
animationDirection = 1
end
end

-- print score
screenrint(10, 260, "BY HEDZX, SCORE:" .. score, white)
-- wait for vertical sync and show new screen
screen.waitVblankStart()
screen:flip()
end
while true do

-- Clear Screen
screen:clear()

-- Show Background
showbackground()

-- Menu
if onmenu == 1 then
screen:blit(165,80, menu)
mainmenuscreen()
screenrint(198, 100, "Start", white)

pad2 = Controls.read()

if pad2:up() then
if menutime == 0 then
if menuy > 100 then
menuy = menuy - 10
end
menutime = 1
end
end

if pad2:down() then
if menutime == 0 then
if menuy < 120 then
menuy = menuy + 10
end
menutime = 1
end
end

if pad2:cross() then
if menuy == 100 then
onmenu = 0
screen:clear()
showbackground()
level1()
screen:flip()
screen.waitVblankStart(18 0) -- Wait 3 seconds
screen:clear()
end
if menuy == 110 then
onmenu = 3
screen.waitVblankStart(15 )
end
if menuy == 120 then
onmenu = 2
screen.waitVblankStart(15 )
end
end

-- Timer for Menu Selecting
if menutime >= 1 then
menutime = menutime + 1
end
if menutime == 5 then
menutime = 0
end
screenrint(180, menuy, "->", white)
end
end
-- Read Controls pressed and change cursor location
pad = Controls.read()
taken from console shooter...... and get this error:

Quote:
error:untl.lua:240: 'end' expected (to close 'function' at line 19) near '<eof>'
Error: No script file found.
Press start to restart
tnx
__________________
Hedzx is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 12-03-2005, 04:15 PM   #2
 
InhumanElmo's Avatar
 
Join Date: Oct 2005
Location: OMG where AM I!?!?!?!?
Posts: 820
Trader Feedback: 0
Default

You need an end somewhere. I have been getting the same error. Also your code is a little off. Or atleast to me. I think that the Controls.read() belongs above the point where u have the actual what if statements for the button input.
__________________
[SPOILER="For PSP History"]1.50 > 1.52 > 2.00 > 1.5 > 1.5 (POC CF) > 1.5 (Harleyg) > 1.5 (Casual) > 3.03 OE-A > 3.03 OE-C[/SPOILER]
Check it out: [URL="http://youtube.com/watch?v=xNVPKM07TWs&mode=related&search="]Pen Spinning[/URL]
InhumanElmo is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Tags
lua

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off



All times are GMT -8. The time now is 03:03 AM.



Use of this Web site constitutes acceptance of the TERMS & CONDITIONS and PRIVACY POLICY
Copyright © 2009, QJ.NET. All Rights Reserved.
Contact Us