Space Engineers

Space Engineers

Statistiken ansehen:
Dieses Thema wurde geschlossen
How do you code with the Sensor?
has anyone found the code for if the sensor is activated or not?
There must be one since the color of the block changes with it.
< >
Beiträge 115 von 15
Straight from the document provided by the developer.

Sensor
Interface name: IMySensorBlock
Parent: IMyFunctionalBlock
Fields:
float LeftExtend
float RightExtend
float TopExtend
float BottomExtend
float FrontExtend
float BackExtend
bool DetectPlayers
bool DetectFloatingObjects
bool DetectSmallShips
bool DetectLargeShips
bool DetectStations
bool DetectAsteroids
Actions:
OnOff -> Toggle block On/Off
OnOff_On -> Toggle block On
OnOff_Off -> Toggle block Off
IncreaseLeft -> Increase Left extent
DecreaseLeft -> Decrease Left extent
IncreaseRight -> Increase Right extent
DecreaseRight -> Decrease Right extent
IncreaseBottom -> Increase Bottom extent
DecreaseBottom -> Decrease Bottom extent
IncreaseTop -> Increase Top extent
DecreaseTop -> Decrease Top extent
IncreaseBack -> Increase Back extent
DecreaseBack -> Decrease Back extent
IncreaseFront -> Increase Front extent
DecreaseFront -> Decrease Front extent
Detect Players -> Detect players On/Off
Detect Floating Objects -> Detect floating objects On/Off
Detect Small Ships -> Detect small ships On/Off
Detect Large Ships -> Detect large ships On/Off
Detect Stations -> Detect stations On/Off
Detect Asteroids -> Detect Asteroids On/Off
Lexe 2. Jan. 2015 um 6:21 
Zuletzt bearbeitet von Lexe; 2. Jan. 2015 um 6:21
if you spent more than 2 second looking at that stuff you would realise thats the one thing they LEFT OUT. hence why i'm talking about it.
You get what you get
but i know the variable exists. they just didn't document it.
If you know exists, why ask for it?
ugg i'm asking for what it's called.
Well you were provided with what they gave, if you believe it is there and as a public variable (which I doubt), time to start guessing on what name it could be
Wambosa 2. März 2015 um 22:11 
for others with the same question here is how to get what woolfoma is asking...

bool IMySensorBlock.IsActive

I just spent two hours scouring the internet and "guessing" for this little piece of information. unfortunately the documentation is not always accurate/updated. However i found it here
https://cubrr.github.io/space-engineers-doc-collab/html/P_Sandbox_ModAPI_Ingame_IMySensorBlock_IsActive.htm


By the way @Nekochan. rude.
Ursprünglich geschrieben von wambosa:
for others with the same question here is how to get what woolfoma is asking...

bool IMySensorBlock.IsActive

I just spent two hours scouring the internet and "guessing" for this little piece of information. unfortunately the documentation is not always accurate/updated. However i found it here
https://cubrr.github.io/space-engineers-doc-collab/html/P_Sandbox_ModAPI_Ingame_IMySensorBlock_IsActive.htm


By the way @Nekochan. rude.
OMG, i was making an AI space fighter (so you could basically have hordes of enemies to fight in sp) and i gave up because of this one thing, thank you so much for the help. I'll post here when i have made the fighter and uploaded it to the workshop.
Wambosa 3. März 2015 um 10:27 
yay! I am super glad that i could finally answer a question for someone! I've been a form crawler and knowledge leech for years. I really want to give back now. I had the same idea to make a more advanced AI, but have been having trouble with the API due to its intentional restrictions. (like no caching of the IMyEntity) BUT you can in fact access its methods and properties without caching it.
for others with the same question here is how to get what woolfoma is asking...

bool IMySensorBlock.IsActive
Not to sound really really dumb, but is it possible that you can only fetch that variable once per script?

What I am doing is basically this:
void Main()
{
IMySensorBlock heightSensor= GridTerminalSystem.GetBlockWithName("HeightSensor") as IMySensorBlock;

List<IMyTerminalBlock> blocks = new List<IMyTerminalBlock>();
GridTerminalSystem.GetBlocksOfType<IMyBeacon>(blocks);
IMyBeacon beacon = blocks[0] as IMyBeacon;
IMyBeacon beacon2 = blocks[1] as IMyBeacon;

beacon.SetCustomName(heightSensor.IsActive.ToString());
//while ((heightSensor.IsActive == false) && heightSensor.FrontExtend < 50) {
heightSensor.GetActionWithName("IncreaseFront").Apply(heightSensor);
//}

beacon2.SetCustomName(heightSensor.IsActive.ToString());
}
The idea is to keep increasing the range of the sensor to establish how far the nearest surface is from my platform, and in this example the sensor starts detecting at exactly 25m, and this is what happens when I manually set the range (1st beacon becomes "false" when set to 24m, and "true" when set to 26m).

I commented out the while loop to single-step through the execution for the purpose of tracking down the error.

However, the 2nd reading (and text assigned to the 2nd beacon) is always the same, even when logically it shouldn't be: When I run the script starting with range 24m, I get "false" (reading at 24m), then range gets increased to 26m, but the 2nd reading is still "false". I checked the range in the K menu and it was indeed incremented as I intended.

The next time I run the script however, the 1st beacon is set to true (still at 26m) when literally nothing has changed.

Does anyone have any idea what's going on?

Edit to add: Or, to look at it another way, it seems that the sensor's detection is only updated once ever phyics step (i.e. 1/60s) while no time passes during the script's execution...
Zuletzt bearbeitet von AlexMBrennan; 3. März 2015 um 19:04
Actually, turns out that the whole loop is somewhat unnecessary - you can simply use sensor.LastDetectedEntity.GetPosition() to calculate the distance directly
var entity = sensor.LastDetectedEntity;
if (entity != null) {
var position = sensor.LastDetectedEntity.GetPosition();
// do stuff
}
else
{
// LastDetectedEntity returns null if no object is in range
// i.e. distance from target is > 50m
}
Zuletzt bearbeitet von AlexMBrennan; 4. März 2015 um 11:35
W h y s o r u d e ? @Nekochan
ShadedMJ 19. Aug. 2020 um 18:11 
Ursprünglich geschrieben von Tokio_Jokio:
W h y s o r u d e ? @Nekochan
Why rude __5__years__ago__ ???
< >
Beiträge 115 von 15
Pro Seite: 1530 50

Geschrieben am: 2. Jan. 2015 um 6:18
Beiträge: 15