Add String to Table

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


  • So i was trying to make something work.



    First I need to add some Strings to a table. Because the Strings are generated by the Params, it need to be automated.




    So. What is my Problem.


    I tried to add my Strings like this.
    The Variable Letter is m String (it works like i can see in my print)


    Zeichenspeicher[#Zeichenspeicher + 1] = Letter 


    I also tried


    table.insert(Zeichenspeicher, Letter) 


    doesn't work either.


    So i was checking more.


    I declared the Variable like this:


     local Zeichenspeicher = { } 


    and also like this:


    Zeichnspeicher = { } 


    Nothing worked. The Rest of the Script is OK but this little ba****d isnt going like I want.


    So if anyone can help me it would be great

    Warum einfach, wenn es auch schwer geht?


  • In first you need create this table:


    Zeichnspeicher = { } or local Zeichnspeicher = { }


    and next already add strings into this table


    Zeichnspeicher[#Zeichnspeicher + 1] = Letter


    PS. i see differnt names:
    Zeichnspeicher and Zeichenspeicher
    I hope it's mistake on the forum =)

  • There is no Mistake in the Code :C



    Declaration:


    local Zeichenspeicher = {
    -- "Leer",
    -- "Leer",
    }


    Adding:


    local Letter = config.Alphabet[params.RPGFabi_Stationsigns_Buchstabe_1 +1]


    -- table.insert(Zeichenspeicher, Letter)


    Zeichenspeicher[#Zeichenspeicher + 1] = Letter


    print("Zeichenspeicher Letter ".. Letter.." added")

    Warum einfach, wenn es auch schwer geht?


  • Use inspect.lua, check if Letter isn't nil.
    if have commonapi loaded, simple put inspect.lua into res/scripts, then you can use commonapi.dmp(yourvariable) everywhere without doing a require first :)


    LUA is case sensitve, so maybe config.Alphabet isn't defined.
    Zeichenspeicher could be local to a different context, meaning Zeichenspeicher isn't a lua table at this function context.

  • Zeichenspeicher[#Zeichenspeicher + 1] = "Letter" is more reasonable
    if Zeichenspeicher is void, Zeichenspeicher = { "Letter" }

    Problem solved. The string was added to the Table but was deleted directly after, couse the Game restarted the .con after every Change of the Parameter.


    So this did the job:


    Code
    if (Zeichenspeicher == nil) then
    		Zeichenspeicher = {}
    	end

    In debug mode yes but In normal mode all .con are precompiled.


    Anyway it is reexcuted each time, you need somewhere to stock your state.

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

  • Well, but you would want to have your code run successfully in both modes, so it doesn't matter much.
    If you try to help debug this problem from your end via private message and two forum thread then it gets tricky.



    I wouldn't call TPF usage precompiled, the result table of the data function is simply loaded into the game structure once at start/load game time. (except the updateFn, it is called via a global table entry).
    There are some threading memory problems I still have to solve so calling into these function from CommonAPI side isn't doable yet. I should definitely try to invest some time into CommonAPI, lately having not much done...

  • I wouldn't call TPF usage precompiled, the result table of the data function is simply loaded into the game structure once at start/load game time. (except the updateFn, it is called via a global table entry).
    There are some threading memory problems I still have to solve so calling into these function from CommonAPI side isn't doable yet. I should definitely try to invest some time into CommonAPI, lately having not much done...

    for .con files under debug mode no, you can modify .con at runtime and it takes effect immediately, no matter something inside updateFn or not, since updateFn is only a closure with context variables even outside itself.
    For lua all are preexecuted.


    My point is the second line in the last reply, don't get me wrong. ;-)

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

BlueBrixx