![]() |
|
Sensor wirelink delay? - Printable Version +- Team Spartan Cookies & Milk Forums (https://teamscm.co.uk) +-- Forum: Garry's Mod (https://teamscm.co.uk/forum-4.html) +--- Forum: Starfall (https://teamscm.co.uk/forum-7.html) +--- Thread: Sensor wirelink delay? (/thread-2542.html) |
Sensor wirelink delay? - SuperPlayer - 13-12-2017 Hey there. While I was working on my chip today I noticed that there seems to be a problem with changing targets on the sensor array and getting the outputs via wirelink. This is the code I am talking about: Code: --@name Test
--@author SuperPlayer
wire.createInputs( {"IN"}, {"ENTITY"} )
Sensor = {}
Sensor.Entity = find.byClass("sensor_array",function( Ent ) return Ent:owner() == ents.owner() end )[1]
Sensor.Wirelink = Sensor.Entity:getWirelink()
hook.add( "input", "hookname", function( input, value )
Sensor.Wirelink["Target"] = value
printStuff(value)
end )
function printStuff(E)
print(E:class())
for k,v in pairs(getStatus(E)) do
print(k,v)
end
end
function getStatus(Ent)
if Ent:class() == "player" then
return {Health = Ent:health(), Armor = Ent:armor()}
elseif Ent:class() == "ship_core" then
return {Hull = Ent:entHealth(), MaxHull = Ent:entMaxHealth(),Plating = Ent:platingStrength(), Shield = Ent:getShield():getTotalCharge(),MaxShield = Ent:getShield():getMaxCharge()}
elseif Ent:class():find("box_") then
return {Hull = Ent:entHealth(), MaxHull = Ent:entMaxHealth()}
elseif Ent:class():find("st_shuttle_") or Ent:class() == "sci_fi_shuttle" then
return {Hull = Sensor.Wirelink["Health"]or 0, MaxHull = Sensor.Wirelink["Max Health"]or 0, Shield = Sensor.Wirelink["Shields"]or 0, Armour = Sensor.Wirelink["Armour"]or 0}
else
return {Health = Ent:entHealth()}
end
endCode: st_shuttle_type11
Shield 0
Armour 0
MaxHull 0
Hull 0
--------------------------------------
sci_fi_shuttle
Shield 100
Armour 200000
MaxHull 10000
Hull 10000
--------------------------------------
ship_core
Hull 410
MaxShield 60000
Plating 0
MaxHull 410
Shield 0
--------------------------------------
st_shuttle_type11
Shield 0
Armour 0
MaxHull 410
Hull 410
--------------------------------------But when changing to a shuttle the problem occurs. Ano figured out that if you delay printStuff(value) by 1 second everything works. Now my question is if that is intentional or a bug? Also while we are on it, could you explain how to use Code: profiler.push("TargetStuff")Code: profiler.pop("TargetStuff")Thanks, SuperPlayer RE: Sensor wirelink delay? - Red The Blue Color - 13-12-2017 I'm pretty sure sensors have a hardcoded delay if you attempt to change targets more than so many times under a certain amount of time (though i'm not sure) and profilers I don't use often but you use profiler.push(name) to start a profiler state and then just profiler.pop() to end it. If you attempt to pop without pushing one it will error.
RE: Sensor wirelink delay? - Person8880 - 13-12-2017 The sensor array refreshes in a short interval rather than immediately when the target changes. It's probably better to watch the outputs for changes using Wirelink:addOutputCallback() rather than to read directly from them. As for the profiler, as Red said, it's a stack, so the error you're getting means you're popping when you've not pushed anything yet. RE: Sensor wirelink delay? - Kosmos - 13-12-2017 I thought wirelinks (and wire links) aren't immediate, ever (unless the source entity updates before the target entity). For high-speed operations you need to use the readcell/writecell functionality (which is not well supported). RE: Sensor wirelink delay? - SuperPlayer - 13-12-2017 Ok thanks for the help with the sensor part. For the profiler part: The example red posted works but when using the following code it get the error [SF - ERROR] SF amaritan/Samaritan.txt:670: Attempted to pop too many profiler states.Code: if Samaritan.Values.Tactical.WeaponCode ~= "0|0|0|0" then
Samaritan.Operations.UpdateTargetPos()
if not Profiling then
print("Profiling now")
profiler.push("TargetStuff")
Profiling = true
end
end
if Samaritan.Values.Tactical.WeaponCode == "0|0|0|0" and Profiling then
profiler.pop()
Profiling = false
print("Not profiling anymore")
endAnd i tested just letting the profiler run for a few seconds, it still happens RE: Sensor wirelink delay? - Person8880 - 13-12-2017 Ah I see the confusion. The profiler can only measure inside a single call, as soon as the event/timer exits the profiler is reset. The idea is to profile each occurrence of a function/event/timer, so you can see how long a specific piece of code is taking. Leaving the profiler open over time will not give you useful results as it would include the actual time passed where it's not doing anything. RE: Sensor wirelink delay? - SuperPlayer - 13-12-2017 Ahh ok. Thanks for the clarification. |