



Reply From: 
timothybrentwood 
Well first off float(target.scale.y)
will give you the number with the decimals (a floating point number opposed to an integer 1,2,3,…).
I’m confused as to exactly what you’re trying to accomplish with your code though? A scale factor is generally thought of as being multiplied by another value to ‘scale’ it up or down. For example: 100 with a scale factor of 2 would be 200 = 100 * 2. If you wanted a 25 percent increase in size your scale factor would be 1 (the original size) + 0.25 = 1.25 so something that is 25% bigger than 100 is: 100 * 1.25 = 125. Similarly if you wanted a 40% decrease in size you would do 1  0.40 = 0.6 so 100 * 0.6 = 60.
If you’re getting this value from a user and you want to guarantee it’s in an acceptable range use the clamp()
function:
var MINIMUM_SCALE_FACTOR = 1
var MAXIMUM_SCALE_FACTOR = 2.5
var user_input = 0.6
var scale_factor = clamp(user_input, MINIMUM_SCALE_FACTOR, MAXIMUM_SCALE_FACTOR)
# scale_factor is now 1 because 0.6 < MINIMUM_SCALE_FACTOR = 1
target.scale.y = scale_factor
If you’re giving the user an option to choose a scale factor between like 05, simply convert that scale factor before using it. This code will increase the scale by 25% for every digit over 0:
var user_input = 3
var scale_factor = 1 + (0.25 * user_input)
# scale_factor is now 1.75
target.scale.y = scale_factor
I tried float earlier and it had the same result, basically the code checks for the scaling variable to be 1, if so it runs the scaling boolean operation, the function is shared by multiple instances in the hud from child nodes of the parent script, their scripts send their sprite path as target to this function, which needs to record the initial scale value to match against the rest of the operation, which is, if the current scale is less than the original scale+1, add 0.25 until it is equal or more than, then switch direction until it is equal to the original scale, and exit the function/make the scaling variable 0 to stop the operation.
In the hud, potion sprites, herb sprites, and others, once clicked, run this operation as a visual UI queue.
In writing this I thought to myself, why not just send the known scale from the child script to this function as well, which would make life easier, but add to the computations a touch. In the end, I opted for making the scales whole numbers and int() works just fine, the issue I was having initially was that int() was rounding up/down or just deleting the decimals from the scale if it was like 3.6 or 2.22 etc, so the final scale was smaller than the original.
Using float made the current scale update along with the original scale, so the UI elements just grew into infinity.
Teethree89  20210429 02:23
I think Tweens are going to give you the effect you desire:
func scale_up_down(sprite):
var tween = Tween.new()
var original_scale = sprite.scale
var max_scale = 5
var duration = 1
tween.interpolate_property(sprite, "scale",
original_scale, Vector2(original_scale.x, max_scale), duration,
Tween.TRANS_LINEAR, Tween.EASE_IN_OUT)
tween.start()
yield(tween, "tween_completed")
tween.interpolate_property(sprite, "scale",
Vector2(original_scale.x, max_scale), original_scale, duration,
Tween.TRANS_LINEAR, Tween.EASE_IN_OUT)
tween.start()
The above code will increase the scale.y of an input sprite until it reaches max_scale over duration seconds then scale it back down to its original scale over the same duration.
timothybrentwood  20210429 19:41