When storing time.time() in a game property, the game property doesn't return the same time #41490

Closed
opened 2014-08-19 11:21:42 +02:00 by Roderick Gadellaa · 13 comments

System Information
Windows 7 x64, Intel 3000 graphics

Blender Version
Broken: 2.70a f93bc76

Short description of error
In the game engine, when setting a game property (type float) of an object to time.time() and then printing it, it returns not the same value as you have set.

Exact steps for others to reproduce the error

Set Blender in game engine mode
Create an object and assign it a game property named "thetime", type float
Create a sensor (always or keyboard) and a controller (python), attach them to eachother

Python code:

thetime = time.time()
print(thetime)

prints something like 1440000.1348

obj["thetime"] = thetime
print(obj["thetime"])

prints something like 1440023.0

It looks like the object (which is basically C++ code?) is using doubles while python can only handle floats?

It does work when I convert the time to int (and also set the game property to type float)

**System Information** Windows 7 x64, Intel 3000 graphics **Blender Version** Broken: 2.70a f93bc76 **Short description of error** In the game engine, when setting a game property (type float) of an object to time.time() and then printing it, it returns not the same value as you have set. **Exact steps for others to reproduce the error** Set Blender in game engine mode Create an object and assign it a game property named "thetime", type float Create a sensor (always or keyboard) and a controller (python), attach them to eachother Python code: thetime = time.time() print(thetime) > prints something like 1440000.1348 obj["thetime"] = thetime print(obj["thetime"]) > prints something like 1440023.0 It looks like the object (which is basically C++ code?) is using doubles while python can only handle floats? It does work when I convert the time to int (and also set the game property to type float)

Changed status to: 'Open'

Changed status to: 'Open'

Added subscriber: @rejhgadellaa

Added subscriber: @rejhgadellaa

Added subscriber: @marcino15

Added subscriber: @marcino15

Float property has limit.
If you want store exact time, you must use string property obj["thetime"] = str(thetime)

Float property has limit. If you want store exact time, you must use string property obj["thetime"] = str(thetime)

@marcino15 thanx for the quick reply. I hope you mean this to be a workaround and not a fix? :)

Python uses doubles (doesn't have floats, I mixed that up in the OP) and since the game engine uses python for programming it would make sense if the game properties are of the same type as python's types since python does not have the option to choose (thus the C/C++ side should adept).

In other words: game property floats should be of type double.

@marcino15 thanx for the quick reply. I hope you mean this to be a workaround and not a fix? :) Python uses doubles (doesn't have floats, I mixed that up in the OP) and since the game engine uses python for programming it would make sense if the game properties are of the same type as python's types since python does not have the option to choose (thus the C/C++ side should adept). In other words: game property floats should be of type double.

This is correct work and not need to fix.

This is correct work and not need to fix.

Added subscriber: @sphaero

Added subscriber: @sphaero

I tend to disagree. I think storing time as a string is indeed a workaround. I'm not sure how the the game engine handles float game properties internally but if it creates a situation likes this because of float <> double conversion it would make sense to set the float game property as a double internally.

I tend to disagree. I think storing time as a string is indeed a workaround. I'm not sure how the the game engine handles float game properties internally but if it creates a situation likes this because of float <> double conversion it would make sense to set the float game property as a double internally.
Member

Added subscriber: @JorgeBernalMartinez

Added subscriber: @JorgeBernalMartinez
Member

it is not easy to increase the precision from float to double in property code. It would involve changes which affect to int and timer properties also (data variable used by int/float would have to pass to 8 bytes).

it is not easy to increase the precision from float to double in property code. It would involve changes which affect to int and timer properties also (data variable used by int/float would have to pass to 8 bytes).

Added subscriber: @panzergame

Added subscriber: @panzergame

Changed status from 'Open' to: 'Archived'

Changed status from 'Open' to: 'Archived'
Porteries Tristan self-assigned this 2015-05-18 22:46:12 +02:00

Hello, BGE convert as much as possible properties in his own type and in this case in float. So you have to set it in a tuple to keep the precision.

obj["time"] = (time.time(), )

I don't think that is a wrong behavior to contrain the user to use as minimum hight precision value.

Hello, BGE convert as much as possible properties in his own type and in this case in float. So you have to set it in a tuple to keep the precision. ``` obj["time"] = (time.time(), ) ``` I don't think that is a wrong behavior to contrain the user to use as minimum hight precision value.
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
5 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#41490
No description provided.