![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | Surtarso |
This is my function that detects what loot I got and add the corresponding bonus. When I have lots of loot on screen, they get the “@num” that screws my function, so I made this workaround to remove the @ and the numbers from the name, and it works:
func _picked_item(name,value):
name = name.replace("@","")
var replace_array:Array = ["0","1","2","3","4","5","6","7","8","9"]
for i in replace_array.size():
name = name.replace(i,"")
prints------> name
But for some reason, if I add the “@” to the array (and remove
name = name.replace("@","")
from the start), it no longer removes the “@” from names… It makes no sense to me
func _picked_item(name,value):
var replace_array:Array = ["@","0","1","2","3","4","5","6","7","8","9"]
for i in replace_array.size():
name = name.replace(i,"")
prints----> @name@
I know it’s not a big deal, I just really want to understand why the “@” inside the array wont remove it, but will outside the array normally…
the rest of the function goes like:
if name == "ShieldDrop": immunity_duration += value if immunity_duration < 0.75 else 0.0
if name == "HealthDrop": PlayerData.health += value if PlayerData.health < PlayerData.MAX_HEALTH else 0
if name == "SpeedDrop": shoot_rate -= value if shoot_rate > 0.2 else 0.0
if name == "DoubleShotDrop": bullet_type = value
if name == "TripleShotDrop": bullet_type = value