Hello :) The title may sound weird but this is how I came to this question... In my code, I need to know the width of a sprite's texture, then divide it by 32 to know how many frames can be extracted from it (as a part of a strip). The only problem is that get_texture().get_width() returns a constant so if I divide the result by 32, I have an error message because I changed the value of this constant. Do you know a simple way to turn the initial width into a variable ? Thanks a lot.

if I divide the result by 32, I have an error message because I changed the value of this constant.

Post the code and the exact error message.

You create a variable like this:

var width = # whatever

As far as I know, the only way to get an error from using a constant is to use the assignment operators.

get_texture().get_width() /= 32

The answer is, don't do that. Assign it to a variable.

var x = get_texture().get_width() / 32

This is the code I intended to use first : hframes = get_texture().get_width()/32

The error message I get is this : Integer division, decimal part will be discarded

Any texture I use is a multiple of 32 pixels in width.

That is a standard warning, not an error, and not related to const or var. While width may be a multiple of 32, the compiler cannot know that. It could be any valid number, as far as it's concerned. In your case, it's not a problem, if you're sure the number is always an even multiple of 32. I think you can suppress the warning, if it bothers you.

#warning-ignore:integer_division
hframes = get_texture().get_width()/32

Thanks for your advice and you're right, it was just a warning message ;)

7 months later