[SOLVED] Can i reference other actor's attributes?

tetsu0sh0

  • Posts: 49
Is it possible to get an attribute from an actor?
Say i have a scene behavior that clicks on an actor.
That actor has an attribute of "health"
Can i somehow reference that attribute without making it global?

« Last Edit: August 24, 2012, 12:41:06 pm by tetsu0sh0 »

rob1221

  • *
  • Posts: 9448
There are blocks under Behavior > Attributes to do that.

tetsu0sh0

  • Posts: 49
Yeah i found them. Thank you.
I'm having a difficult time organizing my game.
I'm unsure of whether i should make my code per actor, or make behaviors and attach them to my actors..

ipe 369

  • Posts: 1001
Probably behaviours, it's much easier especially if you find out you need it again

shotfrost

  • Posts: 221
i think if that code is applied to multiple actors then you should make it into a behavior for easier further change, and also easier when you need to refer to it;e.g:disable it or get an attribute from it. other than that, you can make your own code.but i still think you should put it into behaviors( just my personal opinion from personal experience ^^)

tetsu0sh0

  • Posts: 49
Thread Hijack

Well the thing is, i'm making an RTS...
So right now i have a behavior that will select and deselect a unit, issue a move command etc etc..
But i'm not sure if that should be a scene command or an actor command because i want to interact with every single actor type.

And then what about gathering resources?
How would i go about knowing if my actor is near the resource or not..
I got the reference and i can "pull" resources from the resource point and place them into my actors inventory..

I'm setting a bit when my actor collides with a resource, but how do i know when he walks away?

Ugh.. so many questions

ipe 369

  • Posts: 1001
For your first question, you should make it an actor behaviour then attatch it to every actor type you want to be draggable.
for your second question, use pythagoras' theoryum (or something, you know, a^ + b^ = c^) To get the distance.

For your last question, set a boolean in the always block to false all the time, and in the when collides set it to true. Then when the true goes back to false you know the actor has moved away.

tetsu0sh0

  • Posts: 49
Say there's 10 trees in a forest.
My worker walks up to one of those trees.
How do i specifically reference that tree and that worker?

ipe 369

  • Posts: 1001
Make a behaviour. This behaviour is an actor behaviour for the worker.

3 attributes:
closest distance
current tree
maximum distance (So the worker doesnt go seeking a tree from miles away)

for each actor of type _tree_
if (distance (pythagoras) < closest distance)
{
    if (distance < maximum distance)
    {
         closest distance = distance;
         current tree = the actor (The block you get when you place the for each actor of type);
    }
}

tetsu0sh0

  • Posts: 49
ok im gonna try that thanks.
How would i go about calling that though?
I wouldn't want my worker ALWAYS searching for a tree.
Would you recommend having a "search for tree" boolean?
And than when a tree is found, reset the "search for tree"?

ipe 369

  • Posts: 1001
no, put it in the always block. Set the maximum distance to like, 10. Then whenever a worker is close to a tree, it'll chop it. Because the distance is so small, the chances are if you click so close to a tree you want him to chop anyways

tetsu0sh0

  • Posts: 49
OH alright. Hmm gotta try that.
Thanks man :)

« Last Edit: August 24, 2012, 08:16:51 am by tetsu0sh0 »

tetsu0sh0

  • Posts: 49
See this is what i dont understand yet.

This worker is always going to be doing a distance algorithm for every tree on the map right?
Multiply that by a lot of workers, and a lot of trees.
This wont lag at all?

Also... what do i do with the "Actor of Type" block once i get it?
How would that carry over into another behavior? Or would it?

Sorry for all these questions - I thought i had a grasp on how this all worked but i guess i really dont.

ipe 369

  • Posts: 1001
No, you can't move the actor of type block, set it to the closest tree attribute then get that from the behaviour you need

i'm not sure about the lag, if there were 1000 trees on a map, then that'd just be laggy anyway. I can't see any other way of doing it other than having another behaviour for the tree and the 2 communicating.

tetsu0sh0

  • Posts: 49
I got the find tree thing working great thanks.
I'm still having issues pulling value from other actors/behaviors.

When my actor is near the tree and chopping, i want to decrease the "resource amount" by 1 every second. I also want to increase my actor's "Resources carried" number by that same value.

I keep getting a null reference.
Attached screenshots this time