The International Simutrans Forum

Development => Scripting Scenarios and AI => Topic started by: Yona-TYT on May 26, 2017, 03:51:05 AM

Title: "Promote to line" button is causing problems.
Post by: Yona-TYT on May 26, 2017, 03:51:05 AM

When this button is pressed for the first time, the function: "is_schedule_allowed (pl, schedule)" does not work.

(http://files.simutrans.com/index.php/apps/files_sharing/ajax/publicpreview.php?x=1440&y=372&a=true&file=line%2520error.png&t=cygIWt7qhpnq0UC&scalingup=0)


I must wait for this to be able to launch a new version of the tutorial.  ;)
Title: Re: "Promote to line" button is causing problems.
Post by: Dwachs on May 26, 2017, 06:23:50 AM
Is_schedule_allowed is only called when the schedule of a line or a line-less convoy is changed.
Title: Re: "Promote to line" button is causing problems.
Post by: Yona-TYT on May 27, 2017, 01:11:54 AM
Quote from: Dwachs on May 26, 2017, 06:23:50 AM
Is_schedule_allowed is only called when the schedule of a line or a line-less convoy is changed.
And why not work here too?  ???
Title: Re: "Promote to line" button is causing problems.
Post by: Dwachs on May 27, 2017, 03:31:23 PM
The schedule should have been checked before already.
Title: Re: "Promote to line" button is causing problems.
Post by: Yona-TYT on July 18, 2017, 01:34:07 AM
I'd really like to solve this.  :-[

Maybe if you implement a function that allows you to check the lines.  ???
Example: is_line_allowed (pl, line)

This can be called each time the "Promote to line" button is pressed.
Title: Re: "Promote to line" button is causing problems.
Post by: prissi on July 18, 2017, 02:21:52 AM
Why, the line is valid for that kind of transport?
Title: Re: "Promote to line" button is causing problems.
Post by: Yona-TYT on July 18, 2017, 01:19:48 PM
Quote from: prissi on July 18, 2017, 02:21:52 AM
Why, the line is valid for that kind of transport?

Actually I only need to check the Schedule before creating the line, with the class line_x you can do that and much more.  ;)
Title: Re: "Promote to line" button is causing problems.
Post by: An_dz on July 18, 2017, 06:02:44 PM
The schedule was already created, so the function has already fired before promoting to line. If you want to know when a schedule was promoted to line then I guess it would make more sense to have another event, like on_schedule_to_line.
Title: Re: "Promote to line" button is causing problems.
Post by: Yona-TYT on July 21, 2017, 12:05:12 AM
Maybe a new topic?.  ???
Title: Re: "Promote to line" button is causing problems.
Post by: Dwachs on July 22, 2017, 01:57:49 PM
see r8270: promote to line will call is_schledule_allowed.
Title: Re: "Promote to line" button is causing problems.
Post by: Yona-TYT on July 22, 2017, 04:38:19 PM
Quote from: Dwachs on July 22, 2017, 01:57:49 PM
see r8270: promote to line will call is_schledule_allowed.

Thank you, now I can solve a problem that did not allow me to sleep peacefully.  ;D


Something of music here:  ;)
Title: Re: "Promote to line" button is causing problems.
Post by: Yona-TYT on July 23, 2017, 12:21:05 AM
@Dwachs

Two important details:
1. If the schedule is not correct, the line should not be allowed to be created.
2. If the schedule is not correct, the list should be cleared.
Title: Re: "Promote to line" button is causing problems.
Post by: Yona-TYT on July 24, 2017, 10:43:13 AM
This is much better for me:  ;)

simutool.cc (line 6856)

                if (!scenario_check_schedule(welt, player, line->get_schedule(), can_use_gui())) {
                    player->simlinemgmt.delete_line(line);
                    break;
                }



But I still have a problem, I need to differentiate between the call when you press the "Promote to line" button and when the "Schedule" window is closed .. is it possible in any way ?.  ???
Title: Re: "Promote to line" button is causing problems.
Post by: Dwachs on July 24, 2017, 12:01:29 PM
Quote from: Yona-TYT on July 24, 2017, 10:43:13 AM
But I still have a problem, I need to differentiate between the call when you press the "Promote to line" button and when the "Schedule" window is closed .. is it possible in any way ?.  ???
no, this is not possible.
Title: Re: "Promote to line" button is causing problems.
Post by: Yona-TYT on July 24, 2017, 12:07:02 PM
Quote from: Dwachs on July 24, 2017, 12:01:29 PM
no, this is not possible.

And clean the schedule list ?.
Title: Re: "Promote to line" button is causing problems.
Post by: Yona-TYT on July 25, 2017, 11:57:33 PM
@Dwachs

Quote from: Yona-TYT on July 24, 2017, 10:43:13 AM
This is much better for me:  ;)

simutool.cc (line 6856)

                if (!scenario_check_schedule(welt, player, line->get_schedule(), can_use_gui())) {
                    player->simlinemgmt.delete_line(line);
                    break;
                }


I'm afraid there's a problem with this.  :-[

It seems that when I create a line "pl.create_line (wt)" it is deleted immediately.

                    pl.create_line(wt)
                    // find the line - it is a line without schedule and convoys
                    local list = pl.get_line_list()
                    local c_line = null
                    foreach(line in list) {
                        if (line.get_waytype() == wt  &&  line.get_schedule().entries.len()==0) {
                            // right type, no schedule -> take this.
                            c_line = line
                            break
                        }
                    }
                    c_line.change_schedule(pl, sched)
                    convoy[0].set_line(pl, c_line)
                    depot.start_convoy(pl, convoy[0])
                    this.step_nr(5)


(http://files.simutrans.com/index.php/apps/files_sharing/ajax/publicpreview.php?x=1440&y=372&a=true&file=sche_error.png&t=sJLQ1B1malVVwid&scalingup=0)

Edit.
Luckily find a simple solution using a flag before using "pl.create_line(wt)". ;)

                    lin_flag = true
                    pl.create_line(wt)


function is_schedule_allowed(pl, schedule)
{
    if (lin_flag){
        lin_flag = false
        return null
    }
}


Title: Re: "Promote to line" button is causing problems.
Post by: Dwachs on July 26, 2017, 07:30:27 AM
Imho. this is a problem of your script: It should accept empty schedules.
Title: Re: "Promote to line" button is causing problems.
Post by: Yona-TYT on July 28, 2017, 03:51:39 AM
@Dwachs
I am very happy to see this problem solved. thank you very much!.  ;D

You can try the script here:
Script -> tutorial-test-lines.zip (http://files.simutrans.com/index.php/s/iBuVKwHIv8qPTnF)
Savegame -> test-tuto.sve (http://files.simutrans.com/index.php/s/jISL5bZpnxInaCl)
(http://files.simutrans.com/index.php/apps/files_sharing/ajax/publicpreview.php?x=1440&y=372&a=true&file=tutorial-v6.2.png&t=VCFb06cXPs0OZ94&scalingup=0)