0

Is there another way to use the conditional event to monitor parking spots? The end goal is to see on the events output log, when a car has parked and where. I made an event, that calls a function, that runs a loop through each parking space and returns true on a spot that is taken. I wanted to trigger this event whenever a car has parked but the looping is causing the simulation to freeze.

Function(){
for(int i = 0; i<29; i++) //29 = number of parking spaces
    {
        if(parkingLot2.getCarOnSpace(i) != null) //if spot i taken
        {
            return true; 
            //true sent back to event, is then triggered
        }       
    }
return false;
}

Event
condition: Function();
Action: event.restart();

1 Answers1

1

So first the event.restart() function only applies if the event has trigger type: timeout and mode: user control, otherwise your event.restart() function does nothing...

Second, you need to call your function not on a conditional event, but on the moment a car parks... You can do this on the "on exit" action of the carMoveTo block.

And your function can be done better using nSpaces instead of 29:

for(int i = 0; i<parkingLot2.nSpaces(); i++)
    {
        if(parkingLot2.getCarOnSpace(i) != null)
        {
            return true; 
        }       
    }
return false;

You can use a similar function to know in what space the car parked, but you need to have a separate array collecting info on which spaces are free or not since the parkingLot object doesn't have that function. Imagine you have an array with size parkingLot2.nSpaces() and boolean elements all starting with false since all the parking spaces are free. Whenever your car enters the parking space, you use the same function but instead of "return true" you set the array to be true in that particular index. And you have to set the array to false when the car exits.

Felipe
  • 8,311
  • 2
  • 15
  • 31
  • The point of using an event it that it has its own output log(Database->events_log). So I'm thinking its easier for a database to read just the event log to find out **when and where** a car has parked. Meaning I have to use an event to find that moment. What would calling the function on "on exit" in CarMoveTo do? It would return and do nothing. The function is to trigger the condition. Is there any way to place a trigger in the "on exit" Action that returns true to the event? – user9463018 Apr 05 '18 at 14:59
  • you could do something like having a variable called usedParkings initially 0 and the condition of the event would be parkingLot.nCars()!=usedParkings with an action saying userParkings=parkingLot.nCars(); – Felipe Apr 05 '18 at 16:26