Results 1 to 5 of 5
  1. #1

    Default Searching for actors using foreach

    This seems like some pretty basic functionality, I understand it's slow, it won't be done frequently etc.

    I need to search through all my actors to find a bunch of specific ones dynamically and add them to an array list. I'll worry about building the array and adding the found objects once I figure out how to fix this compile error.

    My code is the following:

    Code:
    local actor  A;
    local string actor_tag;
    
    ForEach WorldInfo.AllActors(class'Actor', A)
    {
    	actor_tag = A.Tag;
    	if (actor_tag == "Crystal")
    	{
    		P.ClientMessage("crystal found!");
    	}
    }
    The error I'm receiving is:
    Error, 'ForEach': An iterator expression is required

    On the "ForEach" line obviously.

    Cheers

  2. #2
    Veteran
    Join Date
    May 2007
    Location
    Above KillZ, Below StallZ
    Posts
    9,953

    Default

    I'm guessing that whatever code you're in doesn't have a WorldInfo reference. Is this in an Actor?
    http://www.ericbla.de http://www.dungeondefenders.com http://en.wikipedia.org/wiki/Warm_Gun http://www.rekoil.com http://www.groundbranch.com

    - Please don't send me private messages asking programming questions, those would be better asked on the Programming forum here. Thanks

  3. #3

    Default

    It's in a UpdateCamera function.

    How do I go about adding a reference to WorldInfo?

  4. #4
    Veteran
    Join Date
    May 2007
    Location
    Above KillZ, Below StallZ
    Posts
    9,953

    Default

    so, is that in an Actor, or in an Object? if it's in an Actor, just do foreach AllActors(...) ... if it's in an Object, you could do class'WorldInfo'.static.GetWorldInfo()
    http://www.ericbla.de http://www.dungeondefenders.com http://en.wikipedia.org/wiki/Warm_Gun http://www.rekoil.com http://www.groundbranch.com

    - Please don't send me private messages asking programming questions, those would be better asked on the Programming forum here. Thanks

  5. #5
    Palace Guard

    Join Date
    Jun 2007
    Location
    Christchurch
    Posts
    3,514

    Default

    AllActors is an iterator defined in Actor. As the camera is an actor, it isn't necessary to use WorldInfo here.

    You can also compare Names directly, without having to do a string conversion then comparison.


 

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Copyright ©2009-2011 Epic Games, Inc. All Rights Reserved.
Digital Point modules: Sphinx-based search vBulletin skin by CompletevB.com.