Post by yochinatsu on Jun 1, 2024 14:29:17 GMT -5
The error message "ERROR: Attribute Error: 'int' object has no attribute 'stat_type'" is a recurring issue within the code.
Im tryng the command 'get_energy_level' to get the energy level of a SIM.
If you can give me a code that already do that I would be thankfull too
I need it because it's a requirement for the mod I'm developing.
Please help! Thank you!
Im tryng the command 'get_energy_level' to get the energy level of a SIM.
If you can give me a code that already do that I would be thankfull too
I need it because it's a requirement for the mod I'm developing.
from sims4.commands import Command, CommandType, CheatOutput
import services
# Import your custom logger
from logger_messages import Logger
@Command('get_energy_level', command_type=CommandType.Live)
def get_energy_level(sim_id: int = None, _connection=None):
output = CheatOutput(_connection)
output("Starting energy level check command...")
Logger.log("Command initiated: get_energy_level")
try:
sim_info_manager = services.sim_info_manager()
sim_info = sim_info_manager.get(sim_id) if sim_id else services.active_sim_info()
if sim_info is None:
output("No Sim found.")
Logger.error("No Sim found. Exiting command.")
return
Logger.log(f"Retrieved Sim info: {sim_info}, Type: {type(sim_info).__name__}")
if not hasattr(sim_info, 'get_statistic'):
output("Error: Retrieved object is not a Sim info type.")
Logger.error("Invalid object type retrieved.")
return
energy_stat_hash = 0xA63B5343
energy_commodity = sim_info.get_statistic(energy_stat_hash, add=True)
if energy_commodity:
energy_level = energy_commodity.get_value()
output(f"Current energy level: {energy_level}")
Logger.log(f"Current energy level: {energy_level}")
else:
output("Energy commodity not found.")
Logger.error("Energy commodity not found.")
except AttributeError as e:
output(f"Attribute Error: {e}")
Logger.error(f"Attribute Error: {e}")
except Exception as e:
output(f"Unexpected error: {e}")
Logger.error(f"Unexpected error: {e}")
Please help! Thank you!