Adamo Equipment

by ElAdamo

Oh, you'd be surprised at the things you can learn while you're doing alterations.

Content
9 days ago
2.0
112
Combat Armor

g crash when clicking armor to see grid

5 days ago

Error while running event adamo-equipment::on_player_armor_inventory_changed (ID 38)
Given value has to be larger than or equal to: 0
stack traceback:
[C]: in function 'newindex'
__adamo-equipment
/adamocontrol.lua:107: in function 'to_property'
adamo-equipment/control.lua:148: in function 'process_equipment_change'
adamo-equipment/control.lua:167: in function <adamo-equipment/control.lua:164>

5 days ago
(updated 5 days ago)

CORRECTION: its when i click with the left click. to remove the armor not when i try to see grid

if i click with right click it will open normally.

5 days ago
(updated 5 days ago)

Problem:
The error occurs when you click with the left mouse button while interacting with equipment, and it seems related to trying to assign a negative value to a player's property (like health or inventory slots). The error message indicates that the value being assigned must be greater than or equal to 0. The right mouse button works fine, suggesting a different event handling for each button.

Solution:
The solution focuses on validating values before they are assigned to the player's properties to ensure they are never less than zero.

Key Changes:
Validation Function:

A new function validate_and_apply_property was added. This function checks if the value to be assigned is negative, and if it is, it sets the value to 0. This ensures that no property is set to a negative value.
Updated Equipment Processing:

In the function process_equipment_change, where equipment is processed and properties are updated based on the player's gear, the new validation function is used. This ensures that when equipment changes, the modified values (e.g., health bonus, inventory slots) are validated and applied correctly.
Handling on_player_armor_inventory_changed:

This event, triggered by inventory changes (which includes left-click interactions), was updated to include this validation logic before applying changes to the player's properties, preventing any negative values from being assigned.
Code Snippet for Validation:
lua

local validate_and_apply_property = function(player, property, value)
local valid_value = math.max(0, value) -- Ensures value is >= 0
if valid_value ~= value then
Adamo.debug("Invalid value for " .. property .. " corrected to " .. valid_value)
end
Adamo.player.add.to_property(player, property, valid_value)
return valid_value
end
This function ensures that any value being applied to the player's properties (e.g., health bonus, inventory slots) is never less than 0. If the value is negative, it gets corrected to 0.

Conclusion:
By adding validation before applying changes to the player's properties, the solution ensures that no negative values can be set, thus preventing the error that occurs when using the left mouse button. The code now safely handles changes to the player's equipment and stats, ensuring that they stay within valid ranges.

5 days ago

that fixed the problem for now.

4 days ago
(updated 4 days ago)

Thanks, I'll check this out. My code has guards for a lot of this stuff but some of them didn't come out of the 2.0 upgrade unscathed.

Ensuring no negative values getting set prevents the crash but doesn't fix the bug -- I will investigate why there could be a negative value in the first place. It shouldn't ever go negative since the system counts and keeps track of how many equipment items of each type is equipped. Sounds like it must be something weird that happens when the armor is removed. Maybe it's triggering two events or something.

4 days ago
(updated 4 days ago)

LOL I just read your suggestion in more detail. Obvious ChatGPT solution. :P What equipment were you using when the crash happened? I can't replicate this error.

4 days ago

ahah yeahh i used chatgpt ahah its a good tool hahah

was using some other mod too. all items from this mod+ some other.

let me see

4 days ago

some item from extended vanilla equipment and smg equipment.

and vanilla battery, solar and jetpack from earendal

3 days ago

I pretty much guarantee it's jetpack. Earendel's code is abstracted pretty strongly so I can't tell what's going on yet. My code keeps track of the things that are equipped and then finds the difference after a change and moves the bonuses by just that amount. Earendel is setting and overriding the the bonuses in various places and there may be a race condition. Will be a while before I can fix this properly.

New response