ID:1140456
 
ob/card_player
icon='suppchar.dmi'
icon_state="card"
verb/play()
set src in view(1)
var/randturn=rand(0,1)
if(!randturn)
usr.turn=1
src.turn=0
if(randturn)
usr.turn=0
src.turn=1
while(1)
var/oppcard=pick(src.hand)
var/mycard=input("Which card?") in usr.hand
view(5) << "[src] plays [oppcard] with attack of [oppcard.atk] and defense of [oppcard.def]"
view(5) << "[usr] plays [mycard] with attack of [mycard.atk] and defense of [mycard.def]"
sleep(1)

obj/punch_card
var/atk = 0
var/def = 0
icon='card.dmi'
New(a,b,i)
atk = a
def = b
icon_state="[i]"


Problem description:The computer randomly picks a card from the list called hand and I pick a card from my list also called hand but DM gives me an error when I input something like [mycard.atk] when it has an atk variable. How do I get around this?
You mean var/obj/punch_card/mycard=input("Which card?") in usr.hand ???

This won't actually work if usr.hand doesn't contain any /obj/punch_card s
But it WILL contain that! What should I do?
I added
            if(src.hand.len>0 && usr.hand.len>0)
on top and the error is gone
Now when I play I get another error when I click the verb play. runtime error: Cannot read "85".atk
Associative lists. You are getting keys. Get the values instead. Or even better, just use a normal list since it just gives you problems every now and then. I don't think associative lists will be put into good use in your game anyways.
var/selection = input("Which card?") in usr.hand
if(!istext(selection))
world << "go post on the forum that input() didn't return text"
var/obj/punch_card/mycard = usr.hand[selection]


try this? I don't know what the hell is in your usr.hand list.

I am pretty sure you are making something you aren't capable of making. We've done most of the work for you. I suggest you learn a lot more about variables, path types, passing arguments, getting return values, object oriented programming in general, associative lists...

The error is telling you that the text "85" isn't an object (its text) and text can't have variables, such as .atk

So in other words, your input call is returning text.
That's why I call myself just a beginner. I think I'll have someone else do this work for me.
Do what FIREking did or use a normal list. It's not a good idea to suddenly plugin associative lists into your code if you're not familiar with it. Don't give up just yet.
When I used normal lists the numbers showed up not the objects.
Well, you'll have to do some changes in your code since you were using associative lists.
I'm not sure whether I should continue trying to do this or just wait and get someone to do it for me
Send me the details, I'll help you out tomorrow. I need to go to bed. Play with your code for a while.
I already posted everything here.
Ok I used FIREking's coding and it seems to work so far. This is what I have so far:

mob/card_player
icon='suppchar.dmi'
icon_state="card"
verb/play()
set src in view(1)
var/randturn=rand(0,1)
if(!randturn)
usr.turn=1
src.turn=0
if(randturn)
usr.turn=0
src.turn=1
while(1)
var/obj/punch_card/oppcard=pick(src.hand)
var/obj/punch_card/oppcardtwo=src.hand[oppcard]
if(src.hand.len>0 && usr.hand.len>0)
var/selection = input("Which card?") in usr.hand
if(!istext(selection))
world << "go post on the forum that input() didn't return text"
var/obj/punch_card/mycard = usr.hand[selection]
view(5) << "[src] plays [oppcardtwo] with attack of [oppcardtwo.atk] and defense of [oppcardtwo.def]"
view(5) << "[usr] plays [mycard] with attack of [mycard.atk] and defense of [mycard.def]"
if(usr.turn)
var/myexp=usr.exp/10
if(mycard.atk==oppcardtwo.def)
myexp/=2
usr.exp+=myexp
view(5) << "[usr] gained [myexp]"
else if(mycard.atk>oppcardtwo.def)
var/dmg
dmg=mycard.atk-oppcard.def
myexp*=dmg
usr.exp+=myexp
view(5) << "[usr] gained [myexp]"
else if(mycard.atk<oppcardtwo.def)
var/negdmg
negdmg=oppcard.def-mycard.atk
myexp/=negdmg
usr.exp+=myexp
view(5) << "[usr] gained [myexp]"
sleep(1)
It looks like the input doesn't pop up though
Using usr and src in the same verb play() is really just a bad idea. Honestly, you're going about this all wrong. It's really hard to tell you what to change because the answer would be, to write it properly, from scratch.

Having a giant while(1) loop that never ends and hence play verb never actually returns is a bad idea.

The input will never display if usr or src.hand.len is 0 or lower.

It would be better to write the card game as an object, and have it take moves as input and then you can just get an output from it... I suggest taking a look at the developer's resources and finding a card game template or something similar.
Ok.
It looks like I'm not ready to make a card game yet.
It doesn't matter what you try to make, if you don't learn how to program right, you're always going to be running into this kind of stuff, getting stuck in it.

Why don't you learn how to do basic, simple things, and learn to code on a basic level? It's good to get experience, but if you learn to code the wrong way, you're just creating more issues for yourself.

I learned from writing something, then having a more experienced, better coder write it for me to observe, maybe you should try that as well.