fire detector problem

Discussion about Mods for Prison Architect

Moderator: NBJeff

rsdworker
level3
level3
Posts: 262
Joined: Sun Sep 30, 2012 2:36 pm

fire detector problem

Postby rsdworker » Thu Feb 05, 2015 9:44 pm

i had idea for fire detector so i copied the scripts from worker detector but there was error - saying pair is nil

code:

Code: Select all

 function Create()
    local ourX = Object.GetProperty("Pos.x")
    local oury = Object.GetProperty("Pos.y")
end

function Update ( passed )
    local nearbyObjects = Object.GetNearbyObjects("Fire", 2.0)
    local pris = "None"
    for name, distance in pairs( nearbyobjects ) do
        pris = name
    end
    if pris ~= "None" then
        Object.SetProperty("Triggered",2)
    else
        Object.SetProperty("Triggered",0)
    end
end


i am not sure why its having problems
GamingBud
level2
level2
Posts: 194
Joined: Mon Dec 29, 2014 8:33 pm

Re: fire detector problem

Postby GamingBud » Thu Feb 05, 2015 10:23 pm

rsdworker wrote:i had idea for fire detector so i copied...

Stop right there. Wow. Next time you should ask before coping someone else's scripts. Especially if you do not know how to use it.
rsdworker
level3
level3
Posts: 262
Joined: Sun Sep 30, 2012 2:36 pm

Re: fire detector problem

Postby rsdworker » Thu Feb 05, 2015 10:26 pm

GamingBud wrote:
rsdworker wrote:i had idea for fire detector so i copied...

Stop right there. Wow. Next time you should ask before coping someone else's scripts. Especially if you do not know how to use it.


sorry but i did gave suggestion to that person but as i said i will contact and give a apologise
but i am not sure if i could contacted first but i realised its was my fault because AgentBlackout didn't reply to my comment - problem is i have to friend him to message him first
seronis
level1
level1
Posts: 42
Joined: Fri Dec 05, 2014 1:32 am

Re: fire detector problem

Postby seronis » Fri Feb 06, 2015 3:27 pm

The code you copied is basic syntax. You're fine cause stuff like that is gonna end up being done the same way no matter who writes the code.

GamingDude is bad at syntax so doesnt realize this. Ignore his complaint
User avatar
Chad
level3
level3
Posts: 255
Joined: Wed Sep 26, 2012 8:00 pm

Re: fire detector problem

Postby Chad » Fri Feb 06, 2015 6:00 pm

rsdworker wrote:i had idea for fire detector so i copied the scripts from worker detector but there was error - saying pair is nil

code:
(...)
i am not sure why its having problems


check your Variables! nearbyobjects is not the same as nearbyObjects. Not existing variables are always nil.

seronis wrote:The code you copied is basic syntax. You're fine cause stuff like that is gonna end up being done the same way no matter who writes the code.

GamingDude is bad at syntax so doesnt realize this. Ignore his complaint


Epic answer! 8)
seronis
level1
level1
Posts: 42
Joined: Fri Dec 05, 2014 1:32 am

Re: fire detector problem

Postby seronis » Sat Feb 07, 2015 12:15 pm

Making a statement that suggests he did something wrong _IS_ a complaint. I think your english syntax is bad too.

Its also impossible to test something until its syntax is correct. You cant test bad syntax because its not valid code while the syntax is bad. Its somewhere between utterly broken and undefined behavior.
RGeezy911
level5
level5
Posts: 1098
Joined: Fri Aug 09, 2013 7:21 pm

Re: fire detector problem

Postby RGeezy911 » Sat Feb 07, 2015 8:19 pm

A few off-topic posts have been removed. Please get back on track guys.

Cheers!
Mercury002
level1
level1
Posts: 19
Joined: Wed Feb 11, 2015 11:25 pm

Re: fire detector problem

Postby Mercury002 » Sat Feb 14, 2015 3:05 pm

Ok the code you will use is generic, however some of the code is unnecessary for example this code will work just as well;

function Create()
local x = Object.GetProperty("Pos.x")
local y = Object.GetProperty("Pos.y")
local NAME_OF_YOUR_SCRIPT = Object.GetNearbyObjects ("Fire", 3) -- detects fire in 3 squares
for name,distance in pairs(NAME_OF_YOUR_SCRIPT) do
INSERT YOU CODE
Object.Spawn("Water", x, y) -- spawns water on top of object
end
else
INSERT YOU CODE
end
end

This is not the main problem of the code however, I've tried something similar in order to add water around watery objects like the sink, shower ect, if there is a fire nearby.
The problems are that while Object.Spawn works and can spawn anything (even supply trucks or more prisoners). If water is spawned, the code doesn't throw back any errors, however the water does not appear, perhaps it evaporates automatically really quickly like the fire hose and much more quantity needed?.

The main problem however is that while the Object.GetNearbyObjects works on all objects just as above, detecting fire is a different issue, It will activate code upon detecting the fire and throw back errors, this could be due to the nature of the fire. Fire grows and shrinks and spreads to other squares, so it is possible that the object "Fire" is only relevant at the very moment a fire spawns and then other objects/scripts are used to spread fire.

I tired to make ... flammable/explosive objects by using the code above to detect fire on top of the object Object.GetNearbyObjects ("Fire", 0) and then spawn fire all around the object and then delete the object (MUST DELETE THE OBJECT, otherwise it may create a loop of detecting fire and spawning fire infinity),. However this worked if the code was changed to discover anything else other than fire (haven't tried water but it might be the same), ie supply truck is nearby and boom the explosive goes off burning the driver
Mercury002
level1
level1
Posts: 19
Joined: Wed Feb 11, 2015 11:25 pm

Re: fire detector problem

Postby Mercury002 » Sat Feb 14, 2015 5:01 pm

Ok after A little testing the code, the code below detects the workman who just built the object and then it spawns 2 trees alongside ... it works (funny note you can kill a workman if you spawn objects all around the object they just built without deleting it as it uses up all of the squares - the workman disappears from the square and is replaced). :lol:

Code: Select all

function Create()
   local x = Object.GetProperty("Pos.x")
   local y = Object.GetProperty("Pos.y")
   local Test = Object.GetNearbyObjects ("Workman", 10)
      for name,distance in pairs(Test) do
         Object.Sound("__RiotAssault", "Explosion") -- creates an explosion sound, from the riot assault gorup of sounds
         Object.Spawn("Tree", x, y - 1) -- spawns above of object
         Object.Spawn("Tree", x, y - 2) -- spawns above of object
         Object.Delete (name)
      end
end


The code below wont detect the fire and thus wont spawn trees. :evil:

Code: Select all

function Create()
   local x = Object.GetProperty("Pos.x")
   local y = Object.GetProperty("Pos.y")
   local Test = Object.GetNearbyObjects ("Fire", 10)
      for name,distance in pairs(Test) do
         Object.Sound("__RiotAssault", "Explosion") -- creates an explosion sound, from the riot assault gorup of sounds
         Object.Spawn("Tree", x, y - 1) -- spawns above of object
         Object.Spawn("Tree", x, y - 2) -- spawns above of object
         Object.Delete (name)
      end
end


The code below wont detect the water and thus wont spawn trees, even if you call in the fire-brigade and spray it with water ... :roll:

Code: Select all

function Create()
   local x = Object.GetProperty("Pos.x")
   local y = Object.GetProperty("Pos.y")
   local Test = Object.GetNearbyObjects ("Water", 10)
      for name,distance in pairs(Test) do
         Object.Sound("__RiotAssault", "Explosion") -- creates an explosion sound, from the riot assault gorup of sounds
         Object.Spawn("Tree", x, y - 1) -- spawns above of object
         Object.Spawn("Tree", x, y - 2) -- spawns above of object
         Object.Delete (name)
      end
end


If you swap spawn tree with fire, then fire spawns, if you swap it with water then the code seems to work (as I added a sound to go off every time it worked) and the water doesn't appear.
This would seem to prove that the same code works for some things and not others. It must be a problem with the source code itself, I dont think we can do much until the developers fix it or include fire detection and watr spawning.
User avatar
Brento666
level3
level3
Posts: 290
Joined: Wed Sep 02, 2015 9:23 pm

Re: fire detector problem

Postby Brento666 » Wed Sep 16, 2015 7:45 pm

The code below wont detect the fire and thus wont spawn trees. :evil:

No one has replied here with updated info; Detecting fire with GetNearbyObjects is very much working in the current build!
(This topic can be closed)

Return to “Modding”

Who is online

Users browsing this forum: No registered users and 22 guests