Hello. I was watching BergZurg Arcade make setters/getters for his hack and slash rpg in one of his video tutorials. I wanted to do the same so I tried to rig up a script in Java, only to find they weren’t covered in the newbie guide, walker boy, or TT tutorials. I found a script, but when I try to reference the command in another script I get nothing. This could be because I don’t actually know how to reference commands or functions from other scripts. So my question today is two fold. Here is the set/get command.
Which are to be used in later on in the script:
As a simple test I tried to get it print out the adjusted value in another script.
Which gives the unknown Identifier error. I know from the vids that in C# you can change the properties your script inherits from. But I’d like to learn how to do it in java partly because Java overall seems more user friendly, and partly because I already tried copying BurgZerg only have the crushing reality that I didn’t have any idea what I was doing come crashing down halfway through. Thank you kindly for your time.
you need an instance of said class (the script where the function is in declares a class and if you put it on something that gives you an instance) and then call it someInstance.AdjustedValue()
there is no global, non classes form of function declarations
dreamora: First off thank you for the quick reply. But I’m not sure how to i instance a class.(Do you mean put the script on a game object?) I made the rest of the alterations and now the error is telling me to do exactly that.
Right you would put the script onto a game object and then later find that specific script instance at runtime through some measure (or by having a public variable on the later that wants to use it which you setup in the editor already for example)
alright so I got a variable attached my BaseAttributes script, however it’s not working like I hoped it would.
Now I’m quite sure I’m doing it wrong since all I’ve done is added another error. Thanks in advance for your patients, I know I’m being a super newb with this. If you have any tutorials or reference I’d be happy to to take a look and try to get the rest myself. I was looking for hours before I came here and most was either not quite related or way over my head. I’ve been getting a bit warmer since you mentioned the instancing
Yes, this can be confusing.
lets say you have this setup
gameobject A
script1-- attached to gameobject A
gameobject B
script2–attached to gameobject B
if you want script2 to communicate with script1, normally you would need to first find gameobjectA (gameobject.find or similar)
the you need to get the script1 instance thru getcomponent on gameobjectA
after that script2 instance can call whatever public methods in script1 instance.