[CUSTOM] dialog system (working/tutorial pending)

  • #10, z sebastianSunday, 25. September 2016, 23:42 hodinky 8 years ago
    Maybe the code genies can bring us light here...

    I SUMMON @SIMONS and @BIGSTANS

    wulululululululululu~

    Kapitán

    2346 Posts


  • #11, z afrlmeMonday, 26. September 2016, 00:51 hodinky 8 years ago
    Simon you will probably get a reply from but David? I barely even see him online on Skype / Steam these days - he's quite busy with other things at the minute.

    Imperátor

    7285 Posts

  • #12, z sebastianMonday, 26. September 2016, 08:30 hodinky 8 years ago
    I found the following lines in a wiki about lua (for wow) :

    "Out of scope and garbage collection

    A variable is said to have gone "out of scope" when it is no longer accessible by the currently executing code block. If a variable is out of scope, it is eligible for garbage collection. If no accessible references exist to the variable anymore, the variable will be garbage collected at some point in the future. Take note that this implies that global variables will never be garbage collected unless they are overwritten because they never go out of scope."

    So the "local" stuff gets cleared when not needed. When I have a definition script (loaded permanetly) this may will never be the case when declaring the local variable in the whole scope of the loaded script (at the top outside any function)...

    But to get sure i hope some vs-dev will show up and clear some things up smile

    Kapitán

    2346 Posts

  • #13, z SimonSMonday, 26. September 2016, 09:00 hodinky 8 years ago
    local t = {}
    t["_temporary_"] = ""
    
    t[1] = "hello world"
    t[2] = "goodbye world"
    

    This is a waste of time, since t is not in the global table, it will never qualify for being saved, so no temporary needed.

    Everything that is defined local is not the global table.

    You can also define functions as local:

    local function test()
    end
    


    which equals to

    local test = function()
    end
    


    It's all a question of where do you want to access it, if it should only be visible to the script it's a local.

    About the out of scope thing: Lua doesn't have a scope. It works only with reference counting. Example:

    local t = {}
    function f()
      t[1] = 0
    end
    
    -- t is referenced and will not be collected
    
    f = 0 -- f and t are now unreferenced and will be collected
    


    While t would be out of scope once the function is left, it is not collected.

    Kapitán

    1582 Posts

  • #14, z sebastianMonday, 26. September 2016, 09:31 hodinky 8 years ago
    From a Lua Site: The place where a variable is visible is called the "scope" of a variable.

    Isn't the "scope" of your examples "t" the whole file because you declared it outside of the function?
    By that of course it doesn't get collected because it may is used by other functions in that file, too...

    So to have it clear: does a local variable get garbage collected when not used/referenced to (in VS) anymore (by leaving a function or a while scriptblock) ?

    Kapitán

    2346 Posts

  • #15, z SimonSMonday, 26. September 2016, 09:42 hodinky 8 years ago
    What I meant is it doesn't have a scope in the same way that c++ has a scope, where all variables that go out of scope are immediately freed. Only a reference counter is decremented.

    A global gets never collected, until you remove the link.
    All other variables get collected once there is no reference.

    Kapitán

    1582 Posts

  • #16, z sebastianMonday, 26. September 2016, 09:52 hodinky 8 years ago
    Thanks for clearing this up for me. I'm still new to Lua and a slow lerner regarding new languages.

    ^_^

    Kapitán

    2346 Posts

  • #17, z Simon_ASAMonday, 26. September 2016, 10:59 hodinky 8 years ago
    Hi, I cannot help you Sebastian, I can only encourage you, but your idea of creating a custom dialog system is GREAT! Best of luck!!

    Čestný člen

    321 Posts

  • #18, z sebastianMonday, 26. September 2016, 11:30 hodinky 8 years ago
    Thanks smile

    The code itself is finished right now.
    Now i'll try to create a longer test conversation and maybe an additional interface to make it look different (and test these options)

    These things are still. left but are not required to make it work:



    2) replace < vs=xxx > and < v=xxx > to its string or int. Because the text from the table gets already displayed via a show object text action part, the tags inside this string don't get replaced again. So i need to replace the tags inside the text before displaying them...

    3) currently the object polygon of each line is static. It would be cool to add points to reorder the object polygon and change it regarding to the displayed text (so the dialogscript need a further "polygon"-field with coordinates).

    Kapitán

    2346 Posts

  • #19, z afrlmeMonday, 26. September 2016, 12:01 hodinky 8 years ago
    Aye, thanks for explaining it a little better Simon. smile

    I'm mostly self-taught (as in I only sometimes look up reference code blocks that are similar to something I want to create or as something to refresh my memory on account of the bad memory). I've tried reading through the technical bullshit on the official Lua site, but the large majority of it just sounds like convoluted technical mumbjo jumbo bullshit & it hurts my brain & offends my eyes.

    In regards to the table example I provided. I personally never use local tables myself as a lot of the time I create tables outside of the script I create the functions used to access & manipulate said tables & for things I don't need to save as I have them load in on game launch I tend to set them as temporary. To be honest I don't have a clue how typing table_name["_temporary_"] = "" actually works as it just looks like a regular table field name to me except for the _underscore_ bits.

    Anyway, hopefully I'll be able to take note of what you said & use it to help keep my scripts even more compact & clean. smile

    Imperátor

    7285 Posts

  • #20, z ke4Tuesday, 27. September 2016, 10:00 hodinky 8 years ago
    Damn this looks quite complex grin

    Are you using the DialogPart table? Or is it possible to execute the classic "display text" action part via Lua and get by just with that?

    Zabiják klíčů

    810 Posts