Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Does AGK Functions work more with floats than integers?

Author
Message
Tobias_Ripper
11
Years of Service
User Offline
Joined: 24th Mar 2013
Location: REPCONN inc.
Posted: 23rd Nov 2017 02:37 Edited at: 23rd Nov 2017 05:53
I'm slowly getting a hang of the C++ in visual studio while converting the code from Tier 1 to Tier 2.
I've been using Visual Studio 2015 for all of 2 days now. This is an absolutely new coding environment for me so these errors are simply foreign. I have no idea where I should start with figuring them out.

One thing I noticed is that I get a lot of :
Quote: "
conversion from 'double' to 'float', possible loss of data
"


So I discovered that if I need to set a float variable to actually be a float value, I need to do:

Quote: "
float speed = 0.5f;
"


So that "f" is what sets it as a float as far as I can understand and if I have a function:
Quote: "
SetObjectScale(enter, 0.3, 0.3, 0.3);
"


in C++ it needs to be


So What if I have variables for values like:


Do I need to make sure that when I'm setting those variables, I do
Quote: "
value_one = 2.5f;
value_two = 7.2f;
value_three = 4.9f; "

to prevent visual studio from complaining about it?
From what I can see, a good number of functions complain about variable conversion.

Most surprisingly is the fact that functions like
Quote: "
agk::GetRawMouseX();
"

are complaining about converting a float value (one getting returned from the function) to an integer value (variable that stores that function) How can a mouse be half a pixel across the screen?
Eisenstadt Studio: Eisenstadtstudio.com
Composers Page: Milesthatch.net
Mobiius
Valued Member
21
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 23rd Nov 2017 08:54 Edited at: 23rd Nov 2017 08:54
Your notes are correct. By default, Visual Studio will default to the larger datatype. So a value of 0.3 would be classed as a double, whilst 0.3f is a float. This is for safety, it's better to assume a larger data type and round down, than to assume a smaller type and lose precision when expanding.

As for a mouse being half a pixel across, it's to accommodate for the virtual resolution. If a screen is 1024 pixels across with a virtual width of 100, if the mouse is at screen X 1000, then its position in the virtual X is 97.66.
Click here for VR Legend of Zelda stuff

Login to post a reply

Server time is: 2024-04-19 23:01:00
Your offset time is: 2024-04-19 23:01:00