Godot: Different values with similar statements.

Created on 15 Apr 2019  路  2Comments  路  Source: godotengine/godot

Godot version:
3.1.

OS/device including version:
N/A

Issue description:
Consider these two lines of code, where damage is defined as an int var damage: int = 10.

damage *= 0.5
damage = damage * 0.5

The first statement returns 0. The second statement returns 5.

My understanding is that the two assignment statements should be the same. If they're not supposed to be, then this is not documented anywhere.

bug gdscript

Most helpful comment

PROGRAMMER TALK:

Probably because damage *= 0.5 is converting the 0.5 to an int which results in it becoming 0.
This is a bug in the type preference of the operation,

EDIT: Seems to only happen when the variable has the int type hint, which makes this behaviour expected, might still be worth doing the conversion to int only after all computation.

All 2 comments

PROGRAMMER TALK:

Probably because damage *= 0.5 is converting the 0.5 to an int which results in it becoming 0.
This is a bug in the type preference of the operation,

EDIT: Seems to only happen when the variable has the int type hint, which makes this behaviour expected, might still be worth doing the conversion to int only after all computation.

That makes me vaguely think of https://github.com/godotengine/godot/issues/26332#issuecomment-467684334, but perhaps slightly different case

Was this page helpful?
0 / 5 - 0 ratings

Related issues

testman42 picture testman42  路  3Comments

n-pigeon picture n-pigeon  路  3Comments

mefihl picture mefihl  路  3Comments

SleepProgger picture SleepProgger  路  3Comments

ducdetronquito picture ducdetronquito  路  3Comments