ID:448931
 
(See the best response by DarkCampainger.)
Code:
        View_Cards()
if(!deck.cards.len)
usr << "[usr.name] appears to be out of cards in [usr.game_gender] Deck."
return
var/A = input("Type in a number of cards to view off the top of your Deck.","View Cards on top of Deck.")as null|num
if(!A) return
if(A > deck.cards.len)
usr << "You don't have THAT many cards in your Deck."
return
var/L[A]
var/i
for(i=1, i<=L.len, i++)
L[i] = i
world << "[usr.name] views the top [A] cards of [usr.game_gender] Deck."
input(usr,"Here are the top [A] cards of your Deck.","Viewing cards on top of Deck")as null|anything in L


Problem description:

Okay so what I want it to do is show me a number of cards off the top of the Deck equal to the number that "A" is. How would I iterate that?
You just need to fix a few things. I'm on my phone, so this may not be very clear, but try to follow me here.
In your for loop, change it to this:
for(i = 1, i<=A, i++)

Then change the next line to:
L[i] = deck.cards[i]

I will happily explain what these changes are and why they needed to be done. If you don't understand please ask. Its better that you learn why it happened than just accept that it did and move on.
Well what you asked me to changed got the code to actually work although, it's only showing me 2 cards no matter what number I input. Anyway to fix it?
If this is a verb, use usr consistently(put it in front of deck.cards), if not then get rid of all usr's. Otherwise the problem must be elsewhere, as nothing here appears to be causing this.
Adding in the usr helped a lot, thanks so much. It's been a while since I last coded so the cobwebs are still up there. Reading the Guide over again is helping too.
I suppose one more thing...
        Arrange_Cards()
if(!usr.deck.cards.len)
usr << "You don't have any cards in your Deck to even arrange."
return
var/A = input("Type in a number of cards to view off the top of your Deck so you can arrange them.","View Cards on top of Deck.")as null|num
if(!A) return
if(A > usr.deck.cards.len)
usr << "You don't have THAT many cards in your Deck."
return
var/L[A]
var/i
for(i=1, i<=A, i++)
L[i] = usr.deck.cards[i]
world << "[usr.name] views the top [A] cards of [usr.game_gender] Deck."
var/swap = input("Here are the top [A] cards of your Deck.","Viewing cards on top of Deck")as null|anything in L
if(!swap) return
alert(usr, "Now choose a card to swap [swap] with.","Choose another card.")
var/swap2 = input("Here are the top [A] cards of your Deck.","Viewing cards on top of Deck")as null|anything in L-swap
if(!swap2) return
switch(alert("Are you sure you want to swap [swap]'s place with [swap2]?","Swapping Cards","Yes","No"))
if("Yes")
usr.deck.cards.Swap(swap, swap2)
if("No")
return


Using the code I somewhat mastered, I'm trying to make a "Arrange Cards" verb. I got it correct down to the part where the code actually swaps the cards around. it gives me this:

runtime error: list index out of bounds
proc name: Arrange Cards (/mob/verb/Arrange_Cards)
usr: Paul De La Torre (/mob)
src: Paul De La Torre (/mob)
call stack:
Paul De La Torre (/mob): Arrange Cards()

I don't know how I can fix this unless I did something that made the List's index go all screwy?
Lists are tricky. Youre going to need to create another list, populate it with the same items in the deck until you get to swap point A(use a for() loop), then populate that place with what is in swap point B. then continue copying the list until you get to swap point B, and fill it with swap point A. Then copy the rest, and replace their current card list with this new one. Any questions?
Lost me there.
In response to Paul De La Torre
Best response
Swap() expects indices, you're passing it the actual cards at the indices. Use Find() to get the index of each card:

var/swapIndex = usr.deck.cards.Find(swap)
var/swap2Index = usr.deck.cards.Find(swap2)
if(swapIndex && swap2Index)
usr.deck.cards.Swap(swapIndex , swap2Index)
It totally slipped my mind to not use the Find() thanks so much for your help, it works perfectly now.
In response to Albro1
var L[] = deck.cards.Copy(1, min(deck.cards.len, A))
What is that? o.o
In response to Kaiochao
Kaiochao wrote:
> var L[] = deck.cards.Copy(1, min(deck.cards.len, A))
>


Thanks, I havent used Copy() very much, forgot it worked like that. I guess that's what i get for trying to help when I have barely touched DM in a few months, haha.