[solved] some help with local and images

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
User avatar
hairy puppy
Prole
Posts: 29
Joined: Tue Apr 22, 2014 3:34 pm

[solved] some help with local and images

Post by hairy puppy »

howdy howdy howdy,

well ive been a damn busy bunny lately learning lua/love2d further [even bought the book and made a donation for a shirt], i always learn better when 'just doing shit' with a language. but ive come under a bit of a head scratcher concerning images and local, mixed with other matters. i have done some searching and did get far with what i did find, but now need to ask for some help.

so, what i have started using pretty early is 'local', which makes sense to me since coming from other backgrounds of code, its seems better to me having a 'local' and then call it in something you need rather than it floating around binary space.
so i have them down, some-what, but with images its a different matter.

so i have been going through some online tutorials, which have been great, always better to hear and see someone coding something, but they dont work in 'local', or use it to to any degree. so when working on some sprite movement have ran into an annoyance of using 'local' with images, or at least a series of images using say something like 'player.left[1] = etc...'
instead of using anim8 or something similar, im using separate png sprites and cycling through them, using [1],[2],[3] etc...
but using these in local become troublesome.
also, on seeing the '[]', it reminds me of arrays in c/c++, which im guessing im right that its true for lua/love2d? i still need to do more reading

to explain it further i have provided the 2 ways i have done, one complete, one not so complete. the one that doesnt start is actually the one im trying to do, since it works in 'local', which i prefer using.

i am going to possibly change up and use either AnAL or anim8, but for now fancy learning this method just now, since i know exactly whatimages are loaded, if you get me?
one thing as well, shoudnt AnAL be renamed AAL, or something similar, rather than what instantly comes to my mind once i see that ;)

anyhow, here are the files. use 'left' & 'right' to move the sprite.
Attachments
youAreLocal.love
youAreLocal
(40.58 KiB) Downloaded 47 times
youreNotLocal.love
youreNotLocal
(40.68 KiB) Downloaded 54 times
Last edited by hairy puppy on Sun Apr 27, 2014 8:10 pm, edited 1 time in total.
lewis lepton
------
http://smokingbunny.net
User avatar
SneakySnake
Citizen
Posts: 94
Joined: Fri May 31, 2013 2:01 pm
Contact:

Re: some help with local and images

Post by SneakySnake »

Please post help requests to Support and Development.

Anyway, the issue has nothing to do with locals or images for that matter.
The table constructor for playerAnimation is malformed.
You can't place statements inside a table constructor.

It should look like this:

Code: Select all

local playerAnimation = {
  left = {
      love.graphics.newImage('images/spriteSheets/player01L/left1.png'),
      love.graphics.newImage('images/spriteSheets/player01L/left2.png'),
      love.graphics.newImage('images/spriteSheets/player01L/left3.png'),
      love.graphics.newImage('images/spriteSheets/player01L/left4.png'),
      love.graphics.newImage('images/spriteSheets/player01L/left5.png'),
      love.graphics.newImage('images/spriteSheets/player01L/left6.png'),
      love.graphics.newImage('images/spriteSheets/player01L/left7.png'),
      love.graphics.newImage('images/spriteSheets/player01L/left8.png'),
  },

  right = {
      love.graphics.newImage('images/spriteSheets/player01R/right1.png'),
      love.graphics.newImage('images/spriteSheets/player01R/right2.png'),
      love.graphics.newImage('images/spriteSheets/player01R/right3.png'),
      love.graphics.newImage('images/spriteSheets/player01R/right4.png'),
      love.graphics.newImage('images/spriteSheets/player01R/right5.png'),
      love.graphics.newImage('images/spriteSheets/player01R/right6.png'),
      love.graphics.newImage('images/spriteSheets/player01R/right7.png'),
      love.graphics.newImage('images/spriteSheets/player01R/right8.png'),
  }
}
Check out the "Table Constructors" section in the Lua reference manual to learn more: http://www.lua.org/manual/5.1/manual.html#2.5.7
Last edited by SneakySnake on Sun Apr 27, 2014 7:56 pm, edited 1 time in total.
User avatar
hairy puppy
Prole
Posts: 29
Joined: Tue Apr 22, 2014 3:34 pm

Re: some help with local and images

Post by hairy puppy »

after a wee dog walk i got to thinking about some old c++/openframeworks projects i made to learn the platform better [ive ultimately stopped because it was just way too much, plus i really just want to make something rather than debug all the time ;)]
but there are ways that you can cycle through a folder of items, say pictures, or whatever is in the folder really. but with some projects i built, i had a folder with specific images in, labelled '001,002,003 etc...', and it was wasnt much code, it was just a few lines which targeted the folder that read whatever was in it, then you could cycle through them with some keyPressed code.

was just wondering if there was something similar for lua/love2d.
this was more a 'think out loud' scenario and ill look into it. but would think that that would be good as a cheap alternative, rather than having the code that i do have for the images
lewis lepton
------
http://smokingbunny.net
User avatar
hairy puppy
Prole
Posts: 29
Joined: Tue Apr 22, 2014 3:34 pm

Re: some help with local and images

Post by hairy puppy »

@sneakysnake
ah, ok, that makes sense. ill give that a go.
thanks for pointing that out. i had a feeling it was something along the lines of that, though was ultimately unsure.

also ill remember for the 'support and development' for future needed help questions
lewis lepton
------
http://smokingbunny.net
Post Reply

Who is online

Users browsing this forum: Semrush [Bot] and 224 guests