- Home /
Question by
alexrweinstein · Feb 04, 2018 at 07:13 PM ·
errorinheritancedefinition
error CS1061: Type `StoryDeck' does not contain a definition for `populateDeckAndStack' and no extension method `populateDeckAndStack' of type `StoryDeck' could be found
First time programmer here, so apologies if this is trivial. I've gotten this type of error many times before, but this one is really stumping me. AdventureCards are working while StoryCards are not, but they are both set up the same way, even within the same file, since they inherit from a common object.
This following code is where the error is generated:
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using game;
public class Dealer : MonoBehaviour
{
protected AdventureDeck adventureDeck;
protected StoryDeck storyDeck;
protected Players players;
void OnGUI(){
if (GUI.Button (new Rect (10, 10, 256, 28), "Start Game")) {
adventureDeck.populateDeckAndStack ();
storyDeck.populateDeckAndStack (); //ERROR HERE
for (int i = 0; i < 4; i++) {
players.playerStacks.Keys.ElementAt(i).setRank(new RankCard());
}
int j=0;
for (int i = 0; i < 21; i++) {
players.Push (adventureDeck.stack.Pop (), j);
if(j == 3)
j=0;
else j++;
}
}
}
void Start(){
adventureDeck = new AdventureDeck();
storyDeck = new StoryDeck ();
players = gameObject.AddComponent<Players> () as Players;
}
}
And here is the relevant code for the object class being used:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace game{
public abstract class Deck {
public List<Card> deck; //store all cards in an arraylist called deck
public CardStack stack;
public CardStackView view;
public GameObject go = new GameObject();
public Deck(){
deck = new List<Card>();
stack = go.AddComponent<CardStack> () as CardStack;
view = go.AddComponent<CardStackView> () as CardStackView;
}
((...lots of functions here (getters, setters, drawCard, etc.)...)
// nothing here, it will be overrriden in the inherited functions
public abstract void populateDeckAndStack ();
}
public class AdventureDeck: Deck
{
public override void populateDeckAndStack(){
//this is where you add each card of each type for adventure cards
deck.Add (new Ally ("arthur", 10, 2));
deck.Add (new Ally ("pellinore", 10, 4));
deck.Add (new Foe ("black knight", 25, 35));
((18 more cards))
for (int i = 0; i < 21; i++) {
stack.Push (i);
}
}
}
public class StoryDeck: Deck
{
public override void populateDeckAndStack(){
deck.Add (new Quest ("boar hunt",2, new Foe ("boar", 5, 15)));
deck.Add (new Quest ("enchanted forest",3, new Foe ("evil knight", 20, 30)));
deck.Add (new Quest ("fair maiden",3, new Foe ("black knight", 25, 35)));
deck.Add (new Quest ("green knight",4, new Foe ("green knight", 25, 40)));
deck.Add (new Quest ("saxon raiders",2, new List<Foe> { new Foe ("saxons", 10, 20), new Foe ("saxon knight", 15, 25)}));
deck.Add (new Quest ("slay dragon",4, new Foe ("dragon", 50, 70)));
}
}
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612151927im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
NullReferenceException. GetComponent dose not work properly 2 Answers
Inventory does not contain a definition for inven ... but it does 1 Answer
The namespace already contains a definition for '' 1 Answer
Passing arguments to base constructor fails 1 Answer
passing variables through scripts 0 Answers