News:

Simutrans Chat Room
Where cool people of Simutrans can meet up.

save convoy_x

Started by Yona-TYT, May 21, 2017, 03:42:22 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Yona-TYT

Quote from: Dwachs on May 20, 2017, 08:27:19 AM
You could also save the convoy_x instances and check them later:
How do I save "convoy_x" using "persistent"?  ???

This does not work:  :-[


datasave <- {
    cov = cov_save
}

class data_save {
     
    // Convoys
    function convoys_save() {return datasave.cov;}
     
    function _save() { return "data_save()"; }
}

persistent.datasave <- datasave


function resume_game()
{

// Datos guardados
//-----------------------------------------------------
     
    foreach(key,value in persistent.datasave)
    {
        datasave.rawset(key,value)
    }
    persistent.datasave = datasave

    // Se obtienen los datos guardados
    cov_save  = data_save().convoys_save()


//-------------------------------------------------------
}


Dwachs

Parsley, sage, rosemary, and maggikraut.

Yona-TYT

I have problems with the list of saved convoys.

Script: http://files.simutrans.com/index.php/s/MnMVUIgYmHetqaa
Savegame: http://files.simutrans.com/index.php/s/nHumABiXC5G5kuB

I have no problem saving convoys, the problem is when the list is loaded empty.

At the time of filling the list the convoys are doubled.



For replica only start the vehicles that are in the road deposit.

I am sure the problem is caused by this code: scenario.nut (line 388)
datasave <- {
    cov = cov_save
}

class data_save {
     
    // Convoys
    function convoys_save() {return datasave.cov;}
     
    function _save() { return "data_save()"; }
}

persistent.datasave <- datasave

convoy_x._save <- function ()
{
    return "convoy_x(" + id + ")"
}
//-----------------------------------------------------------

function resume_game()
{

// Datos guardados
//-----------------------------------------------------     
    // copy it piece by piece otherwise the reference 
    foreach(key,value in persistent.datasave)
    {
        datasave.rawset(key,value)
    }
    persistent.datasave = datasave

    // Se obtienen los datos guardados
    cov_save  = data_save().convoys_save()
    //cov_save  = array(50)

//-------------------------------------------------------

}


If you change "cov_save = data_save().convoys_save()" to "cov_save = array(50)" duplicates no longer appear.


Yona-TYT

@Dwachs
Can you replicate the error? ???

Dwachs

No. I get a list of 10 NUL!!!! entries.

If you look into the log, you see the loaded data from the persistent table, there are no double entries:

...
,
        datasave = {
                cov = [
                        convoy_x(1),
                        convoy_x(7),
                        convoy_x(8),
                        convoy_x(18),
                        convoy_x(6),
                        convoy_x(2),
                        convoy_x(3),
                        convoy_x(11),
                        convoy_x(10),
                        convoy_x(9),
                        convoy_x(5),
                        null,
                        null,
...
Parsley, sage, rosemary, and maggikraut.

Yona-TYT

#5

Quote from: Dwachs on May 25, 2017, 04:49:37 PM
No. I get a list of 10 NUL!!!! entries.
Sorry for the confusion, it's actually that "Null !!!!" Is to indicate that the vehicle fails or is not in the depot.
This is the code that shows the list:

function get_goal_text(pl)
{
        local tx = ""
        local j=0
        for(j;j<gcov_nr;j++){
            local result = true
            // cnv - convoy_x instance saved somewhat earlier
            try {
                 cov_save[j].get_pos() // will fail if cnv is no longer existent
                 // do your checks
            }
            catch(ev) {
                result = false
            }
            if (result){
                if (cov_save[j].is_in_depot()){
                    result = false
                }
            }

            if (result) {
                tx += ">["+j+"] <a href=\"("+cov_save[j].get_pos().tostring()+")\"> ("+cov_save[j].get_pos().tostring()+")[/url] "+cov_save[j].get_name()+"[br /]"
            }
            else
                tx += "<st>["+j+"]</st> Null !!!! [br /]"
        }
        return tx 
}


Quote from: Dwachs on May 25, 2017, 04:49:37 PM
If you look into the log, you see the loaded data from the persistent table, there are no double entries:

...
,
        datasave = {
                cov = [
                        convoy_x(1),
                        convoy_x(7),
                        convoy_x(8),
                        convoy_x(18),
                        convoy_x(6),
                        convoy_x(2),
                        convoy_x(3),
                        convoy_x(11),
                        convoy_x(10),
                        convoy_x(9),
                        convoy_x(5),
                        null,
                        null,
...


Edit.
At first the list is correct, the duplicates appear after starting the second vehicle.
No doubt something strange happens here. :o

Dwachs

So what exactly are the steps to reproduce which wrong behavior?
Parsley, sage, rosemary, and maggikraut.

Yona-TYT

#7

Oops! Forget to uncomment the line "cov_save = data_save() .convoys_save()", change to this script: http://files.simutrans.com/index.php/s/GhSVyKx8V3J39gh

Quote from: Dwachs on May 25, 2017, 06:31:30 PM
So what exactly are the steps to reproduce which wrong behavior?
1. Load the savegame and do not close the window "current scenario details".
2. On the road deposit, start the first bus, note that the space "0" in the list stops being null.
3.Start the second bus, note that space [1] and [6] is no longer null, this should not happen.

As I mentioned before
QuoteIf you change "cov_save = data_save().convoys_save()" to "cov_save = array(50)" duplicates no longer appear.
therefore is not a problem with the scenario.

Dwachs

Loading and saving is correct and does not create double entries. There must be a bug elsewhere in your script.
Parsley, sage, rosemary, and maggikraut.

Yona-TYT

Quote from: Dwachs on May 26, 2017, 06:13:30 AM
Loading and saving is correct and does not create double entries. There must be a bug elsewhere in your script.
It does not seem.

If you remove the line (421) "cov_save = data_save().convoys_save()" and load the game again this works fine. How is this possible then? ???