#Start a thread and I'll explain if you

1 messages · Page 1 of 1 (latest)

paper wren
#

i do care cuz it seems useful

red night
#

For sure, just what you have will work and some people dont care to learn actually lol

#

I just want you to understand that you're getting a direct reference to your SCRIPT. Not, money.

paper wren
#

yeah i got that part

red night
#

That's why your naming doesn't make sense currently.

#

So you understand that it should be like targetController as your reference name.

#

And then from there, you can access everything you want in it.

#

such as money

paper wren
#

waittt i think i just got what you mean

#

so like hold on

#

so your saying even if i put targetController here instead of Money i'd still be able to use the money variable and it would be less confusing?

#

or am i at a loss again

red night
#

haha yeah, that's why i'm saying you don't quite understand yet. Yes, you would do targetController typically. Because you are referencing the ENTIRE script, NOT just money.

#

It's just a different variable name, it will all work, doesnt matter the name, but for clarity and so you understand, you should name it as the script and then access .Money from it.

paper wren
#

ok ok so i change it from
public TargetController Money;
to
public TargetController targetController.Money;

red night
#

Yup. Now, be sure you understand you have access to the whole script (so long as it's public). So you could have targetController.BankAccount, etc.

#

Or even a function:
targetController.MoveTarget()

#

you should get intellisense with all the options when you just do targetController.

paper wren
red night
#

Oh i missed that you named your reference as that lol

#

This is wrong.

paper wren
#

mannn

red night
#

Your reference is:
public TargetController targetController

#

Now drag that object/script into that spot in the inspector.

#

Then in your code, you call targetController.Money

paper wren
#

ok ok so i would then, confusingly change Money.Money -= 1 to targetController.Money.targetController.Money -= 1

red night
red night
paper wren
#

like your asking to make sure i get it?

red night
#

Your reference is targetController.
Now you want to access Money from that script.

paper wren
#

yeah so i do targetController.Money i get that part

red night
#

that's it. yes.

paper wren
#

ok lmao

red night
#

like you have here

paper wren
#

arent i doing it twice though cuz it means targetController.Money = targetController.Money - 1

#

dalphat told me to switch it to a dot in the middle instead of an = because it was giving me an error

red night
paper wren
#

dont worry bout it

#

anyways ok i get it now i think

red night
#

So now if you need something else from the target in this script you're in, you should understand how to access it hopefully.

paper wren
#

ok yeah i just did access something else cuz i needed to make it change the text aswell

#

butttt before i go theres a new issue lmao rq

paper wren
#

i think i need two of them man

red night
#

Share your code.

paper wren
#

the full thing rq?

red night
#

sure

paper wren
#

its pretty short but ill grab one of those websites for it

#

whats the command to pull up the list of them

red night
paper wren
#

thats the full thing thats giving me the error i mentioned

red night
#

can you share your TargetController script too?

paper wren
#

yeah sure

red night
#

Where is this variable defined?

paper wren
#

😭

#

meant to switch that to targetController.Money

#

that would be the issue then

#

mb i copied the set text part from the targetcontroller and didnt realize

red night
#

all good

paper wren
#

alrrrr final test real quick

#

oops forgot to reference the object again lmao

#

okkk final test real quick again

#

alright it all works out 🙏

red night
#

Nice! Congrats. As a small FYI, the code is not the best, as it makes no sense that a target would know about money, but you're learning to reference different scripts and learning in general, so it's good.

#

Just something to think about in the future 🙂

paper wren
#

alr alr now would you be fine with me asking another kind of related but unrelated question

red night
#

sure

paper wren
#

now cuz im using this to set up buying something so i want you to only be able to do it after you have a certain amount of money right

#

so is there a way to add like an "and" type thing to the "if" part that checks the amount of money first aswell?

red night
#

That sounds perfect to me.

paper wren
#

alr ill try to set that up on my own

#

ill come back to the main beginner channel if i have any more issues but for now i should be fine

#

ty for all the help

red night
#

Yup all good. Take a moment to think about what you'll need before writing the code. Helps to take a step back first.

paper wren
#

omg sorry just wanted to say