The International Simutrans Forum

Development => Scripting Scenarios and AI => Topic started by: Yona-TYT on May 24, 2020, 05:54:26 PM

Title: Error using "find_object(mo_building)"
Post by: Yona-TYT on May 24, 2020, 05:54:26 PM

In some cases the buildings / constructions are not not achieved, I suppose it may be due to the abrupt terrain.

Here is the savegame and a test script ->  https://www.mediafire.com/file/sl7nxgp3wsc2awv/test-yona.zip/file

    local c_city = coord(70,409)
    local build = square_x(c_city.x,c_city.y).get_ground_tile().find_object(mo_building)
   

    if (build) gui.add_message("Is correct : "+build+"")

    else gui.add_message("Is null : "+build+"")
Title: Re: Error using "find_object(mo_building)"
Post by: Andarix on May 24, 2020, 06:16:59 PM

local tile = square_x(70,409)
local c_city = tile_x(tile_x, tile.y, tile.get_ground_tile())
local build = c_city.find_object(mo_building)
Title: Re: Error using "find_object(mo_building)"
Post by: Dwachs on May 24, 2020, 06:25:30 PM
What exactly is the bug?
Title: Re: Error using "find_object(mo_building)"
Post by: Yona-TYT on May 24, 2020, 08:20:40 PM
Upgrade:

I made a comparison with a monument, using the same methods:
    // City Wakefield Pos ---------------------------------------------------------------
    local c1_city = coord(70,409)
    local build1 = square_x(c1_city.x,c1_city.y).get_ground_tile().find_object(mo_building)

    if (build1) {gui.add_message("City Wakefield Is correct : "+build1+"")}
    else {gui.add_message("City Wakefield Is null : "+build1+"")}

    // Monument Pos----------------------------------------------------------------------
    local c2_city = coord(95,33) 
    local build2 = square_x(c2_city.x,c2_city.y).get_ground_tile().find_object(mo_building)

    if (build2) {gui.add_message("Monument Pos Is correct : "+build2+"")}
    else {gui.add_message("Monument Pos Is null : "+build2+"")}


The displayed result is as follows:
Monument Pos Is correct : (instance : 0x0x555962a4f750)
City Wakefield Is null : (null : 0x(nil))


I suspect it is a problem that only affects multi-tile buildings.
  Correct, it only seems to affect the town hall





Quote from: Andarix on May 24, 2020, 06:16:59 PM local tile = square_x(70,409) local c_city = tile_x(tile_x, tile.y, tile.get_ground_tile()) local build = c_city.find_object(mo_building)
This is basically the same, I have tried and it is indeed the same result




Just out of curiosity, why do the instances change between two values? In this example "0x0x555961e625c0" and "0x0x555961e625c0"
Shouldn't I keep only one?.Monument Pos Is correct : (instance : 0x0x555961e625c0)
Monument Pos Is correct : (instance : 0x0x5559629bd5b0)
Monument Pos Is correct : (instance : 0x0x555961e625c0)
Monument Pos Is correct : (instance : 0x0x5559629bd5b0)
Monument Pos Is correct : (instance : 0x0x555961e625c0)
Monument Pos Is correct : (instance : 0x0x5559629bd5b0)
Monument Pos Is correct : (instance : 0x0x555961e625c0)
Monument Pos Is correct : (instance : 0x0x5559629bd5b0)
Monument Pos Is correct : (instance : 0x0x555961e625c0)
Monument Pos Is correct : (instance : 0x0x5559629bd5b0)
Monument Pos Is correct : (instance : 0x0x555961e625c0)
Monument Pos Is correct : (instance : 0x0x5559629bd5b0)
Monument Pos Is correct : (instance : 0x0x555961e625c0)
Monument Pos Is correct : (instance : 0x0x5559629bd5b0)
Monument Pos Is correct : (instance : 0x0x555961e625c0)
Monument Pos Is correct : (instance : 0x0x5559629bd5b0)
Monument Pos Is correct : (instance : 0x0x555961e625c0)
Monument Pos Is correct : (instance : 0x0x5559629bd5b0)
Monument Pos Is correct : (instance : 0x0x555961e625c0)
Monument Pos Is correct : (instance : 0x0x5559629bd5b0)
Monument Pos Is correct : (instance : 0x0x555961e625c0)
Monument Pos Is correct : (instance : 0x0x5559629bd5b0)
Title: Re: Error using "find_object(mo_building)"
Post by: Dwachs on May 25, 2020, 06:07:53 AM
I do not know, what you are doing. But at (70,409) there is no townhall in the savegame. The townhal is at (72,409) -(73,410).

Please upload a minimal example showing the wrong behaviour. I do not want to edit a randomly given script to produce an error message.
Title: Re: Error using "find_object(mo_building)"
Post by: Yona-TYT on May 25, 2020, 12:45:19 PM
But  (70,409) is that the location that the window shows me?..... Shouldn't the title bar show the position (72,409)?.
Title: Re: Error using "find_object(mo_building)"
Post by: Dwachs on May 25, 2020, 01:30:11 PM
It shows the centre of the rectangle formed by the city borders.