Welcome to Keen Software House Forums! Log in or Sign up to interact with the KSH community.
  1. You are currently browsing our forum as a guest. Create your own forum account to access all forum functionality.

Sensor problem

Discussion in 'Programming (In-game)' started by Rodiboki, Apr 29, 2020.

Thread Status:
This last post in this thread was made more than 31 days old.
  1. Rodiboki Trainee Engineer

    Messages:
    5
    Hi,

    I have a problem. I don't know why the script gets stuck in the while Loop when I leave the sensor area.
    If the while Loop the entity_list_out does not change and runs into the while Loop, entity_list_out is deleted by the Clear (.count again to 0)
    Then the list should be filled again, but if I am not in the sensor. the entity_list_out.Count should be 0.
    Where's the problem. Do you have to reset the sensor somehow or where is the problem?

    Code:
    List<MyDetectedEntityInfo> entity_list_out = new List<MyDetectedEntityInfo>();
    var sensor_out = GridTerminalSystem.GetBlockWithName("Sensor CC out") as IMySensorBlock;
    sensor_out.DetectedEntities(entity_list_out);
    
    if (entity_list_out.Count != 0)
    {
    //... Code  ...
      while (entity_list_out.Count != 0)
      {
    	  entity_list_out.Clear();
    	  sensor_out.DetectedEntities(entity_list_out);
      }
    //... Code  ...
    }
    
    Best regards
    Rodiboki
     
  2. Malware Master Engineer

    Messages:
    9,860
    You can't code like that. The game is essentially stopped while a script runs. This would simply make your script be forcefully terminated.

    So what's happening here is; you have a detection in the sensor. You clear and fill the list with the current state, which still will have a detection in the sensor. Which will cause a loop. Which will...

    The sensor state won't change, so you'll hit a complexity exception.
     
    • Like Like x 1
  3. Rodiboki Trainee Engineer

    Messages:
    5
    Ok.
    I have to use a different strategy. OK

    Many thanks.


    Best regards
    Rodiboki
     
  4. Malware Master Engineer

    Messages:
    9,860
  5. Rodiboki Trainee Engineer

    Messages:
    5
    Yes, I know.
    Now I stop a script early until the next start by the timer.
    I think my new strategy works.

    Best regards
    Rodiboki
     
    Last edited: Apr 29, 2020
    • Like Like x 1
Thread Status:
This last post in this thread was made more than 31 days old.