#Card list thing
1 messages · Page 1 of 1 (latest)
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
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)
And learn how to use functions with parameters
Please use paste sites and show the whole script
!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.
That's a massive script
On a side note, I don't get why all those shared repeated variables are not just in Card
ye i know, i started not much time ago so i'm still getting grasp of separating scripts
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?
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.
Ok lemme look at the script again
Thank you
The deck List?
yes
I see you have an AddCard function
Where do you create the card instance that you want to add to the deck?
ye i was trying things around
that's exactly the problem. i want to create it outside the awake function, and yet i get errors when i try
no proble no problem, thank you again
Coming into this a bit late but I can take over, wanna get me up to speed with what the current remaining problem is?
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
What error
CS0236
The actual error
A field initializer cannot reference the non-static field, method, or property ‘DeckManagementYoryx.deck’
and same thing for "DeckManagementYoryx.playerScript"
What line
https://gdl.space/qowazenufo.cs line 286, it's not in the other one because it was a failed attempt and i deleted it prior to sending the code
You can't use deck outside of a function because it doesn't exist yet. Create the cards inside a function, all of the object initializers will have run by then
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.