Team Spartan Cookies & Milk Forums
  • Issue Tracker
  • Donations
  • Search
  • Member List
  • Help

Register

Team Spartan Cookies & Milk Forums Garry's Mod Starfall v
« Previous 1 … 6 7 8 9 10 … 18 Next »
Sensor wirelink delay?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Threaded Mode
Sensor wirelink delay?
13-12-2017, 12:05 AM, (This post was last modified: 13-12-2017, 12:06 AM by SuperPlayer. Edited 1 time in total.)
#1
SuperPlayer Offline
TSCM Super Member
****
Posts: 234
Threads: 30
Joined: Oct 2014
Sensor wirelink delay?
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 end
When changing the inputs the following gets printed
Code:
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 --------------------------------------
As you can see there seems to be an error what the sensor array returns. It looks like some previous values dont get overidden or something. Also when changing to a ship_core or borg cube everything works fine.
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")
and
Code:
profiler.pop("TargetStuff")
properly? Because I always run into "Tried to pop too much".

Thanks,
SuperPlayer

[Image: banner_sgmgnlsa1.png]
Stargate Modding Group
Find
Reply
13-12-2017, 05:53 AM,
#2
Red The Blue Color Offline
TSCM Super Donating Member
****
Posts: 422
Threads: 34
Joined: Feb 2015
RE: Sensor wirelink delay?
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.


profiler.push("test")
for i=1,2048 do
printConsole(i)
end
profiler.pop()
--Then use the profiler tool on the chip

"with it's superior software, i have no doubt it will succeed in finding fuck all" - T-17, 2016

[Super Member] [ENCOM] т-ѕсм.Red The Blue Color™: server do you support Hitler?
[Server] srcds_linux: The probabilty is about 99.99%, so interpret that how you want to.
Find
Reply
13-12-2017, 10:45 AM,
#3
Person8880 Offline
gpj.ecafllorT
*******
Posts: 2,407
Threads: 45
Joined: Sep 2013
RE: Sensor wirelink delay?
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.
Find
Reply
13-12-2017, 05:17 PM,
#4
Kosmos Offline
GMod Admin
Posts: 180
Threads: 3
Joined: Dec 2013
RE: Sensor wirelink delay?
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).
Find
Reply
13-12-2017, 06:41 PM,
#5
SuperPlayer Offline
TSCM Super Member
****
Posts: 234
Threads: 30
Joined: Oct 2014
RE: Sensor wirelink delay?
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] SFConfusedamaritan/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") end
This code is a function which is called every 0.2 seconds. It is always printing starting profiling but when ending it the error happens.
And i tested just letting the profiler run for a few seconds, it still happens

[Image: banner_sgmgnlsa1.png]
Stargate Modding Group
Find
Reply
13-12-2017, 06:51 PM,
#6
Person8880 Offline
gpj.ecafllorT
*******
Posts: 2,407
Threads: 45
Joined: Sep 2013
RE: Sensor wirelink delay?
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.
Find
Reply
13-12-2017, 07:58 PM,
#7
SuperPlayer Offline
TSCM Super Member
****
Posts: 234
Threads: 30
Joined: Oct 2014
RE: Sensor wirelink delay?
Ahh ok. Thanks for the clarification.

[Image: banner_sgmgnlsa1.png]
Stargate Modding Group
Find
Reply
« Next Oldest | Next Newest »


  • View a Printable Version
Forum Jump:


Users browsing this thread: 1 Guest(s)
Contact UsTeam Spartan Cookies & MilkReturn to TopLite (Archive) ModeMark all forums readRSS Syndication

Powered By MyBB, © 2002-2026 MyBB Group.