The International Simutrans Forum

 

Author Topic: [Patch] Get version of simutrans  (Read 296 times)

0 Members and 1 Guest are viewing this topic.

Offline Yona-TYT

  • Devotee
  • *
  • Posts: 1768
    • Simutrans-BLOG
  • Languages: ES
[Patch] Get version of simutrans
« on: August 07, 2021, 07:12:55 AM »
I made a little patch to get the version number from the script.https://forum.simutrans.com/index.php/topic,21016.0.html


 

Offline Dwachs

  • DevTeam, Coder/patcher
  • Administrator
  • *
  • Posts: 4913
  • Languages: EN, DE, AT
Re: [Patch] Get version of simutrans
« Reply #1 on: August 07, 2021, 07:40:57 AM »
thank you! in r9983.

Offline Yona-TYT

  • Devotee
  • *
  • Posts: 1768
    • Simutrans-BLOG
  • Languages: ES
Re: [Patch] Get version of simutrans
« Reply #2 on: August 09, 2021, 03:51:02 PM »
Thank you very much for the implementation.  8) 
This is the experiment I wanted to do:  :P
Code: [Select]
function string_analyzer()
{
    local result = {pak= false , st = false}

    //Check version and pakset name
    current_pak = get_pakset_name()
    current_st = get_version_number()

    local p_siz = {a = current_pak.len(), b = pak_name.len()}


    //Pak name analyzer
    local siz_a = max(p_siz.a, p_siz.a)
    local count_a = 0
    local tx_a = ""
    for(local j=0;j<siz_a;j++){
        try {
            pak_name[count_a]
        }
        catch(ev) {
            break
        }
        if(count_a>0 && current_pak[j]!=pak_name[count_a]){
            break
        }
        if(current_pak[j]==pak_name[count_a]){
            tx_a += format("%c",current_pak[j])
            count_a++
            continue
        }
    }
    if(pak_name == tx_a) result.pak = true
    //gui.add_message("Current: "+current_pak+"  Tx: "+tx_a+"  Pak: "+pak_name+" result: "+result.pak)

    local s_siz = {a = current_st.len(), b = simu_version.len()}
    local siz_b = max(s_siz.a, s_siz.a)

    local nr_a = 0
    local nr_b = 0

    while(nr_a<s_siz.a || nr_b<s_siz.b){
        local value_a = ""
        for(local j=nr_a;j<s_siz.a;j++){
            local tx = format("%c",current_st[j])
            try {
                tx.tointeger()
            }
            catch(ev) {
                if(tx=="."){
                    nr_a = j+1
                    break
                }
                nr_a++
                continue
            }
            value_a+=tx
        }

        local value_b = ""
        for(local j=nr_b;j<s_siz.b;j++){
            local tx = format("%c",simu_version[j])
            if(tx=="."){
                nr_b = j+1
                break
            }
            value_b+=tx
            if(j == s_siz.b-1)nr_b = s_siz.b
        }
        try {
            value_a.tointeger()
            value_b.tointeger()
        }
        catch(ev) {
            continue
        }
        //gui.add_message("value_a "+value_a.tointeger()+"  value_b "+value_b.tointeger()+"")
        if(value_a.tointeger()<value_b.tointeger()){
            result.st = false
            break
        }
        result.st = true
    }
    //gui.add_message("result st: "+result.st+"  result pak:" +result.pak)
    return result
}