GetBankBalance returning halved value?

Got a problem with OpenTTD? Find some help here.

Moderator: OpenTTD Developers

Post Reply
srschacher
Engineer
Engineer
Posts: 33
Joined: 15 May 2017 12:48

GetBankBalance returning halved value?

Post by srschacher » 20 Dec 2018 17:56

Hi.

I'm playing version 1.8.0.

I'm testing a modification to an existing game script, and I'm noticing that the function "GSCompany.GetBankBalance(...)" is returning 89600 when my company's balance on the income statement is 179,200.

Is this number purposely scaled in half in the main OpenTTD code? I don't see any reference to that in the API documentation.

Thanks,
Steve

User avatar
planetmaker
OpenTTD Developer
OpenTTD Developer
Posts: 9275
Joined: 07 Nov 2007 22:44
Location: Sol d

Re: GetBankBalance returning halved value?

Post by planetmaker » 20 Dec 2018 18:20

It depends on what currency you use to display your bank balance. The GS functions return the internal money value which is not scaled to any currency (which equals GBP)

https://wiki.openttd.org/Currency

srschacher
Engineer
Engineer
Posts: 33
Joined: 15 May 2017 12:48

Re: GetBankBalance returning halved value?

Post by srschacher » 20 Dec 2018 18:24

Thanks, I did not know that.

I'm using USD. I noticed that the update balance was also doubling the value that I used.

So what is the proper process for using the currency? If I want to assess a 10% penalty on the current balance, how do I know what the scaling factor is? Do I care, or do I just operate on the internal values?

Thanks,
Steve

User avatar
planetmaker
OpenTTD Developer
OpenTTD Developer
Posts: 9275
Joined: 07 Nov 2007 22:44
Location: Sol d

Re: GetBankBalance returning halved value?

Post by planetmaker » 20 Dec 2018 18:28

srschacher wrote:Thanks, I did not know that.

I'm using USD. I noticed that the update balance was also doubling the value that I used.

So what is the proper process for using the currency? If I want to assess a 10% penalty on the current balance, how do I know what the scaling factor is? Do I care, or do I just operate on the internal values?

Thanks,
Steve
A GS doesn't need to worry about currency of clients. 10% are the same 10% - irrespective of what units you use to display it. The conversion of the money to a currency displayed is done by the display routines of OpenTTD, outside any scripts or NewGRFs.

srschacher
Engineer
Engineer
Posts: 33
Joined: 15 May 2017 12:48

Re: GetBankBalance returning halved value?

Post by srschacher » 20 Dec 2018 18:32

Thanks.

What was confusing me was displaying the raw data in debug logs to trace the new code. I thought something was wrong, but now I understand what is going on.

Steve

User avatar
planetmaker
OpenTTD Developer
OpenTTD Developer
Posts: 9275
Joined: 07 Nov 2007 22:44
Location: Sol d

Re: GetBankBalance returning halved value?

Post by planetmaker » 20 Dec 2018 18:34

If you want to avoid this confusion there's two things you can do:

a) choose to play with British Pounds as currency
b) create your own currency which has a conversion factor of 1 wrt the internal money.

Post Reply

Return to “OpenTTD Problems”

Who is online

Users browsing this forum: No registered users and 4 guests