PDA

View Full Version : can somebody please tell me what I'm doing wrong with my lua script?



lmtlmt
August 28th, 2006, 12:39
can somebody please tell me what I'm doing wrong with my lua script?do the images work if they are jpeg? the menu works


-- EVILMANA.COM PSP LUA CODEBASE
-- www.evilmana.com/tutorials/codebase
-- Menu
-- SUBMITTED BY: KIWI
red = Color.new(255, 0, 0)
white = Color.new(255, 255, 255)

--Variables
Select = 1
maxSelect = 2
oldpad = Controls.read()
--loop
while true do
pad = Controls.read()
screen:clear()
--checar decicion
if pad:up() and oldpad:up() ~= pad:up() then
Select = Select - 1
end
if pad:down() and oldpad:down() ~= pad:down() then
Select = Select + 1
end
if Select > maxSelect then
Select = 1
elseif Select <= 0 then
Select = maxSelect
end
if Select == 1 then
screen:print(334,202,"2 PLAYER", red)
screen:print(334,220,"EXIT",white)
end
if Select == 2 then
screen:print(334,202,"2 PLAYER", white)
screen:print(334,220,"EXIT",red)
end
if pad:cross() and Select == 1 then
dofile("duel.lua")
end
if pad:cross() and Select == 2 then
break
end
screen.waitVblankStart()
screen.flip()
oldpad = pad
end



but this part doesnt
--IMAGES
background = Image.load("YUGI BACKGROUND.png")
title = Image.load("title.png")
card1 = Image.load("SDY-001.jpeg")
card2 = Image.load("SDY-002.jpeg")
card3 = Image.load("SDY-003.jpeg")
card4 = Image.load("SDY-004.jpeg")
card5 = Image.load("SDY-005.jpeg")
card6 = Image.load("SDY-006.jpeg")
card7 = Image.load("SDY-007.jpeg")
card8 = Image.load("SDY-008.jpeg")
card9 = Image.load("SDY-009.jpeg")
card10 = Image.load("SDY-010.jpeg")
card11 = Image.load("SDY-011.jpeg")
card12 = Image.load("SDY-012.jpeg")
card13 = Image.load("SDY-013.jpeg")
card14 = Image.load("SDY-014.jpeg")
card15 = Image.load("SDY-015.jpeg")
card16 = Image.load("SDY-016.jpeg")
card17 = Image.load("SDY-017.jpeg")
card18 = Image.load("SDY-018.jpeg")
card19 = Image.load("SDY-019.jpeg")
card20 = Image.load("SDY-020.jpeg")
card21 = Image.load("SDY-021.jpeg")
card22 = Image.load("SDY-022.jpeg")
card23 = Image.load("SDY-023.jpeg")
card24 = Image.load("SDY-024.jpeg")
card25 = Image.load("SDY-025.jpeg")
card26 = Image.load("SDY-026.jpeg")
card27 = Image.load("SDY-027.jpeg")
card28 = Image.load("SDY-028.jpeg")
card29 = Image.load("SDY-029.jpeg")
card30 = Image.load("SDY-030.jpeg")
card31 = Image.load("SDY-031.jpeg")
card32 = Image.load("SDY-032.jpeg")
card33 = Image.load("SDY-033.jpeg")
card34 = Image.load("SDY-034.jpeg")
card35 = Image.load("SDY-035.jpeg")
card36 = Image.load("SDY-036.jpeg")
card37 = Image.load("SDY-037.jpeg")
card38 = Image.load("SDY-038.jpeg")
card39 = Image.load("SDY-039.jpeg")
card40 = Image.load("SDY-040.jpeg")
card41 = Image.load("SDY-041.jpeg")
card42 = Image.load("SDY-042.jpeg")
card43 = Image.load("SDY-043.jpeg")
card44 = Image.load("SDY-044.jpeg")
card45 = Image.load("SDY-045.jpeg")
card46 = Image.load("SDY-046.jpeg")
card47 = Image.load("SDY-047.jpeg")
card48 = Image.load("SDY-048.jpeg")
card49 = Image.load("SDY-049.jpeg")
card50 = Image.load("SDY-050.jpeg")
cardback = Image.load("about_fraud_back_auth.jpeg")

-- COLOURS
black = Color.new(0, 0, 0)
white = Color.new(255, 255, 255)
blue = Color.new(0, 128, 255)
red = Color.new(255, 0, 0)
green = Color.new(0, 255, 0)

-- sounds
introsnd = Sound.load(("Yugioh GX English theme.mp3")

screen:blit(0, 0, title)

while true do
screen.waitVblankStart()
end


and here is the rar of all the images and the script and the script.cmd but i have removed the sound beacause it was 10 mb so just delete the line of code that says , i am trying to make a game but i have to make the title screen first, any help would be much appreciated.


ps. this is just the beta: version1.0 will have 50 cards, and version 2.0 will have 100 cards, and that might be it, but if people like it i will continue to0 update it

lmtlmt
August 29th, 2006, 07:21
how would i set attack and defence points to each image/card, could i use variables and could it be used to determine how many life points to subtract.

Gizmo356
August 29th, 2006, 07:36
Dont Do That If I Could Help I Would But Im Not Home Im Using My Cell Phone So I Cant Help

Gizmo356
August 29th, 2006, 16:45
No It Can Play A Lot More And You Could Store Attk And Def Points In A Table

lmtlmt
August 30th, 2006, 11:26
here is an example of what the cards on the game will be like, the big one is the card when it is in your hand and the little one is the card when its on the field

lmtlmt
August 30th, 2006, 11:57
is this table good enough for this type of game, the table is for this card, here is the table


mystical elf = { 800, 2000, 4, "[spellcaster]" }
mystical elf[1] = "attack"
mystical elf[2] = "defence"
mystical elf[3] = "level"
mystical elf[4] = "type"
or should the table be like this

mystical_elf = { 800, 2000, 4, "[spellcaster]" }
attack = mystical_elf[1]
defence = mystical_elf[2]
level = mystical_elf[3]
type = mystical_elf[4]
ps> how do i make it so when that card id selected that information is printed to the screen next to it:confused:

do i do this


screen:print(100, 100, mystical_elf[1],green)
screen:print(100, 140, mystical_elf[2],green)
screen:print(100, 180, mystical_elf[3],green)
screen:print(100, 220, mystical_elf[4],green)

Gizmo356
August 30th, 2006, 16:55
No It Cant Play Mp3 But Why Would U Convert Them To .it It Could Change A 3meg Song To 300kb And Ill Help U When I Get Home

lmtlmt
August 31st, 2006, 07:00
ok ps

i have edited my script and thought it would work but it still doesnt, and i have no ideah why. here it is, i was just trying to load the background.


--IMAGES
background = Image.load("YUGI BACKGROUND.png")
title = Image.load("title.png")
card1 = Image.load("SDY-001.jpeg")
card2 = Image.load("SDY-002.jpeg")
card3 = Image.load("SDY-003.jpeg")
card4 = Image.load("SDY-004.jpeg")
card5 = Image.load("SDY-005.jpeg")
card6 = Image.load("SDY-006.jpeg")
card7 = Image.load("SDY-007.jpeg")
card8 = Image.load("SDY-008.jpeg")
card9 = Image.load("SDY-009.jpeg")
card10 = Image.load("SDY-010.jpeg")
card11 = Image.load("SDY-011.jpeg")
card12 = Image.load("SDY-012.jpeg")
card13 = Image.load("SDY-013.jpeg")
card14 = Image.load("SDY-014.jpeg")
card15 = Image.load("SDY-015.jpeg")
card16 = Image.load("SDY-016.jpeg")
card17 = Image.load("SDY-017.jpeg")
card18 = Image.load("SDY-018.jpeg")
card19 = Image.load("SDY-019.jpeg")
card20 = Image.load("SDY-020.jpeg")
card21 = Image.load("SDY-021.jpeg")
card22 = Image.load("SDY-022.jpeg")
card23 = Image.load("SDY-023.jpeg")
card24 = Image.load("SDY-024.jpeg")
card25 = Image.load("SDY-025.jpeg")
card26 = Image.load("SDY-026.jpeg")
card27 = Image.load("SDY-027.jpeg")
card28 = Image.load("SDY-028.jpeg")
card29 = Image.load("SDY-029.jpeg")
card30 = Image.load("SDY-030.jpeg")
card31 = Image.load("SDY-031.jpeg")
card32 = Image.load("SDY-032.jpeg")
card33 = Image.load("SDY-033.jpeg")
card34 = Image.load("SDY-034.jpeg")
card35 = Image.load("SDY-035.jpeg")
card36 = Image.load("SDY-036.jpeg")
card37 = Image.load("SDY-037.jpeg")
card38 = Image.load("SDY-038.jpeg")
card39 = Image.load("SDY-039.jpeg")
card40 = Image.load("SDY-040.jpeg")
card41 = Image.load("SDY-041.jpeg")
card42 = Image.load("SDY-042.jpeg")
card43 = Image.load("SDY-043.jpeg")
card44 = Image.load("SDY-044.jpeg")
card45 = Image.load("SDY-045.jpeg")
card46 = Image.load("SDY-046.jpeg")
card47 = Image.load("SDY-047.jpeg")
card48 = Image.load("SDY-048.jpeg")
card49 = Image.load("SDY-049.jpeg")
card50 = Image.load("SDY-050.jpeg")
cardback = Image.load("about_fraud_back_auth.jpeg")

-- COLOURS
black = Color.new(0, 0, 0)
white = Color.new(255, 255, 255)
blue = Color.new(0, 128, 255)
red = Color.new(255, 0, 0)
green = Color.new(0, 255, 0)

screen:blit(0,0,background,false)


screen.flip()
screen.waitVblankStart()

end

ACID
August 31st, 2006, 09:47
I wish i was at home to help. Hope fully the good gizmo can help sooner then i can. All i can say is everithing he said is correct.

ACID
August 31st, 2006, 09:56
lmtlmt you can see he is not onlyne right now by the red button on under his avatar. So try not to keep on double posting for no reason. Now go under member list and hunt down a lua coder and send them a Pm if they can help they will trust me.

ACID
August 31st, 2006, 10:24
If you say so but its still triple posting not apreciated.

jason215
August 31st, 2006, 14:22
what error did u get

Gizmo356
August 31st, 2006, 16:48
Y Do U Keep Presureing Me I Told U I Wasnt Home Stop Calling Me Out Like I Have To Help Because I Dont But I Will Help Trust Me And Y Do U Make Me Look Like A Bad Person On Every Page Gizmo U Said U Said U Would Help But Ur No Were To Be Found Gizmo Uve Been On For An Hour And A Half But U Havent Replyed Yet Leave Me Alone Ill Help When I Can. And If I Sound Like An Ass Sorry Its Just Im Very Busy And Cant Help With Every Little Problem U Have Rite Now

lmtlmt
September 1st, 2006, 06:40
what error did u get

i got the no script file found, but i scrapped that script and started again with this , and it works.

the menu


-- EVILMANA.COM PSP LUA CODEBASE
-- www.evilmana.com/tutorials/codebase
-- Menu
-- SUBMITTED BY: KIWI
red = Color.new(255, 0, 0)
white = Color.new(255, 255, 255)

--Variables
Select = 1
maxSelect = 2
oldpad = Controls.read()
--loop
while true do
pad = Controls.read()
screen:clear()
--checar decicion
if pad:up() and oldpad:up() ~= pad:up() then
Select = Select - 1
end
if pad:down() and oldpad:down() ~= pad:down() then
Select = Select + 1
end
if Select > maxSelect then
Select = 1
elseif Select <= 0 then
Select = maxSelect
end
if Select == 1 then
screen:print(334,202,"2 PLAYER", red)
screen:print(334,220,"EXIT",white)
end
if Select == 2 then
screen:print(334,202,"2 PLAYER", white)
screen:print(334,220,"EXIT",red)
end
if pad:cross() and Select == 1 then
dofile("script.lua")
end
if pad:cross() and Select == 2 then
break
end
screen.waitVblankStart()
screen.flip()
oldpad = pad
end
which i didnt make and the script which i did


-- COLOURS
black = Color.new(0, 0, 0)
white = Color.new(255, 255, 255)
blue = Color.new(0, 128, 255)
red = Color.new(255, 0, 0)
green = Color.new(0, 255, 0)

--Table
mystical_elf = { 800, 2000, 4, "[spellcaster]" }
mystical_elf[1] = "attack="
mystical_elf[2] = "defence="
mystical_elf[3] = "level="
mystical_elf[4] = "type="
--Images
title = Image.load("YUGI BACKGROUND.png")

screen:blit(0, 0, title)
screen:print(0, 0, "player 1 its your turn", green)

screen.flip()

while true do
screen.waitVblankStart(240)

end

all it does is load the background and say player1 its your turn, but its a start.

Gizmo356
September 1st, 2006, 06:42
use luaplayer windows so u can debug easyer

lmtlmt
September 1st, 2006, 06:53
i try to but it (the batch file) wont work

Gizmo356
September 1st, 2006, 06:56
it works for me is the extention.cmd

lmtlmt
September 1st, 2006, 06:58
yep

Gizmo356
September 1st, 2006, 07:03
did u type

luaplaye scriptname.lua
pause

lmtlmt
September 1st, 2006, 07:06
yep

Gizmo356
September 1st, 2006, 07:07
ok

lmtlmt
September 1st, 2006, 07:14
i edited my menu so it would have a background instead of a blank screen but it stopped working after that can you see why


-- EVILMANA.COM PSP LUA CODEBASE
-- www.evilmana.com/tutorials/codebase
-- Menu
-- SUBMITTED BY: KIWI
red = Color.new(255, 0, 0)
white = Color.new(255, 255, 255)
backgroung = Image.load("menu.png")

--Variables
Select = 1
maxSelect = 2
oldpad = Controls.read()
--loop
while true do
pad = Controls.read()
screen:clear()
--checar decicion
if pad:up() and oldpad:up() ~= pad:up() then
Select = Select - 1
end
if pad:down() and oldpad:down() ~= pad:down() then
Select = Select + 1
end
if Select > maxSelect then
Select = 1
elseif Select <= 0 then
Select = maxSelect
end
if Select == 1 then
screen:print(59,56,"2 PLAYER", red)
screen:print(59,69,"EXIT",white)
screen:blit(0, 0, menu)
end
if Select == 2 then
screen:print(59,56,"2 PLAYER", white)
screen:print(59,69,"EXIT",red)
screen:blit(0, 0, menu)
end
if pad:cross() and Select == 1 then
dofile("script.lua")
end
if pad:cross() and Select == 2 then
break
end
screen.waitVblankStart()
screen.flip()
oldpad = pad
end

Gizmo356
September 1st, 2006, 07:21
try switching the extention to jpg jpeg or png

lmtlmt
September 1st, 2006, 07:23
it is a png.

ps you should get an msn account

Gizmo356
September 1st, 2006, 07:29
change screen:blit(0,0,menu) to

screen:blit(0,0,backgroung,false)

lmtlmt
September 1st, 2006, 07:37
well the picture comes up but the words go away

Gizmo356
September 1st, 2006, 07:39
put the background code before the text code.

lmtlmt
September 1st, 2006, 07:39
yay it works! thamx gizmo, but do u know how to make the text bigger

Gizmo356
September 1st, 2006, 07:40
srry i dont know how

lmtlmt
September 1st, 2006, 07:45
thats ok I'll find out somehow

lmtlmt
September 1st, 2006, 10:50
could somebody post i list of all the lua symbols you know

==
=~

and all thier meanings?

M!ckeY
September 1st, 2006, 11:10
you should try asking in the development area, you might get faster results there :)

lmtlmt
September 1st, 2006, 11:55
ok

benh
September 1st, 2006, 11:57
you may have a memory leak loading all those images

lmtlmt
September 1st, 2006, 11:59
what does that mean

lmtlmt
September 1st, 2006, 14:29
in the game it now loads the background the deck and sets the life points to 4000!.

ths is the script


green = Color.new(0, 255, 0)
blue = Color.new(0, 128, 255)
luaLogo = Image.load("deck.jpg")
background = Image.load("YUGI BACKGROUND2.png")
lifepoints = (4000)

function scaleImage(newX, newY, theImage)

resizedImage = Image.createEmpty(newX, newY)
for x = 1, newX do
for y = 1, newY do
resizedImage:blit(x,y , theImage,
math.floor(x*(theImage:width()/newX)),math.floor(y*(theImage:height()/newY)), 1,
1)
end
end
return resizedImage

end

scaleImage(53,70, luaLogo) -- Resize image.

while true do
screen:blit(0, 0, background, false)
screen:blit(2,173, resizedImage) -- Show the resized image
screen:print(10, 11, "player 1 its your turn", green)
screen:print(410, 14, lifepoints, blue)

screen.flip()
screen.waitVblankStart()

end


i am still trying to fugure out how to load all the images, some people have told me a few ways, but i still dont know which one to go for, i have had i lot of help from benj, so thnx for that

pspsk8r
September 1st, 2006, 15:56
whats a lua script?

lmtlmt
September 1st, 2006, 23:17
whats a lua script?

it is a script for a game that you can play on your psp using lua player.

lmtlmt
September 2nd, 2006, 01:28
i was trying to make the selecter move from one space to another by pressing left.
it doesnt work. here is the script


green = Color.new(0, 255, 0)
blue = Color.new(0, 128, 255)
luaLogo = Image.load("deck.jpg")
background = Image.load("YUGI BACKGROUND2.png")
lifepoints = (4000)
selecter = Image.load("selecter.png")

function scaleImage(newX, newY, theImage)

resizedImage = Image.createEmpty(newX, newY)
for x = 1, newX do
for y = 1, newY do
resizedImage:blit(x,y , theImage,
math.floor(x*(theImage:width()/newX)),math.floor(y*(theImage:height()/newY)), 1,
1)
end
end
return resizedImage

end

scaleImage(53,70, luaLogo) -- Resize image.

while true do
pad = controls.read()
screen:blit(0, 0, background, false)
screen:blit(2,173, resizedImage) -- Show the resized image
screen:print(10, 11, "player 1 its your turn", green)
screen:print(410, 14, lifepoints, blue)
screen:blit(384, 172, selecter)
if pad:left() then
selecter.x = selecter.x - 78

screen.flip()
screen.waitVblankStart()

end


any ideas on how to make it work

lmtlmt
September 2nd, 2006, 02:06
can you assign images to tables? just wondering

Shadowblind
September 2nd, 2006, 02:54
Here, uase tables:

card_1 = {
Image.load("card1.png"),
Image.load("card2.png"),
Image.load("card3.png"),
Image.load("card4.png"),
Image.load("card5.png"),
Image.load("card6.png"),
Image.load("card7.png"),
Image.load("card8.png"),
}

This is a more suitable way to upload images. Less memory leaks:D

lmtlmt
September 2nd, 2006, 02:58
oh sorry it didnt work because i didnt change it from

card.png to SDY-001.jpg

I'll try it again

Shadowblind
September 2nd, 2006, 03:05
Thats for loading the into animation i beleive...

This would be for images I think

Cards = { }
card[1] =Image.load("card.png")
card[2] = Image.load("card3.png")
card[3] = Image.load("card4.png")
card[4] = Image.load("card5.png")
card[5] = Image.load("card6.png")


Im not what you'd call experiance, so maybe check with zion or yaustar first.

lmtlmt
September 2nd, 2006, 03:19
nope stilll didnt work
thanx for trying

Shadowblind
September 2nd, 2006, 03:21
I'll figure out somethin. In the meantime, why not join the evilmana forums for advice.

lmtlmt
September 2nd, 2006, 03:25
i tried to register but it kept saying
text written is not the same as shown

in the part how you have to write what it says RU5SD, that thing

Shadowblind
September 2nd, 2006, 03:42
The first suggestion shoulda worked...

yaustar
September 2nd, 2006, 03:47
i was trying to make the selecter move from one space to another by pressing left.
it doesnt work. here is the script



any ideas on how to make it work

Here is your mistake:

screen:blit(384, 172, selecter)
if pad:left() then
selecter.x = selecter.x - 78
Here you attempt to create an entry in a table on a variable that is not a table. Also there is no end for your if statement.

Try this:


green = Color.new(0, 255, 0)
blue = Color.new(0, 128, 255)
luaLogo = Image.load("deck.jpg")
background = Image.load("YUGI BACKGROUND2.png")
lifepoints = (4000)
selecter = Image.load("selecter.png")

function scaleImage(newX, newY, theImage)

resizedImage = Image.createEmpty(newX, newY)
for x = 1, newX do
for y = 1, newY do
resizedImage:blit(x,y , theImage,
math.floor(x*(theImage:width()/newX)),math.floor(y*(theImage:height()/newY)), 1,
1)
end
end
return resizedImage

end

scaleImage(53,70, luaLogo) -- Resize image.

selectorX = 384

while true do
pad = controls.read()
screen:blit(0, 0, background, false)
screen:blit(2,173, resizedImage) -- Show the resized image
screen:print(10, 11, "player 1 its your turn", green)
screen:print(410, 14, lifepoints, blue)
screen:blit(selectorX, 172, selecter)
if pad:left() then
selectorX = selectorX - 78
end

screen.flip()
screen.waitVblankStart()

end



could somebody post i list of all the lua symbols you know

==
=~

and all thier meanings?

http://lua-users.org/wiki/ExpressionsTutorial

lmtlmt
September 2nd, 2006, 09:33
thanx yaustar, but it doesnt work

yaustar
September 2nd, 2006, 11:23
thanx yaustar, but it doesnt work
That doesn't tell me much. WHAT doesn't work.

lmtlmt
September 2nd, 2006, 11:28
the script, it just exits

yaustar
September 2nd, 2006, 11:32
Do you get a syntax error? If so, what is it?

Edit: Nevermind, "controls.read()" is meant to be "Controls.read()". Case sensitivity.

lmtlmt
September 2nd, 2006, 11:35
nope, no syntax error, it just exits

yaustar
September 2nd, 2006, 11:35
See the previous post for the syntax error.

lmtlmt
September 2nd, 2006, 11:38
it works, how do i make it so it just goes to each section of this picture, as if it was a menu, and not too fast?

yaustar
September 2nd, 2006, 12:08
Learn about if statements.

lmtlmt
September 2nd, 2006, 12:36
where would i be able to learn about if statements?

yaustar
September 2nd, 2006, 12:42
http://lua-users.org/wiki/ExpressionsTutorial Scroll to the bottom

lmtlmt
September 2nd, 2006, 13:20
do you know any that are easier to understand?

yaustar
September 2nd, 2006, 13:23
http://lua-users.org/wiki/ControlStructureTutorial

lmtlmt
September 2nd, 2006, 13:32
yes that one is much easier, thank u for all your help

lmtlmt
September 3rd, 2006, 10:17
so using if statements, could i say, when an image is in a certain place i could screen print or screen blit something, and when it moves from that spot it will go away, is that right?

while trying to to that it doesnt work, i used this code

if selectorX = 375 then
screen:print(407, 208, "select", green)

do you know how to make it work?

lmtlmt
September 5th, 2006, 07:24
c'mon anybody know?