The International Simutrans Forum

Development => Scripting Scenarios and AI => Topic started by: Yona-TYT on September 12, 2016, 11:35:25 AM

Title: Error using: command x (tool_build_way)
Post by: Yona-TYT on September 12, 2016, 11:35:25 AM

Try loading the attached scenario.


Loading BDF font 'cyr.bdf'
Reading city configuration ...
Reading speedbonus configuration ...
Reading menu configuration ...
Reading object data from pak/...
Loaded /home/yona/Descargas/simutrans/pak/sound/horse.wav to sample 19.
Loaded /home/yona/Descargas/simutrans/pak/sound/crossing.wav to sample 20.
Reading menu configuration ...
Midi disabled ...
Calculating textures ...done
Creating cities ...
Creating cities: 1
Creating factories ...
Distributing 1 tourist attractions ...
Preparing startup ...
Loading BDF font 'cyr.bdf'
Show banner ...
Running world, pause=0, fast forward=0 ...
script engine started.
World destroyed.
script engine started.
sim: boden/wege/weg.cc:98: static weg_t* weg_t::alloc(waytype_t): Assertion `0' failed.


Thread 1 "sim" received signal SIGABRT, Aborted.
0xb7fdabc8 in __kernel_vsyscall ()
(gdb) where
#0  0xb7fdabc8 in __kernel_vsyscall ()
#1  0xb7b585c9 in __GI_raise (sig=6) at ../sysdeps/unix/sysv/linux/raise.c:54
#2  0xb7b59ca7 in __GI_abort () at abort.c:89
#3  0xb7b50e17 in __assert_fail_base (
    fmt=0xb7ca365c "%s%s%s:%u: %s%sAssertion `%s' failed.\n%n",
    assertion=0x836a3e2 "0", file=0x836a3d0 "boden/wege/weg.cc", line=98,
    function=0x836a5a0 <weg_t::alloc(waytype_t)::__PRETTY_FUNCTION__> "static weg_t* weg_t::alloc(waytype_t)") at assert.c:92
#4  0xb7b50e9b in __GI___assert_fail (assertion=0x836a3e2 "0",
    file=0x836a3d0 "boden/wege/weg.cc", line=98,
    function=0x836a5a0 <weg_t::alloc(waytype_t)::__PRETTY_FUNCTION__> "static weg_t* weg_t::alloc(waytype_t)") at assert.c:101
#5  0x0809d6d3 in weg_t::alloc (wt=ignore_wt) at boden/wege/weg.cc:98
#6  0x0830cbfe in tool_build_way_t::get_besch (this=0x9a83620,
    timeline_year_month=23160, remember=false) at simtool.cc:2129
#7  0x0830d091 in tool_build_way_t::init (this=0x9a83620, player=0x89de210)
    at simtool.cc:2221
#8  0x081f4918 in script_api::param<script_api::call_tool_work>::push (vm=
    0x9a6cd20, v=...) at script/api/api_command.cc:195
#9  0x081f4701 in command_work (vm=0x9a6cd20) at script/api/api_command.cc:145
#10 0x0829c707 in SQVM::CallNative (this=0x9a6cd20, nclosure=0x9a94b10,
    nargs=5, newbase=9, retval=..., suspend=@0xbfffc72f: false)
    at squirrel/squirrel/sqvm.cc:1210
Title: Re: Error using: command x (tool_build_way)
Post by: Dwachs on September 12, 2016, 05:16:40 PM
The last argument of the work function must be the (internal) name of a way (see class way_desc_x, member function get_name)

local tool = command_x(tool_build_way)
local err = tool.work(player_x(1), square_x( coordx[j+2].x, coordx[j+2].y ).get_ground_tile(), square_x( coordx[j+2].x+6, coordx[j+2].y ).get_ground_tile(), PUT_NAME_OF_WAY_HERE)

Using class command_x puts you in undocumented land. I think I should invent some properly named functions to issue such commands. Now that somebody is using this.

For use of this class, see my AI script. The AI builds ways, stations, depots, and vehicles.
Title: Re: Error using: command x (tool_build_way)
Post by: Yona-TYT on September 13, 2016, 03:23:03 PM
Opens and immediately closes. ???



local tool = command_x(tool_build_way)
local err = tool.work(player_x(1), square_x( coordx[2].x, coordx[2].y ).get_ground_tile(), square_x( coordx[2].x+6, coordx[2].y ).get_ground_tile(),""+wt_road)




Title: Re: Error using: command x (tool_build_way)
Post by: Dwachs on September 13, 2016, 05:32:43 PM

""+wt_road

will not work. You will need the raw name (untranslated) of an existing way object, for example "cobblestone_road" in pak64.

Title: Re: Error using: command x (tool_build_way)
Post by: Yona-TYT on September 13, 2016, 05:44:36 PM
Still does not work.

local err = tool.work(player_x(1), square_x( coordx[2].x, coordx[2].y ).get_ground_tile(), square_x( coordx[2].x+6, coordx[2].y ).get_ground_tile(),"cobblestone_road")


If I put: ""+cobblestone_road, Index does exist.
Title: Re: Error using: command x (tool_build_way)
Post by: Yona-TYT on September 14, 2016, 10:17:52 AM
My intention with this is to build the stations automatically.
Title: Re: Error using: command x (tool_build_way)
Post by: Dwachs on September 14, 2016, 07:15:43 PM
This code works for me

local t = command_x(tool_build_way)
local err = t.work(player_x(1), {x=20, y=40, z=4}, {x=20, y=41, z=4}, "cobblestone_road")

Can't see what is wrong with your script.
Title: Re: Error using: command x (tool_build_way)
Post by: Yona-TYT on September 14, 2016, 09:41:11 PM

Doing some tests I found that "command_x(tool_build_way)" and "command_x(tool_set_climate)" are interfere with each other.


For example, if run first "tool_set_climate" I can no longer use "tool_build_way".


Is this a bug ?. ???
Title: Re: Error using: command x (tool_build_way)
Post by: Dwachs on September 15, 2016, 06:07:42 AM
Difficult to say without script code. Could you please post the script and debug output (-debug 2)
Title: Re: Error using: command x (tool_build_way)
Post by: Yona-TYT on September 15, 2016, 02:23:44 PM
Quote from: Dwachs on September 15, 2016, 06:07:42 AM
Difficult to say without script code. Could you please post the script and debug output (-debug 2)
I think it was a error from the savegame, I was solved with a new map.

Now the problem is it locks when the "command_x (tool_set_climate)" and then "command_x (tool_build_way)" is used.
Quote from: Yona-TYT on September 14, 2016, 09:41:11 PM
Doing some tests I found that "command_x(tool_build_way)" and "command_x(tool_set_climate)" are interfere with each other.
For example, if run first "tool_set_climate" I can no longer use "tool_build_way".
Is this a bug ?. ???

To replicate load the savegame and then use the remove tool as public service.

If you remove the line "94-99" in "regions.nut" this does not happen.

if (opt == 0)
{                 
   local tool = command_x(tool_build_way)         
   local err = tool.work(player_x(1), square_x( coord_st1[j+2].x, coord_st1[j+2].y ).get_ground_tile(), square_x( coord_st1[j+2].x+6, coord_st1[j+2].y ).get_ground_tile(),"cobblestone_road")
           
}


Scenario: regions3-256x256.zip (http://www.mediafire.com/download/9ms074vvjdisvm7/regions3-256x256.zip)
Savegame: Savegame.sve (http://www.mediafire.com/download/mkd8vjv35deglj2/Savegame.sve)

(https://www.mediafire.com/convkey/6270/68fmter8utt3h8g6g.jpg)
               
Title: Re: Error using: command x (tool_build_way)
Post by: Yona-TYT on September 16, 2016, 08:29:30 AM
I think it's a problem with the function "is_work_allowed_here", I guess some restrictions still remains undocumented. ???
Title: Re: Error using: command x (tool_build_way)
Post by: Dwachs on September 16, 2016, 06:25:56 PM
I cannot see anything wrong with the script. What should I do to trigger an error?