v1.3 local stock exchange wrong calculations, bug?

General discussion about X³: Farnham's Legacy.

Moderators: Moderators for English X Forum, Moderators for the X3:FL Forums

Post Reply
ArchmageFil
Posts: 7
Joined: Sat, 3. Feb 07, 20:31
xr

v1.3 local stock exchange wrong calculations, bug?

Post by ArchmageFil » Fri, 7. Jan 22, 08:43

Not sure if it should have been posted on the tech forum. But since the search did not produce anything, I would like to make sure that this is not my specific bug.

The game started at version 1.3. Having opened the first exchange, I noticed that it has most of the goods in abundance, but I do not use the exchange to trade, so I forgot this for a while. Now I have grown up to build factories and tried to use the local exchange to determine where and what is better to build. And it doesn't seem to be working properly.
Any bay for a resource not only goes to the demand column, but is also added to the exchange supply column in the amount as if it were full. For NPC dock - if there is something there, then first the empty volume is added to the demand, then the real quantity.
screenshot for illustration https://photos.app.goo.gl/8qhEUb2Ew6aPP67a7

For the player's stations, this also happens, with the exception of the trading station - nothing has changed during its construction.
This is how it looks when serial building of 3 computer factories.
before https://photos.app.goo.gl/npEfChSubVVAYT7z7
first https://photos.app.goo.gl/BFWQWfGbHL4z1c2V9
2nd https://photos.app.goo.gl/PEAQDU5EECyX3wsZ6
3d https://photos.app.goo.gl/uWJwsjLtRQ8eAWcz8
Each time stock grows by 5000 e.s. 3332 nostrop oil and 208 silicon.

If someone started the game with version 1.3, I would like to confirm whether everyone has issue. And maybe there are tips on how to fix this?

CheloDeAstora
Posts: 8
Joined: Fri, 24. Jun 22, 23:37
x3fl

Re: v1.3 local stock exchange wrong calculations, bug?

Post by CheloDeAstora » Fri, 19. May 23, 22:48

I have exactly the same bug. I play unmodded by the way in FL 1.3. I created this account just to report this.
What apparently happens is that the "Supply" column is calculated as what it should be (wares as product in the cluster of sectors + wares in player ships + flying wares, according to the script "plugin.st.ex.loc.ex.ProdResCheck") BUT for some reason (or bug) the "Demand" column value is also added to it. This way, the supply will NEVER be able to be less than the demand; therefore, no profitsss. The only exceptions to this are the wares with 0 in supply or demand which are only 1 or 2 if any at all in the cluster.

At the beginning no one cares about the Stock Exchange, but once you become billionare and want to have fun with large scale economy, the stock exchange shines by its concept. Unfortunately, I run out of time. If anyone is available please have a look at the suspicious scripts:
"plugin.st.ex.station.run"
"plugin.st.ex.loc.ex.ProdResCheck".

CheloDeAstora
Posts: 8
Joined: Fri, 24. Jun 22, 23:37
x3fl

Re: v1.3 local stock exchange wrong calculations, bug?

Post by CheloDeAstora » Mon, 22. May 23, 18:39

The error is in this file: plugin.st.ex.station.run
The script is perfectly written, the problem is that the underlying functions "merge tables" and also "clone table" are bugged.
There is no documentation about these functions but in theory "merge tables" should grab two tables and produce a third one ($table.wares). The problem is that "merge tables" is also afecting one of the inputs (&table.products), which is nutts! Obviously it is not the intended behaviour.

Code: Select all

sub.UpdateData:
$ware.data = [THIS]-> call script 'plugin.st.ex.loc.ex.ProdResCheck' : local.sectors.array=$array.sectors do.waits=[FALSE]
$table.products = array or table get $ware.data (0)
$table.resources = array or table get $ware.data (1)
$table.wares = merge tables, $table.products, $table.resources, null, null, null
$array.wares = sort table keys: table=$table.wares
gosub sub.UpdatePrices:
endsub
The first workaround would be this: produce a clone of $table.products and use it in "merge tables" instead of the original.

Code: Select all

sub.UpdateData:
$ware.data = [THIS]-> call script 'plugin.st.ex.loc.ex.ProdResCheck' : local.sectors.array=$array.sectors do.waits=[FALSE]
$table.products = array or table get $ware.data (0)
$table.resources = array or table get $ware.data (1)
$table.products.aux = clone table $table.products
$table.wares = merge tables, $table.products.aux, $table.resources, null, null, null
$array.wares = sort table keys: table=$table.wares
gosub sub.UpdatePrices:
endsub
This didn't work either. The reason: "clone table" function is also bugged!!! It is not copying the table and all its values. (Someone skipped the lesson on pointers).

"merge tables"
"clone table"

are not working. Please don't use these. These functions seem to be implemented for FL but obviously were not tested.

Finally, the workaround I used to produce a copy of the table so merge tables don't screw the original one was this:

Code: Select all

sub.UpdateData:
$ware.data = [THIS]-> call script 'plugin.st.ex.loc.ex.ProdResCheck' : local.sectors.array=$array.sectors do.waits=[FALSE]
$table.products = array or table get $ware.data (0)
$table.resources = array or table get $ware.data (1)

$table.products.key.array = get keys: table=$table.products
$table.products.data.array = get data: table=$table.products
$table.products.aux = convert arrays to table: keys=$table.products.key.array, data=$table.products.data.array

$table.wares = merge tables, $table.products.aux, $table.resources, null, null, null

$array.wares = sort table keys: table=$table.wares
gosub sub.UpdatePrices:
endsub
Bingo! The local stock exchange is working, the trend indicators green and red have started to move, the prices fluctuate as they should. It is time for profitsss my friends!

Before:
Image https://ibb.co/hKX10H7

After:
Image https://ibb.co/5hMJ2kB

Please, if anyone with more knowledge about how things work around here could actually write a fix using this and maybe include it in a future patch it would be great. Thank you.
Last edited by CheloDeAstora on Sun, 28. May 23, 00:07, edited 1 time in total.

aiedculedsul
Posts: 6
Joined: Tue, 23. May 23, 06:43

Re: v1.3 local stock exchange wrong calculations, bug?

Post by aiedculedsul » Sat, 27. May 23, 17:47

Hi CheloDeAstora,

Thanks for taking the time to figure this out. I´m not a programmer, how- with what program do I edit the plugin.st.ex.station.run file? Wordpad doesn't work unfortunately. Also, how do you restart the task in game?

thanks so much!

CheloDeAstora
Posts: 8
Joined: Fri, 24. Jun 22, 23:37
x3fl

Re: v1.3 local stock exchange wrong calculations, bug?

Post by CheloDeAstora » Sun, 28. May 23, 00:03

Hello aiedculedsul,
I normally use X-Studio viewtopic.php?f=201&t=439195 but it gave me problems while editing this script because of some "[Unrecognized parameter]". So I edited the file via the in-game script editor, it may be complicated though if you are not used.

Instead, I recommend you the following:
- Download the script file: https://drive.google.com/file/d/1HGuzLW ... jMZXl/view
- Paste it inside the script folder ( <GameFolder>\addon2\scripts ) and erase, rename or move the original file "plugin.st.ex.station.run.pck".
- Run the game and load your save normally.
- Enable the script by changing your pilot name to "Thereshallbewings" (this will mark you as "modified" of course)

After this, the stock exchange will start working.

The first movement in trend (these are the red and green arrows) will be all green because the prices rise from the minimum in which were stucked before. The trend will update every two or three minutes in SETA. From what I read from the script, the trading price of the ware is based on the last 10 trends, this is nice because it makes difficult any kind of immediate exploit (like the nividium one).
PD: It is not necessary to kickstart manually the task on the stock exchange, the script always had some code lines to restart it every time the script version is updated. I got that part bad in the previous post, I apologize.

aiedculedsul
Posts: 6
Joined: Tue, 23. May 23, 06:43

Re: v1.3 local stock exchange wrong calculations, bug?

Post by aiedculedsul » Sun, 28. May 23, 08:44

Trends are moving now and prices fluctuating. Thanks so much for taking the time to help me out!!

Cycrow
Moderator (Script&Mod)
Moderator (Script&Mod)
Posts: 22197
Joined: Sun, 14. Nov 04, 23:26
x4

Re: v1.3 local stock exchange wrong calculations, bug?

Post by Cycrow » Wed, 31. May 23, 18:04

This will be fixed in the next Unofficial Patch.

The issue with merge tables wasn't so simple. It does create a new table that is returned and doesn't change the the first table. However, due to how the script engine works, the data for the tables are actually stored as an array, which includes the datatype and the data itself. When merging the tables, if the data is an integer, it does an addition to merge the values, unfortunately it does this to the original array data not the value itself, which ends up changing the value of both.

The the commands do actually work correctly in most circumstances, its only when you are merging tables with duplicate keys where the data is an integer that it fails.

The clone table command is only a shallow copy, not a deep copy, this is also working correctly mostly, it only fails when used together with merge tables due to how it alters the data array

CheloDeAstora
Posts: 8
Joined: Fri, 24. Jun 22, 23:37
x3fl

Re: v1.3 local stock exchange wrong calculations, bug?

Post by CheloDeAstora » Thu, 1. Jun 23, 21:44

aiedculedsul wrote:
Sun, 28. May 23, 08:44
Trends are moving now and prices fluctuating. Thanks so much for taking the time to help me out!!
It is nothing man, you are welcome. Actually, thank you for testing it and replying.
Cycrow wrote:
Wed, 31. May 23, 18:04
This will be fixed in the next Unofficial Patch.
Yes! This would be great! That way more people would be able to have fun with the local stock exchange, thank you Cycrow!
Cycrow wrote:
Wed, 31. May 23, 18:04
The issue with merge tables wasn't so simple. It does create a new table that is returned and doesn't change the the first table. However, due to how the script engine works, the data for the tables are actually stored as an array, which includes the datatype and the data itself. When merging the tables, if the data is an integer, it does an addition to merge the values, unfortunately it does this to the original array data not the value itself, which ends up changing the value of both.

The the commands do actually work correctly in most circumstances, its only when you are merging tables with duplicate keys where the data is an integer that it fails.

The clone table command is only a shallow copy, not a deep copy, this is also working correctly mostly, it only fails when used together with merge tables due to how it alters the data array
I completely agree, it wasn't so simple specially because there was no apparent error in the script, it was unsettling, it was like solving a mistery where all the suspects (lines of code) seemed to be innocent but one of them killed the local stock exchange :lol: . Anyway, thank you for the clarifications, I learned a lot.

CheloDeAstora
Posts: 8
Joined: Fri, 24. Jun 22, 23:37
x3fl

Re: v1.3 local stock exchange wrong calculations, bug?

Post by CheloDeAstora » Tue, 6. Jun 23, 18:47

I can confirm that the issue has been fixed in the Unofficial Patch v1.3.9 https://forum.egosoft.com/viewtopic.ph ... &t=448962 .

Post Reply

Return to “X³: Farnham's Legacy”