#Hi I d like to flip the last card of a
1 messages · Page 1 of 1 (latest)
Which object is your deck? zoneDeckor the found obj?
Also where did you define cards, it's not in the code snippet
hi, the deck is the found obj
So can't really tell why you're having an error with it.
the line : index = cards[#cards].index, makes an error
What iscards?
if I remove the line it works by flipping the card from the top
the number of cards in obj ?
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 #
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
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
oh
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
and the number of the last card of my deck, right ?
Unless cards is defined somewhere else, it will keep erroring, because you never assigned it a value.
nope, it's just a copy / paste from a code that works fine
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
I was thinkin that "cards" is standard, as Deck as type, or Blue as color
It would be Capitalized if so, but sadly it isn't.
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"
Yes it is, right there:
local cards = Evê_deck.getObjects()
You might as well. At least you know what's wrong and how to count the number of cards, right?