- Home /
'x' is not a member of 'System.Type'.
import UnityEngine
class UpgradeMenuScript (MonoBehaviour):
public class UpgradeData:
public Upgrade1 = ("Rock Picker", 10, "5%", 7, 0.2)
public test = 1
public def constructor(te as int):
te = test
public UpgradeDataInstance = UpgradeData
def Start():
myUpgradeData = UpgradeDataInstance.test
This code is a test to see how I can access other variables (In this case, an array) from a class inside a script. I went through the whole "An Instance of Type 'X' is required to access non static member 'Y'" and people said to create an instance of it and I did. Now I get a new Error: "Assets/Upgrade Menu Stuff/UpgradeMenuScript.boo(16,39): BCE0019: 'test' is not a member of 'System.Type'."
Does anyone have any ideas on A: Whats causing it and B: How to fix it
Thanks, Jordan
With Boo, you may have trouble getting answers to this question. I've only seen a few Boo questions in the last year, so there are not a lot of Boo programmers on this list.
@robertbu There might however be some Python programmers (like myself) and Boo is really just C# + Python (when it comes to syntax)
Answer by Benproductions1 · Feb 24, 2014 at 11:42 AM
Hi! Python programmer here, just giving my 2 cents.
So I might be wrong ;)
When you define a new class, you are defining a type. That type is accessed directly by it's name. If you want to make a new instance of this type, you simply need to __call__
the type:
class Foo:
pass
//Foo is a type
type(Foo) == type
//True
//Make a new instance of Foo
bar = Foo()
//bar is of type Foo
type(bar) == Foo
//True
Therefore on line 16 (where you get the error), you are actually trying to get a variable test
from the type UpgradeData
, not from an instance of it.
I'll leave the fixing part up to you, but if you read my answer carefully i've already told you how to solve it.
The problem was actually the constructor. I was accessing test even though I assigned it to te but when I changed it to .te it wouldn't work either so that will have to do. $$anonymous$$aybe I'm using the constructors wrong. Anyway thanks for the reply. Not sure if that was what you had in $$anonymous$$d but it works now right? But if I add a constructor I get a new Error. I'll cross that bridge when It comes to it. Thanks for the help.
$$anonymous$$y answer solves the one error you posted. I specifically left our the rest with the constructor, as that was not what you asked. If you get a new error, then the one you were getting is solved and therefore the question answered.
You should do some research on OO, which should solve most of your problems.