Help: finding objects and setting them to a variable

Discussion about Mods for Prison Architect

Moderator: NBJeff

GamingBud
level2
level2
Posts: 194
Joined: Mon Dec 29, 2014 8:33 pm

Help: finding objects and setting them to a variable

Postby GamingBud » Sun Feb 01, 2015 4:16 am

So, i set these guy's to a variable

Code: Select all

   local Cable = tonumber(this.GetNearbyObjects("ElectricalCable", 1))
   local Alert = this.GetNearbyObjects("AlertElectrical", 1)

Alert - Later on i'm trying to call it to delete it, so far no problems
Cable - Later on calling it as a number just so see if there are a number of cables right under this object.
User avatar
Pruvan
level2
level2
Posts: 94
Joined: Mon May 27, 2013 4:11 am

Re: Help: finding objects and setting them to a variable

Postby Pruvan » Sun Feb 01, 2015 5:26 am

If you're trying to get the number of objects in the table returned by GetNearbyObjects, you're going to have to manually iterate through it and count the iterations. tonumber() won't work for that.
User avatar
Chad
level3
level3
Posts: 255
Joined: Wed Sep 26, 2012 8:00 pm

Re: Help: finding objects and setting them to a variable

Postby Chad » Sun Feb 01, 2015 8:38 am

GamingBud wrote:So, i set these guy's to a variable

Code: Select all

   local Cable = tonumber(this.GetNearbyObjects("ElectricalCable", 1))
   local Alert = this.GetNearbyObjects("AlertElectrical", 1)

Alert - Later on i'm trying to call it to delete it, so far no problems
Cable - Later on calling it as a number just so see if there are a number of cables right under this object.


It's like Pruvan said, and I'm pretty sure I've already pointed that out in another thread.
Object.GetNearbyObjects() returns a table of all found objects and the distance. You need for loop to iterate through the list.
GamingBud
level2
level2
Posts: 194
Joined: Mon Dec 29, 2014 8:33 pm

Re: Help: finding objects and setting them to a variable

Postby GamingBud » Sun Feb 01, 2015 4:26 pm

Chad wrote:
GamingBud wrote:So, i set these guy's to a variable

Code: Select all

   local Cable = tonumber(this.GetNearbyObjects("ElectricalCable", 1))
   local Alert = this.GetNearbyObjects("AlertElectrical", 1)

Alert - Later on i'm trying to call it to delete it, so far no problems
Cable - Later on calling it as a number just so see if there are a number of cables right under this object.


It's like Pruvan said, and I'm pretty sure I've already pointed that out in another thread.
Object.GetNearbyObjects() returns a table of all found objects and the distance. You need for loop to iterate through the list.

Yep, sorry. I didn't refer to my older codes that Chad lent me and that's why i made this mistake. I fixed it before i got a reply, but i forgot to say that.

Return to “Modding”

Who is online

Users browsing this forum: No registered users and 7 guests