-
-
Notifications
You must be signed in to change notification settings - Fork 18.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Assigning variable type corrupts getter #91689
Comments
Can't test right now but it might be important: The syntax is
|
MRP simplified: @tool
extends EditorScript
var int_prop: int: get = float_returner # Warning: Line 4 (NARROWING_CONVERSION): Narrowing conversion (float is converted to int and loses precision).
func float_returner():
return 1.0
func _run() -> void:
var not_really_an_int: int = int_prop
print(type_string(typeof(not_really_an_int)))
print(not_really_an_int)
print(not_really_an_int + 1)
print(not_really_an_int + 1.0) Output:
Confirmed in: |
@huwpascoe While when taking damage it seems to do currentHealth - damage (40 - 10) fine, but the regen math (var d) is still corrupted and results in 1. Code snippet of debug breakpoint: var currentHealth : int = realMaxHealth :
set(val): # val is what current health should be set to after any damage/heal math has been done and is then clamped
var a = currentHealth
var b = realRegenValueHealth
var c = a + b
var d = currentHealth + realRegenValueHealth # still the only one corrupted
var e = realMaxHealth
currentHealth = clampi(val, 0, realMaxHealth) # even did clampi for good measure, didn't help |
Made some progress on this issue: For the following code: @tool
extends EditorScript
var int_prop: int: get = float_returner # Warning: Line 4 (NARROWING_CONVERSION):
func float_returner():
return 1.0
func _run() -> void:
var not_really_an_int: int = int_prop
print(not_really_an_int + 1.0) the gdscript_vm runs:
why is the VM using assign and not assign_typed_builtin?
why is the type of int_prop set to INT?
why is the VM using assign and not assign_typed_builtin? (part 2)
why is the use_conversion_assign flat not set?
How I think we could fix this:
|
Tested versions
Reproducible in v4.2.1.stable.mono.official [b09f793]
System information
Godot v4.2.1.stable.mono - Windows 10.0.19045 - Vulkan (Forward+) - dedicated AMD Radeon RX 6750 XT (Advanced Micro Devices, Inc.; 31.0.24027.1012) - AMD Ryzen 7 2700X Eight-Core Processor (16 Threads)
Issue description
Setting type of variables that keep track of current Health, Energy and Shield impacts getters of other variables associated with each tracker.
Getting one variable works as intended, but getting at least two results in corruption.
Issue happens outside of setter as well.
Example code shows Health variables and their setters and getters and how they operate together.
Example videos:
Taking Damage
Gaining Shield
Regening Health
![regeningHealth](https://private-user-images.githubusercontent.com/37415138/328715699-e06b55f4-9a7b-42ac-bb5c-f1bd6240c001.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTgwNDgyNjQsIm5iZiI6MTcxODA0Nzk2NCwicGF0aCI6Ii8zNzQxNTEzOC8zMjg3MTU2OTktZTA2YjU1ZjQtOWE3Yi00MmFjLWJiNWMtZjFiZDYyNDBjMDAxLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA2MTAlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNjEwVDE5MzI0NFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWY5NzZmYjU4ZTNhYThkNDI5ZTIwNTQwMTAzYTZiMmU0MzkwNGVjNGU1ZDFjNjRkMjZkN2QwMGQ5NjNkZDk3YzYmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.QAuCqYmKOyD90wpyH-ygSpnyTkJfBtTV-6i3kaOAzSo)
![takingDamage](https://private-user-images.githubusercontent.com/37415138/328715704-f2625214-e5d2-4373-b644-a815378951d6.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTgwNDgyNjQsIm5iZiI6MTcxODA0Nzk2NCwicGF0aCI6Ii8zNzQxNTEzOC8zMjg3MTU3MDQtZjI2MjUyMTQtZTVkMi00MzczLWI2NDQtYTgxNTM3ODk1MWQ2LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA2MTAlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNjEwVDE5MzI0NFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWY4MzU3MjI3NTc0M2RmN2U4MjdmNzVmN2VkNTUyMzMyMzFhMWNhYmRkZDFkMzY0NTAzNzhiM2JmNGIxM2Q2ZWMmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.IGDXo9C2_PKkVMbMhSR0cjG4AP8yo-ETeXuiB646N_4)
Taking Damage
Steps to reproduce
Wait for either the regen function to be called or walk into an attack hitbox to see the Health values corrupting
Walk into circle area to see Shield values corrupting
Wait for energy regen timer to see its values corrupting
*edit: Press ENTER when loading into main scene to load the debug scene
All necessary code is in res://scenes/characters/baseChara/baseChara.gd
Minimal reproduction project (MRP)
Pruned project I was working on when I discovered this: CorruptionExample.zip
The text was updated successfully, but these errors were encountered: