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; Just throwing it out there, if you are using an old version of luaplayer (&lt;0.20), the &quot;%&quot; operator is not ...

 Tweet
1. Just throwing it out there, if you are using an old version of luaplayer (<0.20), the "%" operator is not available (they are based on older versions of lua). Use math.mod instead.
e.g. math.mod(step + 1,6)

2. I have two questions :
1) if i want an enemy to change direction when it reaches an certain space would i do this;
Code:
```if Enemy[1].x > 200 then
Enemy[1].x = Enemy[1].x + 2
end
elseif Enemy[1].x < 100 then
Enemy[1].x = Enemy[1].x - 2
end```
Would something like that work?

2) This is general but concerns lua.
How do you become an better Lua programmer? What books, online tuts to read to become better?

3. Originally Posted by dan369
I have two questions :
1) if i want an enemy to change direction when it reaches an certain space would i do this;
Code:
```if Enemy[1].x > 200 then
Enemy[1].x = Enemy[1].x + 2
end
elseif Enemy[1].x < 100 then
Enemy[1].x = Enemy[1].x - 2
end```
Would something like that work?

2) This is general but concerns lua.
How do you become an better Lua programmer? What books, online tuts to read to become better?
1) yes that would work

2) you dont become a better lua programmer by reading books or online tutorials, the books and online tutorials just teach you the knowledge, you yoursef have to apply that knowledge to become better

over time with your programming you will look at sections of your code and think im sure that can be made smaller, so you make a backup copy and test different methods out, if you dont mange to do it in one day then dont just replace it with the old code, leave it but either work on it again a short time later or come back to it after a while, by which stage you will have probably solved the problem for a different project or peice of code, meaning that you should be able to fix it.

all in all becomming a better programmer is all about coding and trying new things out, when you try new things out you will understand more full where and where not to use certain peices of code, and the method that they are coded in

basically dan practice makes perfect, keep at it and you will get better.

i didnt become as skilled as i am now in a month or two.

4. Ok, then Thanks Fat :)

5. @dan

@Fatboy
Stop being so conceited, you have a long way to go before you are regarded as "skilled". I've seen you act in such a way a number of times recently, and it really make you come across as immature.

6. My bad the computer froze for a bit so i kept clicking post quick reply sorry

7. Originally Posted by Nielkie
@Fatboy
Stop being so conceited, you have a long way to go before you are regarded as "skilled". I've seen you act in such a way a number of times recently, and it really make you come across as immature.
and that affects my programming skills how ?

i may be imature at times but what the hey thats just the way i am people need to learn to deal with it or shut up, the people who do deal with it find that i am quite a nice person, the people who dont have outstanding grudges against me which to be honest im not that bothered about.

8. Fat IS an skilled programmer, just look at this thread Or the Lua examples/snippets Thread. That one might as well be his lol
He's helped me and most people in the forum
-= Double Post =-
Ok, I'm trying to do 3 selectable difficulties But am having trouble I got 3 drifferent .cfg files with the info but don't know how to do it?

I was thinking about having it after you press X on start in the menu then having it print: Easy, Medium, Hard changing colour on each one. Then you press X on anyone of them But i don't really want 3 drifferent files holding the difficultly So could someone maybe tell me how to do it?

9. Originally Posted by dan369
2) This is general but concerns lua.
How do you become an better Lua programmer? What books, online tuts to read to become better?
You become a better Lua programmer by becoming a better programmer. You don't become better overnight, it takes constant learning and practise to accumulate experience over a period of time.

A good book to read would be Code Complete 2nd Edition.
http://cc2e.com/

10. Ok, thanks I'm also reading an book about lua itself, then after understanding lua really well i'll try C/C++

11. Originally Posted by dan369
Ok, I'm trying to do 3 selectable difficulties But am having trouble I got 3 drifferent .cfg files with the info but don't know how to do it?

I was thinking about having it after you press X on start in the menu then having it print: Easy, Medium, Hard changing colour on each one. Then you press X on anyone of them But i don't really want 3 drifferent files holding the difficultly So could someone maybe tell me how to do it?
as i said you need the functions that i have made for the saving and loading of a config file, when i have made it a proper function and made it as small as it can be ill post it on my site and tell you so you can take a look

12. I got the Menu part Set up moving left and right Simply But the loading is quiet hard because i'm not strong with reading/writing to files i know the basics but not advanced stuff

13. hey dan those examples are up on my site, you know which ones to click on

14. Wow that was quick Thanks Fat will help me and loads off people
Off topic: Fat is it possible for your site to have an mini-forum? that would be cool i'd register :)

15. Originally Posted by dan369
Wow that was quick Thanks Fat will help me and loads off people
yeah i know how to do it i just couldnt be bothered to code it earlier when i mentioned it

Originally Posted by dan369
Off topic: Fat is it possible for your site to have an mini-forum? that would be cool i'd register :)
probably but im not quite sure that i need one, if you make a petition and get 50 + people to sign it that will use the forums if i put some up then ill make some

16. How do you make an petition? Does my name count?

17. Originally Posted by dan369
How do you make an petition? Does my name count?
We don't allow petitions on this forum, so it would have to be private.

18. Hey, how would I code bliting only a section of a sprite sheet so I don't have to make 54 seperate images?? thanx

19. Originally Posted by PSProgramer
Hey, how would I code bliting only a section of a sprite sheet so I don't have to make 54 seperate images?? thanx
here i dont know if these are any good but i just found them in one of my folders entitled "sprite crap"

Code:
```white = Color.new(255, 255, 255)

number = 0
tile_width = 32
tile_height = 32
tiles = { }

while true do

screen:clear()

-- insert your main code here

number = number + 1
end

if number >= 9 then
number = 0
end

screen:blit(10, 10, tile_image, 32 * number, 0, 32, 32)

-- insert your main code here

break
end

screen.flip()
screen.waitVblankStart()

end```
Code:
```white = Color.new(255, 255, 255)

number = 0
tile_width = 32
tile_height = 32
tiles = { }

while true do

screen:clear()

-- insert your main code here

number = number + 1

if number >= 9 then
number = 0
end

screen:blit(10, 10, tile_image, 32 * number, 0, 32, 32)
screen.waitVblankStart(60)

-- insert your main code here

break
end

screen.flip()
screen.waitVblankStart()

end```
Code:
```white = Color.new(255, 255, 255)

collumn = 0
row = 0
tile_width = 32
tile_height = 32
tiles = { }

while true do

screen:clear()

-- insert your main code here

collumn = collumn + 1
end

if collumn >= 3 then
collumn = 0
row = row + 1
end

if row >= 3 then
row = 0
end

screen:blit(10, 10, tile_image, 32 * collumn, 32 * row, 32, 32)

-- insert your main code here

break
end

screen.flip()
screen.waitVblankStart()

end```

20. thanx, glad to put use to your "sprite crap" by the way did you get my P.M.??

21. screen:blit(x,y,spriteshe etimage,topleftcornerofse ctionofspritesheetyouwant toblitx, topleftcornerofsectionofs pritesheetyouwanttoblity, bottomrightcornerofsectio nofspritesheetyouwanttobl itx, bottomrightcornerofsectio nofspritesheetyouwanttobl ity)

22. Originally Posted by PSProgramer
thanx, glad to put use to your "sprite crap" by the way did you get my P.M.??
yeah ill take a look when i get time im busy doing a few things this week

and put simply

Code:
`screen:blit(xpos to blit, ypos to blit, full image to use, x start position for tile, y start position for tile, width of tile, height of tile)`
tile is another word for sprite

23. thank you very much, that helps alot. Makes it way easier, and way more efficient!!! thank you!!

24. I want to do some type of online highscore system, But don't have a clue how to do this? would i have do make an webpage or sumthing?
My Plan: Have an system that loads your score using "r" (reading&writing functions) Then connecting to somewhere then you enter an name and it Places you in the right place? Is that possible????

25. Originally Posted by dan369
I want to do some type of online highscore system, But don't have a clue how to do this? would i have do make an webpage or sumthing?
My Plan: Have an system that loads your score using "r" (reading&writing functions) Then connecting to somewhere then you enter an name and it Places you in the right place? Is that possible????
with your own server and sql databse to manage it yes

26. You don't need an SQL DB for a list of scores, but yes, you need some server side scripting and a webserver as well as some good lua online backend stuff.

27. ## a little help from my friends

Hi everyone!
this is my first post here at qj and i wondered if someone can help me im having some trouble making my game which is tile based, so far i have been using this code as a base for mine i got it from http://wiki.ps2dev.org/psp:lua_player:tutorial

-- the map
mapSource = {
"mmmmmmmmmmmmmmmmmmmmmmmm mmmmmm",
"mmmmmmmmmmmmmmmmmmmmmmmm mmmmmm",
"mmeaaaaaaaaaaaaaaaaaaaaa aaafmm",
"mmdpnnnnnnnnnnnnnnnnnnnn nnpbmm",
"mmdokcccccclnkcccccccccc clnbmm",
"mmdojaaaaafdnbmmmmmmmmmm mdnbmm",
"mmdooooooobdnbmmmmmmmmmm mdnbmm",
"mmdokccclobdnbmmmmmmmmmm mdnbmm",
"mmdobmmmdobdnbmmmmmmmmmm mdnbmm",
"mmdobmmmdobdnjaaaaaaaaaa fdnbmm",
"mmdobmmmdpbdnnnnnnnnnnnn bdnbmm",
"mmdobmmmhcghccccccccccln bdnbmm",
"mmdojaaaaaaaaaaaaaaaaain jinbmm",
"mmdpnnnnnnnnnnnnnnnnnnnn nnpbmm",
"mmhccccccccccccccccccccc cccgmm",
"mmmmmmmmmmmmmmmmmmmmmmmm mmmmmm",
"mmmmmmmmmmmmmmmmmmmmmmmm mmmmmm"
}

-- 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

Now i want to use a tileset that it has a total of 64 tiles each tile of 16px by 16px in 8 colums and 8 rows now i cant figure how to number the tiles i have been planning using "aa ab ac ad af" ("aa" beign one tile) etc but i cant figure how to make this code

tile = string.sub(line, x, x)

so it can read the first two characters and then the next two and so on and so forth of each row and then adjust this so it works with the one above

tile = string.byte(tile, 1) - string.byte("a")

well in general how to change the code so it work with the tileset i would like to use
Or if you have a better sugestion on how to do this please i would really appreciate your help

28. Originally Posted by TurtlesPwn
You don't need an SQL DB for a list of scores, but yes, you need some server side scripting and a webserver as well as some good lua online backend stuff.
So how do i start to do this?

29. Originally Posted by dan369
So how do i start to do this?

30. Originally Posted by FaT3oYCG
Any suggestions? Though will it be free? If so any good free website places? Then i get the website What do you do after that?

#### 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 12:44 PM.

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