# SPDX-License-Identifier: GPL-3.0
# Copyright (c) 2014-2023 William Edwards <shadowapex@gmail.com>, Benjamin Bean <superman2k5@gmail.com>
from __future__ import annotations
from dataclasses import dataclass
from typing import final
from tuxemon import formula
from tuxemon.event.eventaction import EventAction
[docs]@final
@dataclass
class SetVariableAction(EventAction):
"""
Set the key in the player.game_variables dictionary.
Script usage:
.. code-block::
set_variable <variable>:<value>
Script parameters:
variable: Name of the variable.
value: Value of the variable
(if value "today" = today's date)
"""
name = "set_variable"
var_list: str
[docs] def start(self) -> None:
player = self.session.player
# Split the variable into a key: value pair
var_list = self.var_list.split(":")
var_key = str(var_list[0])
var_value = str(var_list[1])
# replaces today value with ordinal
if var_value == "today":
var_value = str(formula.today_ordinal())
# Append the game_variables dictionary with the key: value pair
player.game_variables[var_key] = var_value