News:

Simutrans Sites
Know our official sites. Find tools and resources for Simutrans.

"Promote to line" button is causing problems.

Started by Yona-TYT, May 26, 2017, 03:51:05 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Yona-TYT


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




I must wait for this to be able to launch a new version of the tutorial.  ;)

Dwachs

Is_schedule_allowed is only called when the schedule of a line or a line-less convoy is changed.
Parsley, sage, rosemary, and maggikraut.

Yona-TYT

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?  ???

Dwachs

The schedule should have been checked before already.
Parsley, sage, rosemary, and maggikraut.

Yona-TYT

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.

prissi

Why, the line is valid for that kind of transport?

Yona-TYT

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.  ;)

An_dz

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.


Dwachs

see r8270: promote to line will call is_schledule_allowed.
Parsley, sage, rosemary, and maggikraut.

Yona-TYT

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:  ;)

Yona-TYT

@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.

Yona-TYT

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 ?.  ???

Dwachs

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.
Parsley, sage, rosemary, and maggikraut.


Yona-TYT

#15
@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)




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
    }
}



Dwachs

Imho. this is a problem of your script: It should accept empty schedules.
Parsley, sage, rosemary, and maggikraut.

Yona-TYT

#17
@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
Savegame -> test-tuto.sve