Events Next: Event ConfigurationsUp: EventsPrevious: Events


SugarCubes provide the notion of an event with the following characteristics:

To indicate that an event is generated during the current instant, one sets its generated field to this instant number. In that way all events are automatically reset at the beginning of each new instant.

The value (present or absent) of an event can only be known safely after the event is fixed, that is as soon as it is generated, or otherwise at the end of the current instant. Event presence values aredefined in the EventConsts  interface.

public interface EventConsts
  final byte NOT_GENERATED = 0;
  final byte NO_HYPOTHESIS = 0;

  final byte PRESENT  = 1;
  final byte ABSENT   = 2;
  final byte UNKNOWN  = 3;

The presence method returns PRESENT if the event is generated, ABSENT if it is not (which is known only at the end of thecurrent instant), and UNKNOWN otherwise. Class Event  is:

public class Event
implements ReturnCodes, EventConsts, Cloneable
  public String name;

  private int generated = NOT_GENERATED;

  public Event(String name){ = name; }

  public boolean isPresent(Machine machine){ 
    return generated == machine.currentInstant(); 

  public void generate(Machine machine){
    generated = machine.currentInstant();

  public void makeAbsent(Machine machine){
    generated = - machine.currentInstant();

  public boolean isAbsent(Machine machine){ 
    return generated == - machine.currentInstant(); 

  public String toString(){ return name; }
  public Object clone(){ ... }

  public byte presence(Machine machine)
    if (isPresent(machine)) return PRESENT;
    if (isAbsent(machine) || machine.isEndOfInstant())
       return ABSENT;
    return UNKNOWN;