#Card list thing

1 messages · Page 1 of 1 (latest)

sleek wasp
#

Making a thread

#

How about starting with the instantiating bit. Show how you're doing it?

#

@haughty atlas

#

It sounds like you just need to learn how to reference another script to access the list in it

haughty atlas
#

For info i used an abstract class as the base class for each type of card ( don't know if maybe a piece of code in there is the problem)

sleek wasp
#

And learn how to use functions with parameters

#

Please use paste sites and show the whole script

#

!code

empty pawnBOT
#
Posting code

📃 Large Code Blocks
Large code blocks should be posted as links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/
https://paste.myst.rs/, https://hastebin.com/

📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To get C# formatting the first line should only contain cs or csharp.
Add a comment with a line number if there is an error message.
```cs
// Your code here
```
Do not share screenshots of code unless requested.

haughty atlas
#

oh sorry, will do instantly

sleek wasp
#

That's a massive script

#

On a side note, I don't get why all those shared repeated variables are not just in Card

haughty atlas
#

ye i know, i started not much time ago so i'm still getting grasp of separating scripts

sleek wasp
#

Can you explain again what you're trying to do now that I have context?

#

Which is the list you want to add to?

#

And what are you trying to add to the list?

haughty atlas
#

Ye, i need a function that can add a Card object to the list inside the deck class, so that i can use that function from unity to add the card i click to the deck.

sleek wasp
#

Ok lemme look at the script again

haughty atlas
#

Thank you

sleek wasp
#

The deck List?

haughty atlas
#

yes

sleek wasp
#

I see you have an AddCard function

#

Where do you create the card instance that you want to add to the deck?

haughty atlas
#

ye i was trying things around

haughty atlas
sleek wasp
#

You have to do it in a function

#

I have to go, sorry

haughty atlas
#

no proble no problem, thank you again

lime atlas
#

Coming into this a bit late but I can take over, wanna get me up to speed with what the current remaining problem is?

haughty atlas
#

Oh, ye, if you look at the code ( ye i know it's massive i'm sorry) i want to add Card objects to the list in the Deck class dynamically but as far as i remember i have to instantiate the Card object before except that when i do it gives me an error on the parameters i'm passing.

#

Ah, and i need to do it through a function, so that i can then call that function throu unity

lime atlas
#

What error

haughty atlas
#

CS0236

lime atlas
#

The actual error

haughty atlas
#

A field initializer cannot reference the non-static field, method, or property ‘DeckManagementYoryx.deck’

#

and same thing for "DeckManagementYoryx.playerScript"

haughty atlas
lime atlas
haughty atlas
#

I see, so in cases like this i need to do it always inside a function so that all the other "components" gets created before the function.