what is better

Discussions about Coding and Scripting
Post Reply
User avatar
Rakiayn
Masterful
Posts: 550
Joined: Fri Aug 28, 2009 3:33 pm

what is better

Post by Rakiayn »

lets say we have a actor1 in the map.

now if I want to acces that actor1 ingame through actor2, what would be best.

1:
do a 'for' or 'for each' search.
to search for actor 1 every time necesary

2:
or a 'for' or 'for each' search the first time.
and then set a Var in actor1 at actor 2
like:
var actor actor2;

and after that only acces actor2 through that var in actor1

I no for or foreach searches are slow. but I have the fealing that if an actor has a var , that can be quite slow to
gopostal

Re: what is better

Post by gopostal »

How do you want to access them? Depending on what you need from actor one (Inventory, location, some attribute like health or number of jumps left in their boots, etc?) your check will be different.

It's best to let the server control all this anyway. Having one actor check another is slow and should be avoided if you can.
User avatar
Rakiayn
Masterful
Posts: 550
Joined: Fri Aug 28, 2009 3:33 pm

Re: what is better

Post by Rakiayn »

I want to check for properties in the actor.
an example:

1:

Code: Select all


class S_MMSpawner expands TournamentWeapon;

var int number;

function checkpropertiesfromownerinfo()
{
local spawnermasterinfo mi;

	foreach AllActors(class'spawnermasterinfo', mi)
	{
             number = mi.somenumber  
             break;
             }
}

2:

Code: Select all


class S_MMSpawner expands TournamentWeapon;

var SpawnerMasterinfo ownerinfo; 

var int number;

function checkpropertiesfromownerinfo()
{

       if (ownerinfo != none)
       {
       number = ownerinfo.somenumber
       }
  
}

gopostal

Re: what is better

Post by gopostal »

I've never tried it like that but my gut feeling is that you are going to create a shitload of lag if the checks occur with any frequency. An occasional check to inventory of the child actor would be fine but consider that there may be 16 players with multiple children all doing checks at the same time. Even a foreach is gonna stress the server with that level of commitment.
User avatar
Rakiayn
Masterful
Posts: 550
Joined: Fri Aug 28, 2009 3:33 pm

Re: what is better

Post by Rakiayn »

ok, so Option 2 is good. because it doesnt have to do a search. right?
gopostal

Re: what is better

Post by gopostal »

Sure. Anytime you can let the server track the data, it will always be faster and less stressful. If you are going to be doing a lot of checking though to some particular thing you should consider timer so the load is smoothed out. I'm kinda shooting in the dark here though. I don't know if you need something as detailed as exact player position per tick or something much more general. Bandwidth is what hurts on code like this. We never have this problem in 2004 because the server>player pipe is so much larger, but in UT modders must keep lag-stess in mind for all replication back and forth.
Post Reply