Skip to main content

Conditions for Events

Here we talk about Conditions.c!pp 

In this game, Conditions are implemented in a special way. Here the conditions are represented by the Condition-Object. The Condition-Object itself doesn't do much but it serves as base for the different condition types.

The reason Conditions are done this way when fellow coders know there are already boolean operations, is because the conditions have to be checked on demand, so these condition classes help to store the condition and then check on demand if the condition has been fulfilled.

So currently there is a set of different condition types already available. You can find the overview for those here.

 

So now lets set a condition for our event. On the last Page we used this code to register our event:

init 1 python: 
    set_current_mod('base')  

    event_label_event = Event(3, "event_label")
    courtyard_events["patrol"].add_event(event_label_event)

Now lets add a TimeCondition. The TimeCondition is used to for example set the event to be available only at certain times. For example only on Mondays or only during the evening.

Now the updated code looks like this:

init 1 python: 
    set_current_mod('base')  

    event_label_event = Event(3, "event_label", TimeCondition(day = "5-10", month = "2-", daytime = "f"))
    courtyard_events["patrol"].add_event(event_label_event)

You see now the added TimeCondition. It has multiple input values like day, month and daytime. This condition now limits the availability of the Event to between the 5th and 10th day of the month for only January and Febuary and only during free time. So you see, you have some freedom on what you can set for the TimeCondition. The details on what can be used for this Condition can be found below or in the Condition overview.


TimeCondition(blocking: bool = True, **kwargs: str | int)

This condition checks if the current time and date is within the set time limits.

blocking: bool = True

This value sets the visibility of the object including this condition. If blocking is set to True and the condition is not fulfilled, the parent will not be visible. That functionality is only limited for conditions used inside Journal Objects.

**kwargs: str | int

Here he time limits are set using arguments. To use it, set an argument together with the value. Here is an example:

TimeCondition(day= "5-10", month = "2-", year = 2024, daytime = "f")

Here you see the keys "day", "month", "year" and "daytime" set as the arguments together with their values. This example limits the condition to a time between the 5th and 10th on January of February 2024 during free-time.

You can use the following keys: dayweekmonthyeardaytimeweekday

For the keys: day, weekmonthyear, weekday and daytime you can simply set a value as a number or you can set a range.
To set the range, you can either use a plus-symbol at the end (2+) to set the value to the number and upwards. A minus-symbol (2-) for the number and downwards or a range between two values (2-5). The values themselves are always included.
You can also give a set of different values by seperating them with a comma. (2,5,10)

You can also mix the set together with ranges, so the following is also possible: 2,5-10,20+
That would include the values 2, all from 5 to 10, 20 and everything after.

Please make sure to NOT put whitespaces in between.

Some keys also accept special values used to make entering certain values easier. You'll find an overview further below.

Key Overview:

Key Description Limit Special Values
day Used to limit to a certain day in the month 1 - 28 -
week Used to limit to within a certain week in the month 1 - 4 -
month Used to limit to a certain month in the year 1 - 12 -
year Used to limit to a certain year 2023+ -
daytime Used to limit to a certain time of the day 1 - 7
  • "c" - The time during class (2, 4, 5)
  • "f" - The free-time (1, 3, 6)
  • "d" - The entire day except night (1-6)
  • "n" - The night
weekday Use to limit to a certain day in the week 1 - 7
  • "d" - Monday to Friday (1-5)
  • "w" - Saturday and Sunday (6, 7)

 


With that we have now successfully limited the Event, so that it now only shows up during certain times and dates.

On the next Page we talk about how to add images to your event.