Page 1 of 1

Problems with GetNearbyObjects

Posted: Sat Oct 04, 2014 7:11 pm
by ProgSys
Hi everyone,

It is maybe a dump question, but I don't understand what "TypeName" means in "Object.GetNearbyObjects( TypeName, SearchDistance )".
I looked through the Lua page and tried values like "Object" or "People", but nothing seems to work.

Here is a piece of my code:

Code: Select all

   local found = Object.GetNearbyObjects( "People", 20 );
   local size = table.getn(found);
   Game.DebugOut(size);

   for k, v in pairs(found) do
   Game.DebugOut(k);
   Game.DebugOut(v);
   end

-- [EDIT] Working code:
   local objectTypes = {"Guard","Prisoner" }
   for i,objectType in ipairs( objectTypes ) do
      local found = Object.GetNearbyObjects( objectType, 4 );
      for id, distance in pairs(found) do
         Game.DebugOut("Found:");
         Game.DebugOut(id);
      end
   end


Also I have problems with the Debug window, "DebugOut" does not open it. It only opens if a error happens. Is there a button to open it?

Thank you for your help!

Re: Problems with GetNearbyObjects

Posted: Sat Oct 04, 2014 11:34 pm
by learn_more
DebugOut prints either to the debug.txt or the windows debug output.

use DebugView : http://technet.microsoft.com/en-us/sysi ... 96647.aspx or logfusion: http://www.logfusion.ca/ to view debug output.

and no, the script debugger only opens on a script error


ps: you can use print as well, they redirected DebugOut to that.

Re: Problems with GetNearbyObjects

Posted: Sun Oct 05, 2014 10:55 am
by ProgSys
Well DebugOut does print in the game console:
Image
but it does not open the console, even thoght the description of the function inside "lua_function_list.txt" reads:
Game.DebugOut( Message )
Prints a debug message to the script debugger window. Opens the window if it is not yet opened.
N.B. As this functions opens a debug window, you should only use this function for testing purposes
and remove any calls before publishing your mod.

Only a error seams to open the console. So I thought there is maybe a hidden button to open it.

I tried to use print(), but it throws a Runtime Error.
I will try out DebugView.

Re: Problems with GetNearbyObjects

Posted: Mon Oct 06, 2014 5:59 pm
by elDiablo
Sorry, my bad.

TypeName is the Object type's name to get. This is the name given in the Object list from materials.txt. Things like, "Workman", "Toilet", "Visitor", etc. You can see the full list of default item names in the ObjectRequired section of the Material mod schema at http://devwiki.introversion.co.uk/pa/in ... /ModSchema but can also use your own added names. GetNearbyObjects will be improved in later versions (probably a new function) to allow you to search by properties (GetNearbyObjectsWithProperties or something) as well, as searching for all entities at the moment is a bit of a hassle (you will need to search for all entity subtypes, such as "Prisoner", "Medic", "Administrator", etc.).

The DebugWindow isn't working as intended. We'll look at that as well.

Re: Problems with GetNearbyObjects

Posted: Mon Oct 06, 2014 9:58 pm
by ProgSys
Thank you! You helped me a lot :D It would be nice to have a function, which prints out all properties a object has and the ability to put orders into the Work Queue, like "Search Object".