Help drawing images properly

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
tdc5013
Prole
Posts: 38
Joined: Wed Feb 08, 2012 4:24 pm

Help drawing images properly

Post by tdc5013 »

Hi guys,

I've got some code here where I'm trying to illustrate a set of 5 cards; the last five played. The problem is that they're being displayed in reverse order:

http://imgur.com/AumA5MV

That image shows the start of a game, 4 cards played. The first card played is displayed fully, where as the last (latest) is displayed underneath. The actual ordering is fine, they're in place - just reversed.

http://codepad.org/ro6iZhOd

Cards being played are added to the pile with a normal table.insert, with no position specified; so they should just be adding the the end of the table, which means (to me at least) that the code should work. Can anyone point me in the right direction with this?
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Help drawing images properly

Post by Robin »

Normally, yes, but you're looping in reverse order. Replace line 3 by:

Code: Select all

for i = #GLOBAL_VARS.CardPile-4, #GLOBAL_VARS.CardPile do
And line 17 by:

Code: Select all

for i =1,  #GLOBAL_VARS.CardPile do
Hope that helps.

By the way, we'd prefer it that you upload a .love when you have a problem in the future. That way we can see if our proposed solution actually works before replying.
Help us help you: attach a .love.
tdc5013
Prole
Posts: 38
Joined: Wed Feb 08, 2012 4:24 pm

Re: Help drawing images properly

Post by tdc5013 »

Thanks for the help! And I'll remember that in the future, thanks for the info.
User avatar
Lafolie
Inner party member
Posts: 809
Joined: Tue Apr 05, 2011 2:59 pm
Location: SR388
Contact:

Re: Help drawing images properly

Post by Lafolie »

I have to ask, what is the deal with the GLOBAL_VARS table? It sounds suspiciously like _G, the "contents" of which can be accessed globally, since they're globals.

Code: Select all

someFunc = function()
    x = 1
end

someFunc()

print(x) -- 1
print(_G.x) -- 1
In Lua, pretty much everything you declare is global unless you specify otherwise (obvious exceptions are function parameters).
Do you recognise when the world won't stop for you? Or when the days don't care what you've got to do? When the weight's too tough to lift up, what do you? Don't let them choose for you, that's on you.
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 0 guests