![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | Zach1812 |
Hello,
I’m trying to do a bit of math inside one of my functions for my game. I have a TextureRect that expands when a variable is taken and multiplied by the number of pixels in the image. I’ve been following along with HeartBeast and his ARPG tutorials (This one being P18). Since I’ve changed much of the code he posted, I don’t feel right asking him about this one issue. Here’s what I want.
func set_xp(value):
xp = clamp(value, 0, xp_next_level)
var gained_xp = round((xp/xp_next_level)* 10)
if xp_bar != null:
xp_bar.rect_size.x = gained_xp * 3
What is supposed to happen is when the player kills a Snake, they receive 5 XP out of 10 XP. (5 XP for the kill, 10 XP to next Level). That would raise the xp_bar up to 50% completion.
When I do a print function inside the function, the xp and xp_next_level come out correct (ie 5 and 10), but the gained_xp does not. It always returns a 0, no matter how much xp I give the player or what kind of math function I try.
I’ve even tried making xp and xp_next level integers within the math function but that doesn’t solve the issue either.
Any help is greatly appreciated!