The International Simutrans Forum

 

Author Topic: Inconsistency when getting values from "difftick_to_string"  (Read 524 times)

0 Members and 1 Guest are viewing this topic.

Offline Yona-TYT

  • Devotee
  • *
  • Posts: 1730
    • Simutrans-BLOG
  • Languages: ES
 The displayed values are incorrect, for example if I enter a value of 30 (0: 30h) the value shown in "difftick_to_string" is (0: 01h), I can fix this from the script simply by multiplying the value "entrie.wait "by 16.

Offline Yona-TYT

  • Devotee
  • *
  • Posts: 1730
    • Simutrans-BLOG
  • Languages: ES
Re: Inconsistency when getting values from "difftick_to_string"
« Reply #1 on: May 16, 2021, 05:42:45 PM »
Upgrade.
 For pak128 I multiply "entrie.wait" by 8.
 For pak64 I multiply "entrie.wait" by 16.

 I make this setting so that "difftick_to_string" shows the correct value.


Code: [Select]
function is_schedule_allowed(pl, schedule)
{
    local nr = schedule.entries.len()
    if(nr>0){
        local entrie = schedule.entries[0]
        if(entrie.wait){
            local halt   = entrie.get_halt( player_x(pl) )
            if (halt){
                return "Wait Time: "+entrie.wait+" :: Difftick tostring: "+difftick_to_string(entrie.wait*8)+""
            }
        }
    }
    return null
}

Offline Dwachs

  • DevTeam, Coder/patcher
  • Administrator
  • *
  • Posts: 4897
  • Languages: EN, DE, AT
Re: Inconsistency when getting values from "difftick_to_string"
« Reply #2 on: May 17, 2021, 06:09:27 AM »
I see, can be fixed.

In the meantime, prissi created another behavior for absolute departure time. Please do not ask to make this available for scripting as long as this feature is not finalized.

Offline prissi

  • Developer
  • Administrator
  • *
  • Posts: 10818
  • Languages: De,EN,JP
Re: Inconsistency when getting values from "difftick_to_string"
« Reply #3 on: May 17, 2021, 06:40:50 AM »
The schedule waiting time is 65535 ticks per month. However, difftick_to_string() needs them in bits_per_month. Hence you need to shift it left by bit_shifts_per_month-16

Offline Dwachs

  • DevTeam, Coder/patcher
  • Administrator
  • *
  • Posts: 4897
  • Languages: EN, DE, AT
Re: Inconsistency when getting values from "difftick_to_string"
« Reply #4 on: May 19, 2021, 06:17:17 PM »
Please try r9790. I added a new method to schedule_entry_x: waiting_time_to_string. To call it use
Code: [Select]
local entry = schedule.entries[0]
print(entry.waiting_time_to_string)

Offline Yona-TYT

  • Devotee
  • *
  • Posts: 1730
    • Simutrans-BLOG
  • Languages: ES
Re: Inconsistency when getting values from "difftick_to_string"
« Reply #5 on: June 02, 2021, 04:33:43 PM »
Please try r9790. I added a new method to schedule_entry_x: waiting_time_to_string. To call it use
Code: [Select]
local entry = schedule.entries[0] print(entry.waiting_time_to_string)
Thank you very much, this works great.  8)