The International Simutrans Forum

Development => Scripting Scenarios and AI => Topic started by: jameskuyper on December 29, 2022, 02:47:30 PM

Title: create_line
Post by: jameskuyper on December 29, 2022, 02:47:30 PM
Why doesn't player_x.create_line() return a line_x object? I suppose you can locate the newly created line by searching player_x get_line_list(). What's the best way to identify it in that list? Is it guaranteed to be the last one in the list?
Title: Re: create_line
Post by: Andarix on December 29, 2022, 03:08:30 PM
          pl.create_line(wt_rail)

          // find the line - it is a line without schedule and convoys
          local list = pl.get_line_list()
          foreach(line in list) {
            if (line.get_waytype() == wt_rail  &&  line.get_schedule().entries.len()==0) {
              // right type, no schedule -> take this.
              c_line = line
              break
            }
          }
Title: Re: create_line
Post by: Dwachs on December 30, 2022, 08:15:06 AM
This is not possible in the code. The code that actually creates the line does not know about the script, and does not know which script to call back with the new line. So we have to live with that inconvenience.

Of course such functionality can be implemented, but this would require some amount of work.
Title: Re: create_line
Post by: Yona-TYT on December 30, 2022, 01:08:08 PM
It would be great to improve this, I would love several scripts with this.  8)