The International Simutrans Forum

Development => Scripting Scenarios and AI => Topic started by: Yona-TYT on May 31, 2020, 11:59:05 AM

Title: Edit line Lines function
Post by: Yona-TYT on May 31, 2020, 11:59:05 AM


[line_x.update_line(player_x schedule_x)]
I want to fix a little problem with the lines in the tutorial scenario.
Title: Re: Update Lines function
Post by: Dwachs on June 04, 2020, 08:10:51 AM
?? What should this function do, and why do you want such a function?
Title: Re: Update Lines function
Post by: Yona-TYT on June 04, 2020, 03:00:17 PM
Sorry for not explaining well, I mean the "edit line" button. :-[

It is the same as the "Edit line" button in the lines window.

In some cases, I need to change the minimum load or wait time on an already existing line. I think the only way to do that correctly is to use the "Edit line" button in the lines window.

If one tries to change the minimum load or the waiting time on an existing line for a vehicle, if you use the copy button, the new vehicles do not receive the change in the minimum load or time, they keep the values that were used when creating the line.
Title: Re: Edit line Lines function
Post by: Dwachs on June 08, 2020, 12:26:13 PM
There is line_x::change_schedule. What else do you want?
Title: Re: Edit line Lines function
Post by: Yona-TYT on June 08, 2020, 04:09:25 PM
Certainly yes, I had already tried to use it in the past, sorry I forgot about that. :o
Title: Re: Edit line Lines function
Post by: Yona-TYT on June 09, 2020, 06:10:49 PM
Quote from: Dwachs on June 08, 2020, 12:26:13 PMThere is line_x::change_schedule. What else do you want?
Using "line.change_schedule(play, schedule)" in the "is_schedule_allowed (pl, schedule)" function causes error.

This is what I am trying to do:You must create a line with the same name "Test 1".
function is_schedule_allowed(pl, schedule)
{
    local line_name = "Test 1"
    local play =  player_x(pl)
    local list = play.get_line_list()     
    foreach(line in list) {
        if (line.get_name() == line_name && line.get_waytype() == wt_road){

            line.change_schedule(play, schedule)
        }
    }
    return null
}


Is it possible to make this work?.
Title: Re: Edit line Lines function
Post by: Dwachs on June 10, 2020, 06:28:39 PM
Why do you want to create a line within this function? What is the error?
Title: Re: Edit line Lines function
Post by: Yona-TYT on June 10, 2020, 07:37:47 PM
What I want to do is update the line with the correct "schedule", so when copying the convoy the minimum load and waiting time values should be correct for the resulting convoys.
I try to solve this: https://forum.simutrans.com/index.php/topic,19987.0.html

The error is shown in the attached image.
Title: Re: Edit line Lines function
Post by: Dwachs on June 11, 2020, 12:28:19 PM
Could you upload a savegame, script, and instructions to reproduce this? This looks like some bug.
Title: Re: Edit line Lines function
Post by: Yona-TYT on June 11, 2020, 02:08:24 PM
Savegame -> https://www.mediafire.com/file/utfbrccczf1pvhr/test_line_err.sve/file
To replicate open the "schedule" window of the convoy stored in the garage, at the moment of closing you will notice the error.

You can use this minama test script (there is nothing else I can infer).
Title: Re: Edit line Lines function
Post by: Dwachs on June 12, 2020, 06:19:07 AM
thanks, will look into this. It might tak a while.
Title: Re: Edit line Lines function
Post by: Yona-TYT on June 18, 2020, 01:11:24 PM
I think because "line.change schedule(play, schedule)" calls the same function "is_schedule_allowed (pl, schedule)" this must be creating some conflict?.  ???
Title: Re: Edit line Lines function
Post by: Yona-TYT on June 19, 2020, 03:41:11 AM
A possible solution for me will be to add a new function that is called from the [copy convoy] button.

Something like "is_convoy_copy_allowed (pl, convoy, depot)" from that function there should be no problem running "line.change schedule (play, schedule)".  8)
Title: Re: Edit line Lines function
Post by: Dwachs on June 19, 2020, 06:15:13 AM
This is a stack overflow due to all these recursive calls. The error message is misleading. I will disable the call to is_schedule_allowed if change_line is called by scenario script.

Edit: done with r9147
Title: Re: Edit line Lines function
Post by: Yona-TYT on June 19, 2020, 12:01:38 PM
seems reasonable to me :)
Title: Re: Edit line Lines function
Post by: Yona-TYT on June 19, 2020, 10:32:58 PM
Quote from: Dwachs on June 19, 2020, 06:15:13 AMThis is a stack overflow due to all these recursive calls. The error message is misleading. I will disable the call to is_schedule_allowed if change_line is called by scenario script. Edit: done with r9147
I have applied your patch "https://github.com/aburch/simutrans/commit/732372dd5a1c85ba81fec89a03ad3d11b1ae235f (https://github.com/aburch/simutrans/commit/732372dd5a1c85ba81fec89a03ad3d11b1ae235f)", but the problem still persists.

In fact put a counter and it runs about 50 times before giving the error.
(https://www.mediafire.com/convkey/a491/c0rdwuvpkawffh86g.jpg)
Title: Re: Edit line Lines function
Post by: Dwachs on June 20, 2020, 08:20:53 AM
missed one, should work with r9150
Title: Re: Edit line Lines function
Post by: Yona-TYT on June 20, 2020, 10:10:15 AM
Thank you very much, now it works and I have solved the problem .    ;D