Update von Konstruktionen - SimpleProposal

Willkommen in der Transport Fever Community

Welcome to the fan community of Transport Fever and Train Fever, the economic simulators of Urban Games. The community is free for you to share and inform yourself about the game. We cultivate a friendly and objective interaction with each other and our team will be happy to answer any questions you may have.

 

Registration and use is of course free for you.

 

We wish you a lot of fun and hope for active participation.

The Team of the 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.


    Quote

    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? ;)


    Quote

    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.

  • Quote

    No solution, but it's very rare.

    Not with my or your switch modules. ;)

    Quote

    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.

  • 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
    1. oldConstruction.params.seed = nil
    2. 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::):)

  • 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.

  • 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.

  • 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

  • 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.

  • 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

    Edited once, last by Enzojz ().

  • Quote

    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. :/

    Quote

    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
    1. [...]
    2. local done = false
    3. local update = function ()
    4. if not done then
    5.     done = true
    6.     [...]
    7. 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 ...

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


    Quote

    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.


    Quote


    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.



    Quote


    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.

  • Quote

    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
    1. game.interface.sendScriptEvent(id, name, param)

    So could I write

    Code
    1. 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?

    Quote

    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. :/

  • Quote

    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)


    Quote




    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