can foreach command include tables name it is going through?
Posted: Thu Mar 12, 2015 8:22 pm
I already solved my problem alternative way as i came to conclusion it was better to be done different way, but I am anyway wondering for future purposes if following would be possible.
I had several different card deck tables:
abilitycards
blesingcards
recoursecards
These tables contained a list of cards and wether they were in use or not, as example:
Idea was that before starting the game, player could choose to possibly not include some of the cards in game, by changing that cards "inuse" variable to FALSE.
Hence at beginning of game, it would go through all the cards and check if they have "inuse" set to TRUE or not, and if TRUE, then add it to the actual playing deck.
What I wanted to do was something like this:
The obvious problem was on how do i pass this "decksname" variable to this checktoaddcard function to form a new deck that would contain those specifc type of cards?
And yes, I know just putting the name that was given when entering the function is not enough yet, since it will be replacing the original deck with new one making original one destroyed, but I used this wrong version to explain the main problem, for as long as i could first somehow pass the "deckname" through, its not hard to get it form its own deck of cards with different name.
I had several different card deck tables:
abilitycards
blesingcards
recoursecards
These tables contained a list of cards and wether they were in use or not, as example:
Code: Select all
abilitycards = {
["farmer"] = {inuse=TRUE}
}
Hence at beginning of game, it would go through all the cards and check if they have "inuse" set to TRUE or not, and if TRUE, then add it to the actual playing deck.
What I wanted to do was something like this:
Code: Select all
function FormDeck(deckname)
foreach(deckname, checktoaddcard)
endfunction
function checktoaddcard(card, data)
if data.inuse=true then insertItem(???deckname???, card)
endfunction
FormDeck("abilitycards")
FormDeck("blessingcards")
FormDeck("resourcecards")
And yes, I know just putting the name that was given when entering the function is not enough yet, since it will be replacing the original deck with new one making original one destroyed, but I used this wrong version to explain the main problem, for as long as i could first somehow pass the "deckname" through, its not hard to get it form its own deck of cards with different name.