The above video goes away if you are a member and logged in, so log in now!

 Would you like to get all the newest Gaming News fromQJ.NET in your email each day? Want to learn more about the team who brings you the QJ news?

This is a discussion on Lua Programming Help Thread within the PSP Development Forum forums, part of the PSP Development, Hacks, and Homebrew category; Originally Posted by GuitarGod1134 Is there a special way to make a variable a negative number or do I just ...

 Tweet
1. Originally Posted by GuitarGod1134
Is there a special way to make a variable a negative number or do I just do

variable = -90

?
-= Double Post =-
Spoiler for Snow Simultor:
Code:
```-- Snow Simulator By GuitarGod1134
-- just simulates a snow weather condition
--color
white = Color.new(255,255,255)
--pics
snow = Image.create(10,10)
snow:clear(white)
--x = width y = hieght
snowxy = {}
snowxy[1] = { x = 30, y = -300}
snowxy[2] = { x = 200, y = -300}
snowxy[3] = { x = 110, y = -300}
snowxy[4] = { x = 97, y = -300}
snowxy[5] = { x = 400, y = -300}
snowxy[6] = { x = 300, y = -390}
snowxy[7] = { x = 250, y = -300}
--is the snow falling
falling = true
--main loop
while true do
screen:clear()
--blit the background
screen:blit(0,0,background)
--blit the snow
snowy = true
if snowy == true then
screen:blit(snowxy[1].x, snowxy[1].y, snow)
end
if snowy == true then
screen:blit(snowxy[2].x, snowxy[2].y, snow)
end
if snowy == true then
screen:blit(snowxy[3].x, snowxy[3].y, snow)
end
if snowy == true then
screen:blit(snowxy[4].x, snowxy[4].y, snow)
end
if snowy == true then
screen:blit(snowxy[5].x, snowxy[5].y, snow)
end
if snowy == true then
screen:blit(snowxy[6].x, snowxy[6].y, snow)
end
if snowy == true then
screen:blit(snowxy[7].x, snowxy[7].y, snow)
end
--make the snow fall
if falling == true then
snowxy[1].y = snowxy[1].y + 2
end
if falling == true then
snowxy[2].y = snowxy[2].y + 2
end
if falling == true then
snowxy[3].y = snowxy[3].y + 2
end
if falling == true then
snowxy[4].y = snowxy[4].y + 2
end
if falling == true then
snowxy[5].y = snowxy[5].y + 2
end
if falling == true then
snowxy[6].y = snowxy[6].y + 2
end
if falling == true then
snowxy[7].y = snowxy[7].y + 2
end
--now we reset them back to true so they can
--fall down again
if snowxy[6].y == 272 then
falling = false
end
--all the snow flakes
--are reset back
--to thier original
--y coordinates
if falling == false then
backup = true
snowxy[1].y = -300
snowxy[2].y = -300
snowxy[3].y = -300
snowxy[4].y = -300
snowxy[5].y = -300
snowxy[6].y = -390
snowxy[7].y = -300
end
--once they reach the bottom
--falling is declared true again
--so that it makes the affect
--that the snow is always falling
if backup == true then
falling = true
end
screen.waitVblankStart()
screen.flip
end```

Ok when I try to run this I get this really annoying error that for some reason is common in a lot of games I try to make. The error is

error:script.lua:98: '=' expected near 'end'

and Im using windows lua player to test my games if that makes a difference.

And I know there might be some sloppy code in there or something I wrote it in 10 minutes with breakfast in my mind.
Can someone help this guy

2. I have this code=
Im trying to make it when you have A has name then hit L it will print the word
but when i try it i get
:144: bad argument #2 to 'find' <string expected, got no value>

here is my code
Spoiler for Code:
Code:
```white = Color.new(255,255,255)
red = Color.new(255,0,0)
blue = Color.new(0,255,0)
green = Color.new(0,0,255)

--words

--A
A = "A: The first letter of the english alphabet"

characters = { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", " " }

selector = Image.createEmpty(10,10)
selector:clear(red)

charX = 4
charY= 50

currentLetter = 1

currentX = 12
currentY = 48

uppercase = true

name = ""

-- FUNCTION TO DRAW LETTERS
function drawLetters()
for a = 1, 3 do
for b = 1, 9 do
if uppercase == false then
else
end
end
end
end
-- END FUNCTION

-- LOOP
while true do

screen:clear()
if tostring(pad) == "Controls (0)" then
else
screen:print(10,30,"Press X",white)
end

screen:print(10,10,"Search: "..name,white)
screen:blit(currentX,currentY, selector)

drawLetters()

-- TYPE LETTERS
if uppercase == false then
name = name .. characters[currentLetter]
else
name = name .. string.upper(characters[currentLetter])
end
end

-- DELETE LETTER
name = string.sub(name, 1, string.len(name) - 1)
end

-- UPPER OR LOWER
if uppercase == false then
uppercase = true
else
uppercase = false
end
end

-- MOVE SELECTOR RIGHT
if pad:right() and currentLetter ~= 9 and currentLetter ~= 18 and currentLetter ~= 27 and oldpad:right() ~= pad:right() then
currentLetter = currentLetter + 1
currentX = currentX + 10
if currentLetter == 9 or currentLetter == 18 or currentLetter == 27 then
currentLetter = currentLetter - 8
currentX = 12
end
end
-- MOVE SELECTOR LEFT
if pad:left() and currentLetter ~= 1 and currentLetter ~= 10 and currentLetter ~= 19 and oldpad:left() ~= pad:left() then
currentLetter = currentLetter - 1
currentX = currentX - 10
if currentLetter == 1 or currentLetter == 10 or currentLetter == 19 then
currentX = 107 + 80 - 95
currentLetter = currentLetter + 8
end
end

-- MOVE SELECTOR DOWN
currentLetter = currentLetter + 9
currentY = currentY + 10
currentY = 48
currentLetter = currentLetter - 18
end

-- MOVE SELECTOR UP
currentLetter = currentLetter - 9
currentY = currentY - 10
currentY = 68
currentLetter = currentLetter + 18
end
find1 = string.find (name)
screen:print(0,200,find1,blue)
end

screen.flip()
screen.waitVblankStart()
end```

3. how do u do multi-line comments in lua?

4. Originally Posted by Alex G
how do u do multi-line comments in lua?
like this
Code:
```--BLAH BLAH
--BLAH BLAH```
thats the only way i think

5. argh, that buggers up some of my app

6. Originally Posted by the undead
like this
Code:
```--BLAH BLAH
--BLAH BLAH```
thats the only way i think
Now im pretty sure he means
like in C++
/* BLA BLA
BLA
BLA BLA
*/
In lua Im pretty sure thats like
--[ or something I know its used in Snake Lua for the psp by shine just check in that shine puts it in all his luaplayer releases.
-= Double Post =-
--[[
Snake, Copyright (c) 2005 Frank Buss <fb@frank-buss.de> (aka Shine)

artworks by Gundrosen
coding by Shine
background music: "Stranglehold", composed by Jeroen Tel, (C) 1995 Maniacs of Noise
]]

Thats how you do it taken from Snake PSP lua.

7. Originally Posted by GuitarGod1134
Now im pretty sure he means
like in C++
/* BLA BLA
BLA
BLA BLA
*/
In lua Im pretty sure thats like
--[ or something I know its used in Snake Lua for the psp by shine just check in that shine puts it in all his luaplayer releases.
-= Double Post =-
--[[
Snake, Copyright (c) 2005 Frank Buss <fb@frank-buss.de> (aka Shine)

artworks by Gundrosen
coding by Shine
background music: "Stranglehold", composed by Jeroen Tel, (C) 1995 Maniacs of Noise
]]

Thats how you do it taken from Snake PSP lua.
hmm, i never knew that.....now i know

8. cheers, i though it was --[

9. Originally Posted by the undead
I have this code=
Im trying to make it when you have A has name then hit L it will print the word
but when i try it i get
:144: bad argument #2 to 'find' <string expected, got no value>

here is my code
Spoiler for Code:
Code:
```white = Color.new(255,255,255)
red = Color.new(255,0,0)
blue = Color.new(0,255,0)
green = Color.new(0,0,255)

--words

--A
A = "A: The first letter of the english alphabet"

characters = { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", " " }

selector = Image.createEmpty(10,10)
selector:clear(red)

charX = 4
charY= 50

currentLetter = 1

currentX = 12
currentY = 48

uppercase = true

name = ""

-- FUNCTION TO DRAW LETTERS
function drawLetters()
for a = 1, 3 do
for b = 1, 9 do
if uppercase == false then
else
end
end
end
end
-- END FUNCTION

-- LOOP
while true do

screen:clear()
if tostring(pad) == "Controls (0)" then
else
screen:print(10,30,"Press X",white)
end

screen:print(10,10,"Search: "..name,white)
screen:blit(currentX,currentY, selector)

drawLetters()

-- TYPE LETTERS
if uppercase == false then
name = name .. characters[currentLetter]
else
name = name .. string.upper(characters[currentLetter])
end
end

-- DELETE LETTER
name = string.sub(name, 1, string.len(name) - 1)
end

-- UPPER OR LOWER
if uppercase == false then
uppercase = true
else
uppercase = false
end
end

-- MOVE SELECTOR RIGHT
if pad:right() and currentLetter ~= 9 and currentLetter ~= 18 and currentLetter ~= 27 and oldpad:right() ~= pad:right() then
currentLetter = currentLetter + 1
currentX = currentX + 10
if currentLetter == 9 or currentLetter == 18 or currentLetter == 27 then
currentLetter = currentLetter - 8
currentX = 12
end
end
-- MOVE SELECTOR LEFT
if pad:left() and currentLetter ~= 1 and currentLetter ~= 10 and currentLetter ~= 19 and oldpad:left() ~= pad:left() then
currentLetter = currentLetter - 1
currentX = currentX - 10
if currentLetter == 1 or currentLetter == 10 or currentLetter == 19 then
currentX = 107 + 80 - 95
currentLetter = currentLetter + 8
end
end

-- MOVE SELECTOR DOWN
currentLetter = currentLetter + 9
currentY = currentY + 10
currentY = 48
currentLetter = currentLetter - 18
end

-- MOVE SELECTOR UP
currentLetter = currentLetter - 9
currentY = currentY - 10
currentY = 68
currentLetter = currentLetter + 18
end
find1 = string.find (name)
screen:print(0,200,find1,blue)
end

screen.flip()
screen.waitVblankStart()
end```
hey, any one?

10. Originally Posted by GuitarGod1134
Is there a special way to make a variable a negative number or do I just do

variable = -90

?

Here, I explained what was wrong in this edited peice of code:
Spoiler for Edited Code:
Code:
```-- Snow Simulator By GuitarGod1134
-- just simulates a snow weather condition
--color
white = Color.new(255,255,255)
--pics
snow = Image.create(10,10)
snow:clear(white)
--x = width y = hieght
snowxy = {}
snowxy[1] = { x = 30, y = -300}
snowxy[2] = { x = 200, y = -300}
snowxy[3] = { x = 110, y = -300}
snowxy[4] = { x = 97, y = -300}
snowxy[5] = { x = 400, y = -300}
snowxy[6] = { x = 300, y = -390}
snowxy[7] = { x = 250, y = -300}
--is the snow falling
falling = "true"  -----------------------------------MAKE THIS "true"
--main loop
while true do
screen:clear()
--blit the background
screen:blit(0,0,background)
--blit the snow
snowy = true
-----------------------------------------------here put it all under one 'if'
if snowy == true then
screen:blit(snowxy[1].x, snowxy[1].y, snow)
screen:blit(snowxy[2].x, snowxy[2].y, snow)
screen:blit(snowxy[3].x, snowxy[3].y, snow)
screen:blit(snowxy[4].x, snowxy[4].y, snow)
screen:blit(snowxy[5].x, snowxy[5].y, snow)
screen:blit(snowxy[6].x, snowxy[6].y, snow)
screen:blit(snowxy[7].x, snowxy[7].y, snow)
end
--make the snow fall
---------------------------------------------------same here all under 1
if falling == true then
snowxy[1].y = snowxy[1].y + 2
snowxy[2].y = snowxy[2].y + 2
snowxy[3].y = snowxy[3].y + 2
snowxy[4].y = snowxy[4].y + 2
snowxy[5].y = snowxy[5].y + 2
snowxy[6].y = snowxy[6].y + 2
snowxy[7].y = snowxy[7].y + 2
end
--now we reset them back to true so they can
--fall down again
if snowxy[6].y == 272 then

falling = "false" --[[----------------------------HERE is actually what is wrong. false must be in parenthesis to work. otherwise it thinks falling equals
the value of the variable false, which doesn't exhist. ]]

end
--all the snow flakes
--are reset back
--to thier original
--y coordinates
if falling == "false" then -----------------------------------in "" again
backup = true
snowxy[1].y = -300
snowxy[2].y = -300
snowxy[3].y = -300
snowxy[4].y = -300
snowxy[5].y = -300
snowxy[6].y = -390
snowxy[7].y = -300
end
--once they reach the bottom
--falling is declared true again
--so that it makes the affect
--that the snow is always falling
if backup == true then
falling = "true"-----------------------------------------here too ("")
end
screen.waitVblankStart()
screen.flip
end```

-= Double Post =-
hey, any one?
is string.find(whatever) definataly a function? I don't see how that would display anything.

11. is this an actual function?

Code:
```if currentTime > 100 then
screen:blit(Jewel[1].x,Jewel[1].y,jewel)```
i did that about 5 times in my code and it just comes up with a black screen and then resets. If there is a simpler way than using a timer to blit images a intervals someone tell me

12. Originally Posted by the undead
hey, any one?
ok, i thought of something else you could do... hopefully this is what you were trying to do:

Code:
```--words
word = {}
numberofwords = 1
--A
word[1] = {letter = "A",definition = "A: The first letter of the english alphabet"}

--[[add the above stuff to the beggining, and the bottom in the correct spot

--SEARCH FOR A WORD
for a = 1, numberofwords do
if name == word[a].letter then
wordtodisplay = word[a].definition
break
else
wordtodisplay = "No match found."
end
end
while true do
screen:clear()
screen:print(50, 120, wordtodisplay, blue)
break
end
screen.flip()
screen.waitVblankStart()
end
end```
yep, i tested it and it works!

13. well i was gonna get some hardcore coding done tonight but since i cant fix whats wrong at the moment i guess ill just call it a night

14. Why is this unstickied?

15. me again eith another noob question
in collission i found the function to look like this (variables assigned):
Code:
```function collisionCheck(Jewel)
if (Player.x + playerWidth > Jewel.x) and (Player.x < Jewel.x + Jewel.width) and (Player.y + playerHeight > Jewel.y) and (Player.y < Jewel.y + Jewel.height) then
Player.x = oldx
Player.y = oldy
end
end```
but how do i define playerwidth and playerheight? b ecause when i run my code with this in it it says attempt to perform arithmetic on field "x" (a nil value)
is that because i didnt define player width and playerheight?

16. Originally Posted by %chrono trigger%
me again eith another noob question
in collission i found the function to look like this (variables assigned):
Code:
```function collisionCheck(Jewel)
if (Player.x + playerWidth > Jewel.x) and (Player.x < Jewel.x + Jewel.width) and (Player.y + playerHeight > Jewel.y) and (Player.y < Jewel.y + Jewel.height) then
Player.x = oldx
Player.y = oldy
end
end```
but how do i define playerwidth and playerheight? b ecause when i run my code with this in it it says attempt to perform arithmetic on field "x" (a nil value)
is that because i didnt define player width and playerheight?
to do this, i am assuming that 'player' is an image.
to get the width/height of an image you need to do:
Code:
```thewidth = player:width()
theheight = player:height()```

17. well i found out that defining those variables wasn't the cause of the error. i think its the way im setting up my collision.
so if my image is defined as "jewel", but my table is defined as "Jewel". which do i put into the collision function the actual image name? (it would be c.png) or do i put the table name in it or the "jewel" variable?
lastly since it is in a table would i have to define all the elements like this:
Code:
```function collisionCheck(Jewel[1])
if (Player.x + playerWidth > Jewel[1].x) and (Player.x < Jewel[1].x + Jewel[1].width) and (Player.y + playerHeight > Jewel[1].y) and (Player.y < Jewel[1].y + Jewel[1].height) then```

18. also, did yu define his X and Y numbers? if so ya gotta declere those too

19. yes i defined the x and y values i had my game working fine up until i added collision so i know its not the rest of the code

ok, i thought of something else you could do... hopefully this is what you were trying to do:

Code:
```--words
word = {}
numberofwords = 1
--A
word[1] = {letter = "A",definition = "A: The first letter of the english alphabet"}

--[[add the above stuff to the beggining, and the bottom in the correct spot

--SEARCH FOR A WORD
for a = 1, numberofwords do
if name == word[a].letter then
wordtodisplay = word[a].definition
break
else
wordtodisplay = "No match found."
end
end
while true do
screen:clear()
screen:print(50, 120, wordtodisplay, blue)
break
end
screen.flip()
screen.waitVblankStart()
end
end```
yep, i tested it and it works!
ok thanks....i build up from that
-= Double Post =-
ok, i thought of something else you could do... hopefully this is what you were trying to do:

Code:
```--words
word = {}
numberofwords = 1
--A
word[1] = {letter = "A",definition = "A: The first letter of the english alphabet"}

--[[add the above stuff to the beggining, and the bottom in the correct spot

--SEARCH FOR A WORD
for a = 1, numberofwords do
if name == word[a].letter then
wordtodisplay = word[a].definition
break
else
wordtodisplay = "No match found."
end
end
while true do
screen:clear()
screen:print(50, 120, wordtodisplay, blue)
break
end
screen.flip()
screen.waitVblankStart()
end
end```
yep, i tested it and it works!
wait, that wont work because "a" was their just as a test, im going to have more words.....any way i could do it that way? or does it have to be specific?

21. how do you code a function that tells you the FPS of your game/app? i learned about the timer functions, but i still dont know how to do this.

22. Originally Posted by the undead
ok thanks....i build up from that
-= Double Post =-

wait, that wont work because "a" was their just as a test, im going to have more words.....any way i could do it that way? or does it have to be specific?
Any one?

23. Originally Posted by %chrono trigger%
well i found out that defining those variables wasn't the cause of the error. i think its the way im setting up my collision.
so if my image is defined as "jewel", but my table is defined as "Jewel". which do i put into the collision function the actual image name? (it would be c.png) or do i put the table name in it or the "jewel" variable?
lastly since it is in a table would i have to define all the elements like this:
Code:
```function collisionCheck(Jewel[1])
if (Player.x + playerWidth > Jewel[1].x) and (Player.x < Jewel[1].x + Jewel[1].width) and (Player.y + playerHeight > Jewel[1].y) and (Player.y < Jewel[1].y + Jewel[1].height) then```
anyone got any ideas?

24. Originally Posted by %chrono trigger%
anyone got any ideas?

put the table. also, its a very bad habit to name two things the same thing, even if on is capitalized.

25. still a nil value error hmm ive put the table in 2 different ways and still nothing man im stumped. i dont want to paste the whole code unless someone can help so if you think you can help just reply and ill edit this and add my code
thnx

26. Code:
```function collisionCheck( aJewel )
if (Player.x + playerWidth > aJewel .x) and (Player.x < aJewel .x + aJewel .width) and (Player.y + playerHeight > aJewel .y) and (Player.y < aJewel .y + aJewel.height) then
-- do whatever
end
end

-- in the main loop
for i=1, table.getn(Jewel) do
collisionCheck(Jewel[i])
end```

27. Originally Posted by the undead
Any one?
ok, from what i gave you, if you want to add more words to be able to be searched:
You need to the variable 'numberofwords' in your code to be how many words you have total, so change this number in your code as you add more words.

Then, where I have
Code:
`word[1] = {letter = "A",definition = "A: The first letter of the english alphabet"}`
Code:
`word[2] = {letter = "LUA", definition = "Lua: a script-based programming language for the PSP"}`
so if that helps, it would come out to be:
Spoiler for this:
Code:
```--words
word = {}
numberofwords = 2
--A
word[1] = {letter = "A",definition = "A: The first letter of the english alphabet"}
word[2] = {letter = "LUA", definition = "Lua: a script-based programming language for the PSP"}```

ok, from what i gave you, if you want to add more words to be able to be searched:
You need to the variable 'numberofwords' in your code to be how many words you have total, so change this number in your code as you add more words.

Then, where I have
Code:
`word[1] = {letter = "A",definition = "A: The first letter of the english alphabet"}`
Code:
`word[2] = {letter = "LUA", definition = "Lua: a script-based programming language for the PSP"}`
so if that helps, it would come out to be:
Spoiler for this:
Code:
```--words
word = {}
numberofwords = 2
--A
word[1] = {letter = "A",definition = "A: The first letter of the english alphabet"}
word[2] = {letter = "LUA", definition = "Lua: a script-based programming language for the PSP"}```
ok ill try that...if not i have already started one...but this is much cleaner(mine had a whole bunch of if statements.)

29. hey sorry for being off topic here, but how do you change what it says under your picture when you post? because mine just says novice, and thats gay.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•

All times are GMT -8. The time now is 04:34 PM.

Use of this Web site constitutes acceptance of the TERMS & CONDITIONS and PRIVACY POLICY