#Hi I d like to flip the last card of a

1 messages · Page 1 of 1 (latest)

untold zealot
#

Which object is your deck? zoneDeckor the found obj?

#

Also where did you define cards, it's not in the code snippet

viral fulcrum
#

hi, the deck is the found obj

untold zealot
#

So can't really tell why you're having an error with it.

viral fulcrum
#

"obj"

#

"fleau" is the card I want to flip from "obj"

untold zealot
#

the line : index = cards[#cards].index, makes an error
What is cards?

viral fulcrum
#

if I remove the line it works by flipping the card from the top

#

the number of cards in obj ?

untold zealot
#

You mentioned last card of the deck, why not just use #obj.getObjects() which is the size of the deck and is also the index of the last object, since first one is a 1?

#

I meant, where are you defining cards? You referencing it in your code but I don't see where you assigned a value to a variable named cards

#

if you want to get the objects contained in a deck (the cards), call aDeck.getObjects()

#

since you want the last one, use that Dictionary table's size, with #

viral fulcrum
#

thet the part I don't really understand...

#
    for _, Deck in ipairs(zoneDeck.getObjects()) do
        if Deck.getName() == ('Evènements') then
            local fleauCard = Deck.getObjects()
            Deck.takeObject({
                index = cards[#cards].index,
                position = {33, 6, 23.95},
                flip = true
            })
        end
    end
untold zealot
#
    for _, obj in ipairs(zoneDeck.getObjects()) do
        if obj.getName() == ('Evènements') then
            local fleau = obj.takeObject({
                index = #obj.getObjects(),
                position = {33, 6, 23.95},
                flip = true
            })
        end
    end
viral fulcrum
#

oh

untold zealot
#

You said your found deck is obj, right?
So in order to get a table of it's contained cards, you should call obj.getObjects().
But since you're not seem to be interested in iterating them, but just know how many are there, you can get it's length / size with a pound symbol, like so:
#obj.getObjects()

#

that is the size of the deck

viral fulcrum
#

and the number of the last card of my deck, right ?

untold zealot
#

correct!

#

Because in Lua, an array's first index is 1, not 0.

viral fulcrum
#

ok

#

It still doesn't work, but I'll dig

untold zealot
#

Unless cards is defined somewhere else, it will keep erroring, because you never assigned it a value.

viral fulcrum
#

nope, it's just a copy / paste from a code that works fine

untold zealot
#

cards in your snippet is a variable, you're trying to get the value of a variable called cards that you never declared beforehand

#

Well that code has cards declared somewhere, and your snippet doesn't

viral fulcrum
#

I was thinkin that "cards" is standard, as Deck as type, or Blue as color

untold zealot
#

It would be Capitalized if so, but sadly it isn't.

viral fulcrum
#
Evê_guid = '272ee8'

function onload()
    spawnButtons()
    Evê = getObjectFromGUID(Evê_guid) 
end

function spawnButtons()
    self.clearButtons()
    button = {}
function toggleAdvButtons()
    self.lock()
    if advButtonsEnabled == true then advButtonsEnabled = false
    else advButtonsEnabled = true end
    spawnButtons()
end
------------------------------
function Propage()

    possible_Evê = Evê.getObjects()
    Evê_deck = nil
    for k,m in pairs(possible_Evê) do
        if m.tag != nil then 
            Evê_deck = m
            local cards = Evê_deck.getObjects()
            Evê_deck.takeObject({index = cards[#cards].index, position = {33,6,23.95},flip=true})
        end
    end
end
------------------------------
    button.width = 500
    button.height = 500
    button.function_owner = self
    button.position = {0, -0.3, 0}
    button.rotation = {0, 0, 0}
    button.click_function = "Propage"
    button.label = 'Por'
    button.font_size = 0
    self.createButton(button)

end
#

here is the full code that works fine

#

I never declared "cards"

untold zealot
#

Yes it is, right there:
local cards = Evê_deck.getObjects()

viral fulcrum
#

oh yeah I did

#

!!!

#

...

#

🥵

#

I neek to take a break I think...

untold zealot
#

You might as well. At least you know what's wrong and how to count the number of cards, right?