Page 1 of 1

Help drawing images properly

Posted: Thu Mar 14, 2013 2:41 pm
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?

Re: Help drawing images properly

Posted: Thu Mar 14, 2013 2:55 pm
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.

Re: Help drawing images properly

Posted: Thu Mar 14, 2013 3:01 pm
by tdc5013
Thanks for the help! And I'll remember that in the future, thanks for the info.

Re: Help drawing images properly

Posted: Fri Mar 15, 2013 4:24 pm
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).