Author Topic: save convoy_x  (Read 484 times)

0 Members and 1 Guest are viewing this topic.

Offline Yona-TYT

save convoy_x
« on: May 21, 2017, 03:42:22 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:  :-[

Code: [Select]

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()

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

Offline Dwachs

  • DevTeam, Coder/patcher
  • Administrator
  • *
  • Posts: 4235
  • Total likes: 169
  • Helpful: 149
  • Languages: EN, DE, AT
Re: save convoy_x
« Reply #1 on: May 21, 2017, 07:03:08 AM »
Parsley, sage, rosemary, and maggikraut.

Offline Yona-TYT

Re: save convoy_x
« Reply #2 on: May 24, 2017, 06:14:57 AM »
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)
Code: [Select]
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.


Offline Yona-TYT

Re: save convoy_x
« Reply #3 on: May 25, 2017, 04:04:44 PM »
@Dwachs
Can you replicate the error? ???

Offline Dwachs

  • DevTeam, Coder/patcher
  • Administrator
  • *
  • Posts: 4235
  • Total likes: 169
  • Helpful: 149
  • Languages: EN, DE, AT
Re: save convoy_x
« Reply #4 on: May 25, 2017, 04:49:37 PM »
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:
Code: [Select]
...
,
        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.

Offline Yona-TYT

Re: save convoy_x
« Reply #5 on: May 25, 2017, 05:10:40 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:
Code: [Select]
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 
}

If you look into the log, you see the loaded data from the persistent table, there are no double entries:
Code: [Select]
...
,
        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
« Last Edit: May 25, 2017, 05:28:14 PM by Yona-TYT »

Offline Dwachs

  • DevTeam, Coder/patcher
  • Administrator
  • *
  • Posts: 4235
  • Total likes: 169
  • Helpful: 149
  • Languages: EN, DE, AT
Re: save convoy_x
« Reply #6 on: May 25, 2017, 06:31:30 PM »
So what exactly are the steps to reproduce which wrong behavior?
Parsley, sage, rosemary, and maggikraut.

Offline Yona-TYT

Re: save convoy_x
« Reply #7 on: May 25, 2017, 08:08:54 PM »

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

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
Quote
If 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.
« Last Edit: May 26, 2017, 01:00:46 AM by Yona-TYT »

Offline Dwachs

  • DevTeam, Coder/patcher
  • Administrator
  • *
  • Posts: 4235
  • Total likes: 169
  • Helpful: 149
  • Languages: EN, DE, AT
Re: save convoy_x
« Reply #8 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.
Parsley, sage, rosemary, and maggikraut.

Offline Yona-TYT

Re: save convoy_x
« Reply #9 on: May 27, 2017, 01:05:00 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? ???