Setting lots of conditions/values at once using scripts

  • #1, by NovelThursday, 23. May 2013, 23:14 7 years ago
    In order to rush through the chapters of my game, I made a "developer dialogue" that is called when the game begins. The answers in the dialogue call lists of ordinary actions that put the character in the desired place and set the desired conditions/values. This procedure seems more flexible to me than using save games and also works when loading the project on other computers.

    However, I did develop using save games in the last couple of months. Now wanting to swich back to my dev-dialogue idea I'm facing a rather huge list of conditions and values. Instead of clicking the action together now, I thought this might be a good occasion to get started with LUA. :-)

    So, how do I change multiple conditions or values with a script at once and call it from within an action?

    Newbie

    100 Posts


  • #2, by afrlmeFriday, 24. May 2013, 02:21 7 years ago
    I would recommend adding the required conditions/values for each chapter to be added into tables ...

    you could for instance create a table which links to all of the values & conditions by using the getObject() command ...
    tblConds = {}
    tblConds["cond_name"] = getObject("Conditions[cond_name]") -- replace cond_name with condition name
    ...

    tblVals = {}
    tblVals["val_name"] = getObject("Values[val_name]") -- replace val_name with value name
    ...
    1
    2
    3
    4
    5
    6
    7
    8

    alternatively you can use index numbers instead
    tblConds = {}
    tblConds[1] = getObject("Conditions[cond_name]") -- replace cond_name with condition name
    ...
    1
    2
    3
    4

    now for each chapter we can create a function which you can call via "execute a script > function_name()"
    function setC1cv() -- set Chapter 1 conditions & values
    -- let's set the conditions
    tblConds["cond_name"]:setValue(VConditionValue, true) -- or false
    ...
    -- let's set the values
    tblVals["val_name"]:setValue(VValueInt, number) -- replace number with an integer value
    ...
    end
    1
    2
    3
    4
    5
    6
    7
    8
    9

    something like that should work fine I think. this is of course just something quick off the top of my head & there might be a better/alternative way but it's late & I haven't got me thinking cap on.

    P.S: the "..." just represent additional data for you to add, they shouldn't be included in the scripts. Also there's actually a basic developers console which can be toggled with the "tab key" while running your game via the VS editor. With this you can do various things from changing scenes/characters/conditions/values/print_log/execute a script & other various things. you could use it to quickly change to x scene & for executing the required function for changing the values/conditions.

    Imperator

    6804 Posts

  • #3, by NovelFriday, 24. May 2013, 21:51 7 years ago
    Thing is, this is my first attempt with LUA so I might do something stupidly wrong.

    I put your code into a script like you can see on the screenshot. Caling it from within the game didn't work though. Should it work? (I might have made a mistake somewhere else).

    Newbie

    100 Posts

  • #4, by afrlmeFriday, 24. May 2013, 21:57 7 years ago
    ok sorry...

    forgot to mention that the script should be set as "definition" in the script properties & not execution!

    & you need to "execute a script" not "call/quit a script"

    so you would do for example: "execute a script: TurnOn()"

    Imperator

    6804 Posts

  • #5, by NovelFriday, 24. May 2013, 22:10 7 years ago
    Success! Thank you so much AFRLme!
    My mistake was also to try calling "function TurnOn()" instead of "TurnOn()" red

    I guess I need the "call a script" if I want to use a different script temporarily?

    Newbie

    100 Posts

  • #6, by afrlmeFriday, 24. May 2013, 22:28 7 years ago
    just set the conditions values inside of each function & when you execute the function it will change all conditions/values listed inside of it.

    call script is used for scripts that don't use functions.

    for instance:

    local count = 0

    -- repeat this next part until the value of count equals 10
    repeat
    count = count + 1
    print("count value=" .. count)
    until count = 10
    1
    2
    3
    4
    5
    6
    7
    8


    if you check the new wiki under the Lua section on the left hand menu, you will find various Lua stuff to help you get started. I've not written too much on the basics bit yet, but all of the VS Player Commands have working script examples.

    Imperator

    6804 Posts

  • #7, by NovelFriday, 24. May 2013, 23:58 7 years ago
    Oh, I didn't know the new wiki yet. That's good stuff!

    Playing around with the script, it looks like the number of conditions I can change at a time is limited by the engine. I made a list of all conditions and produced the commands using excel. I intended to change all conditions to true or false. But only around 20 are changed. First I thought, it's conditions with an Umlaut that don't work, but as soon as I simply move them to the top of the funtion, it works...
    For my purposes, I should group the conditions anyway. Will try that now.

    Newbie

    100 Posts

  • #8, by afrlmeSaturday, 25. May 2013, 00:59 7 years ago
    there's a limit to how much you can change at the same time? I didn't know as I haven't tested it.

    I think something could be done with the table max number query & the for each command so that you could essentially create tables for each chapter with the required changes & have it go through them one by one - should bypass the limit thing you mentioned - I think. I'm not in the mood or right frame of mind to try thinking up the code for this right now... feeling a bit knackered.

    P.S: technically you could achieve what you are wanting to do by using "called by other action" action parts, inside of the editor itself - well if you don't mind all the energy you'll be exerting via constantly moving the mouse here & there & left clicking to select this & that grin

    Imperator

    6804 Posts

Write post