Update von Konstruktionen - SimpleProposal

Willkommen in der Transport Fever Community

Wir begrüßen euch in der Fan-Community zu den Spielen Transport Fever und Train Fever, den Wirtschaftssimulatoren von Urban Games. Die Community steht euch kostenlos zur Verfügung damit ihr euch über das Spiel austauschen und informieren könnt. Wir pflegen hier einen freundlichen und sachlichen Umgang untereinander und unser Team steht euch in allen Fragen gerne beiseite.

 

Die Registrierung und Nutzung ist selbstverständlich kostenlos.

 

Wir wünschen euch viel Spaß und hoffen auf rege Beteiligung.

Das Team der Transport-Fever Community


  • More likely a bug of the game, have you reported to UG first?

    Not yet. I will do this, but I think it is not a bug, but a safety precaution. Sometimes you want to keep things unchanged you have built before. Imagine - it will change everything on the map! If you don't notice some perhaps unwanted changes, you will save your map and perhaps you can never undo them. I once had a problem with VacuumTube's slope mod. ;) If you don't deactivate a special checkbox, the update of some streets in mountain areas will destroy whole mountains. If you do it manually, you notice this. If you would update automatically, you would not see it, and your savegame could be destroyed forever. I myself know that global updating is a very risky thing - that's why I will be very careful with my update mod. ;)


    But I think something like a special update key or menu would reduce the risk.


    Zitat

    You may keep the nodes from construction side and rebuild edges from free side and using the nodes from construction side so they should get connected.

    You always have the same idea like me. :) But what about two neighboring constructions? ;)


    Zitat

    What about "asset/wk_switch_kit_de_at.con"

    I could send you a pre-version of my update mod, so you could make your own trials - if you want.

    ... don't know much trigonometry ... don't know much about algebra ... don't know what a slide rule is for ...

  • Zitat

    No solution, but it's very rare.

    Not with my or your switch modules. ;)

    Zitat

    Btw, game.interface gets automatically connected edges

    Perhaps I will get it running. If not, it's not so severe. If necessary, you have to update manually. ^^ These guys also do it: https://www.youtube.com/watch?v=plDBlQLt0EA


    I have just sent a request to UG to find out, if the global update issue is a bug.

    ... don't know much trigonometry ... don't know much about algebra ... don't know what a slide rule is for ...

  • Finally I was successful after VacuumTube had done another test. To make it short: There was still another error in my script. In an old version I had used the "load" function instead of "update", because I thought you can use it if you don't want permanent calls. My edge transformations seemed to work, but also load makes permanent calls and there were other disadvantages. So I finally relocated it to "update" in my main mod. But I forgot it in the shorter experimantal version where I did my upgradeConstruction trials. But upgradeConstruction does not work with "load" at all.


    But that was not all. I also had to set seed to nil - as VacuumTube said.


    Now this is my code:

    Code
    oldConstruction.params.seed = nil
    local newId = game.interface.upgradeConstruction(oldConstruction.id, oldConstruction.fileName, oldConstruction.params)


    The upgrade does connect the tracks! Even switches and I hope also stations. I have not yet tested if it also changes the speed coeffs and other things. Moreover I'm waiting for UG's answer to my bug request.


    I am very happy with it. :) Thanks to you and all who helped me! :thumbup::thumbup::):)

    ... don't know much trigonometry ... don't know much about algebra ... don't know what a slide rule is for ...

  • I've got news from UG. :) As I assumed, the missing "complete update" is no bug. Optical changes are done, but no technical, because some parameters, e.g. the travel time, have to be calculated anew and this needs time. I have noticed this in my mod, too. If I do a full replacement, the game will freeze at the start for about two minutes. But afterwards everything seems to be ok. The only thing I have to do is to restart some trains which stopped because I virtually tore away the tracks underneath. Perhaps they will realize my idea of an actualizer button. Until then there is my mod, which now seems to work in the intended way. But though I have to do some tests.

    ... don't know much trigonometry ... don't know much about algebra ... don't know what a slide rule is for ...

  • the load function is to reload data from engine to graphics, so they are called each engine cycle and the data in it is what you returned in save function.


    if you want to execut it once, should sent a event in guiInitHandle and treat it in eventHandle.

    This guy is too lazy to create a signature. 8o

  • Still the question remains: What is "seed" actually good for? The UG wiki does not really tell ... ;)

    in tpf1 seed was an alternative id, for example if you remove a station then add another at the same place in a short while, they will get a same id but not same seed, but I found it not 100% relaiable and it seems in tpf2 they have changed its meaning

    This guy is too lazy to create a signature. 8o

  • The seed is /was used for pseudo random generation and will be constant when upgrading a construction. (The reason the code refuses upgrading with seed parameter)

    (Used in for building trees pseudo random at airport terminal as example)



    The remove / build and and upgrade are technical a bit different:


    When removing you lose ecs entity Construction, the seed, you get an ecs Object (the coutdown sign) that represents a former station.

    (This holds the links to the ecs Line entities intact by using the stationgroup/station type) If you build a new station construction, it looks for these signs and reuses the station.


    When upgrading/rebuilding a station in place, the ecs construction is modified in place...

  • if you want to execut it once, should sent a event in guiInitHandle and treat it in eventHandle.

    Are you sure that guiInit is not only for initializing GUI elements? I don't have any GUI elements in my script because it works fully independent from the GUI. And I cannot find an example what code I must insert there. :/ I also could not find eventHandle - do you mean handleEvent? Or guiHandleEvent?


    For making update working once I use a done flag which is changed after the first pass. I don't know whether there are any disadvantages.

    ... don't know much trigonometry ... don't know much about algebra ... don't know what a slide rule is for ...

  • When upgrading/rebuilding a station in place, the ecs construction is modified in place...

    This seems to be the best way not to destroy the node connections as remove/add does. I found no way to solve it, so I think its better to use update which is now working. The only disadvantage is the missing callback error handler option.

    ... don't know much trigonometry ... don't know much about algebra ... don't know what a slide rule is for ...

  • Are you sure that guiInit is not only for initializing GUI elements? I don't have any GUI elements in my script because it works fully independent from the GUI. And I cannot find an example what code I must insert there. :/ I also could not find eventHandle - do you mean handleEvent? Or guiHandleEvent?


    For making update working once I use a done flag which is changed after the first pass. I don't know whether there are any disadvantages.

    guiInit is called when the map is loaded and it's called once. You can find usage of it in my zero height bridge mod.


    If you use flags, you can only use it once, from time to time, since once you set the flag, they are saved in the gamesave.lua, it's loaded at the next load, so you deadlock your code.

    This guy is too lazy to create a signature. 8o

    Einmal editiert, zuletzt von Enzojz ()

  • Zitat

    guiInit is called when the map is loaded and it's called once. You can find usage of it in my zero height bridge mod.

    I found it, but now I do not know:

    - Where do I get the Id from I have to put in? Can it be my own random Id, e.g. "1" ?

    - The same with the name: Can I use a random name?

    - And which are the params? The only params I know are those of my construction. I think that they are not meant. :/

    Zitat

    If you use flags, you can only use it once, from time to time, since once you set the flag, they are saved in the gamesave.lua, it's loaded at the next load, so you deadlock your code.

    Deadlocking would be exactly what I want in my special case :love::D - because I want the user to start my mod only one time and then never again unless it will be resetted. So I just tried out the thing with the flag but It does not even work. ^^


    This is part of my previous code:

    Code
    [...]
    local done = false
    
    local update = function ()
    if not done then
        done = true
        [...]
    end

    You may notice that local done is outside of any functions although it is read by them - but in a test it was not stored, neither in the savegame. Up to now I anyway thougt that values would only be stored in the state table being used in the load and save functions? For this reason I even had created a second flag state.selfDestruction which works wonderful inside load and save, but if I remove this and leave the job alone to done as used above, it does not work. :/ This is very interesting ...

    ... don't know much trigonometry ... don't know much about algebra ... don't know what a slide rule is for ...

  • First in script there are two indepdent environement: gui part and game engine part, they don't have access to each other


    Zitat

    I found it, but now I do not know:

    - Where do I get the Id from I have to put in? Can it be my own random Id, e.g. "1" ?

    - The same with the name: Can I use a random name?

    - And which are the params? The only params I know are those of my construction. I think that they are not meant. :/


    The usual way I use guiInit is to send an event to game engine so the game engine process an event at the first cycle of the game.

    I don't know what you refer to "name" and "params", I don't think you need them, since your operation is for all edges on the map.


    Zitat


    Deadlocking would be exactly what I want in my special case :love::D - because I want the user to start my mod only one time and then never again unless it will be resetted. So I just tried out the thing with the flag but It does not even work. ^^

    But also when he wants to use it the second time, it won't work.



    Zitat


    You may notice that local done is outside of any functions although it is read by them - but in a test it was not stored, neither in the savegame. Up to now I anyway thougt that values would only be stored in the state table being used in the load and save functions? For this reason I even had created a second flag state.selfDestruction which works wonderful inside load and save, but if I remove this and leave the job alone to done as used above, it does not work. :/ This is very interesting ...


    I have never tried other variable name other than state but I suppose the saved things are the thing you return from save function.

    This guy is too lazy to create a signature. 8o

  • Zitat

    The usual way I use guiInit is to send an event to game engine so the game engine process an event at the first cycle of the game.

    I don't know what you refer to "name" and "params", I don't think you need them, since your operation is for all edges on the map.

    This is what I mean:

    Code
    game.interface.sendScriptEvent(id, name, param)

    So could I write

    Code
    game.interface.sendScriptEvent("__foo__", "myEvent", nil)

    :?: At first I thought id could be a number. But meanwhile I think I must use a string like you did. Do the "__" mean anything or is it only for you?

    Zitat

    But also when he wants to use it the second time, it won't work.

    I've implemented a reset mechanism: A selectable "loadGameScript" modifier in the runFn will replace the load function by something else and so break the chain. This works. 8)


    But I will also try out the event thing. You can never learn enough. :)


    By the way, I'm not so happy with upgradeConstruction as I thought before. The disadvantage is error handling! If an error arises - and there will be errors - it will crash, because it does not handle errors by working around like a proposal does. So I invented a special error handler to cope with this thing. ?( But for this I have to use a proposal structure again. ^^ It's a little redundant, but I found no other way. :/

    ... don't know much trigonometry ... don't know much about algebra ... don't know what a slide rule is for ...

  • Zitat

    At first I thought id could be a number. But meanwhile I think I must use a string like you did. Do the "__" mean anything or is it only for you?

    Nothing special, it's a discrimator, just need to be as much as different to possible ones (from other mods and game vanilla ones)


    Zitat




    By the way, I'm not so happy with upgradeConstruction as I thought before. The disadvantage is error handling! If an error arises - and there will be errors - it will crash, because it does not handle errors by working around like a proposal does. So I invented a special error handler to cope with this thing. ?( But for this I have to use a proposal structure again. ^^ It's a little redundant, but I found no other way. :/

    Try pcall or xpcall of lua, I don't know if it works but it worth trying

    This guy is too lazy to create a signature. 8o

  • I've tested your guiInit/handleEvent method and - good news - it works! The result is the same as with my "done" flag. Maybe your way is the better programming style, so I will use it definitely. But it is not easy to find out what is officially allowed and what could be a hack.

    ... don't know much trigonometry ... don't know much about algebra ... don't know what a slide rule is for ...

BlueBrixx