Scripts not working after loading a game

  • #1, by cr34m3Monday, 10. March 2014, 23:57 6 years ago
    I'm getting some strange behaviour from VS and I can’t seem to pinpoint why exactly. My definition scripts work fine when I start a new game, but after I save, exit the game and load they don’t work anymore.

    As an example; I’m implementing an ‘item view’ interface to allow for closer inspection of items. There’s a condition set for each item (e.g. ViewingITM_Book10) which toggles the display of its large image. I’ve written the script below to save some time and make sure only a single item is displayed:

    tblViewConds = {}
    tblViewConds[1] = getObject("Conditions[ViewingITM_Book10]")
    ...
    tblViewConds[18] = getObject("Conditions[ViewingITM_Will]")

    function ResetItemViews()
    for k = 1,18 do
    tblViewConds[k]:setValue(VConditionValue,false)
    end
    end

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12


    I’ve checked the log file (just the “A cutscene was started in action… but was not terminated” warning) and the console, and it seems like my table of conditions (tblViewConds) is not being defined.

    All other scripts also stop working. Funny thing is, I’ve got a similar script for the save slot selection resetting and it works fine in the main menu (when I’m navigating to my saved game) but after I load it stops working.

    Where can I start troubleshooting? Am I only allowed to have one definition script? Do I explicitly need to specify that scripts load when games are loaded?

    I’m kinda lost here. confuse

    Newbie

    72 Posts


  • #2, by afrlmeTuesday, 11. March 2014, 00:24 6 years ago
    No you can have as many definition/execution scripts as you like, but you can only have one of each event handler/listener & one function for each.

    the error thing you mentioned is just some minor warning to do with using at begin of scene action in 3.7.1. I've not seen that error in the dev/beta builds.

    what exactly is happening? are there any errors in the log file? (make sure log level is set to info) would you be willing to share the scripts?

    P.S: here's a little tip for the for loop...
    for k = 1,18 do


    for k = 1,table.maxn(table/var name) do -- returns total entries of linked table
    1
    2
    3
    4
    5

    it's a good method to use for automatically getting total from data structure tables or dynamic tables where amount of entries changes.

    P.P.S: do any of your scripts feature global vars/tables of the same name?

    P.P.P.S: just remembered... definition scripts are loaded on game launch, so after loading from a save, you may need to reload the script. try setting it as an execution script & calling it after game load or as needed. if you plan on doing that then it might be a good idea to set your tables up as temporary tables.

    Imperator

    6819 Posts

  • #3, by cr34m3Tuesday, 11. March 2014, 00:45 6 years ago
    I've checked my scripts again, there are no duplicate global variable names.

    The only errors in the log file are these:
    01:34:26: A cutscene was started in action "MEN_SaveLoad: BUT_Load: Left click" (data id: 102) but was not terminated
    01:34:28: Error: Failed to run string in Lua: [string "--[[..."]:28: attempt to index field '?' (a nil value)
    01:34:28: Error: String content: ResetItemViews()

    (line 28 is this: tblViewConds[k]:setValue(VConditionValue,false) )

    So what happens is that when I click an item ResetItemViews() fails (as per the log file), the view condition gets set to true (via the VS interface) and ultimately my items get shown on top of each other.

    From the VS console (in-game) if I run "EXEC PRINT(tblViewConds[1])" it indicates that there's a nil value (i.e. the getObject command didn't happen).

    As far as the scripts go, there isn't really much else to show -- the SaveSlotReset script looks almost identical and you've seen the sliding puzzle script.

    Can I just check something: are all the variable defined at the start of Definition scripts (before the first function) implicitly global or do I need to mark them all as global?

    Newbie

    72 Posts

  • #4, by afrlmeTuesday, 11. March 2014, 00:49 6 years ago
    all variables, tables, functions etc are global by default; meaning they will work across all scripts, unless you add local before them.

    see the p.p.p.s part I added to my previous post. let me know if it solves the problem.

    Imperator

    6819 Posts

  • #5, by cr34m3Wednesday, 12. March 2014, 00:49 6 years ago
    P.P.P.S: just remembered... definition scripts are loaded on game launch, so after loading from a save, you may need to reload the script. try setting it as an execution script & calling it after game load or as needed. if you plan on doing that then it might be a good idea to set your tables up as temporary tables.

    Ok, doing this does solve the problem. But using command scripts isn't functional when I want to pass arguments to my functions. (or at least I haven't thought of a way to do that now smile )

    I've done some further poking and I think I've found what the issue is. I am however unsure whether this is a bug or by design.

    Ok, so here’s what’s happening --

    I’ve got these variable definitions at the start of one of my definition scripts:
    booksol = "12345678910"
    feedback = getObject("Values[PuzzleFeedback]")
    allin = getObject("Conditions[B10Inserted]")
    tblOuts = {}
    tblOuts["one"] = getObject("Conditions[B1Out]") -- indices for testing, table has multiple entries
    tblOuts[1] = getObject("Conditions[B1Out]")
    testvar1 = getObject("Conditions[B1Out]")
    1
    2
    3
    4
    5
    6
    7
    8


    I set my logging level to ‘Info’ and ran the game. Now using the tab-console I print the following to the log file:
    Console command: EXEC print(booksol, feedback, allin, tblOuts[1], tblOuts[“one”], testvar1, tblOuts)

    I did this at different times:
    Test1. In the main menu, directly after pressing F9 in VS.
    Test2. Directly after starting a new game from the main menu (first scene).
    Test3. Directly after loading a game (note the results are the same whether I load from the main menu, or load after starting a new game)

    Here’s the results:
    Test1 -- 01:15:08: 12345678910	PuzzleFeedback (20,1)	B10Inserted (10,33)	B1Out (10,44)	B1Out (10,44)	B1Out (10,44)	table: 128CC8E8
    Test2 -- 01:15:53: 12345678910 PuzzleFeedback (20,1) B10Inserted (10,33) B1Out (10,44) B1Out (10,44) B1Out (10,44) table: 128CC8E8
    Test3 -- 01:16:35: 12345678910 PuzzleFeedback (20,1) B10Inserted (10,33) nil nil B1Out (10,44) table: 128CE170
    1
    2
    3
    4


    Right. So I’m guessing that one of two things is happening here; either the tables are cleared and not populated again after loading or the info in tables isn’t being properly saved. Maybe someone with better VS knowledge can explain this behaviour to me. For all I know I’m the one responsible. wink

    Newbie

    72 Posts

  • #6, by afrlmeWednesday, 12. March 2014, 01:20 6 years ago
    That is very strange behavior, indeed. So it's just the tblOuts[1] & the tblOuts["one"] that is causing the problem? everything else seems to have printed ok.

    I'm not sure about the policy of combining increment/integer tables & string tables in the same table. Try commenting out the tblOuts[1] & see if it will print the tblOuts["one"] or vice versa.

    tables can be done in various ways.
    this...
    t = {"something","something_else","other",2,6}
    1
    2
    3

    is the same as...
    t = {}
    t[1] = "something"
    t[2] = "something_else"
    t[3] = "other"
    t[4] = 2
    t[5] = 6
    1
    2
    3
    4
    5
    6
    7

    you can also do stuff like this...
    t = {a = 1, b = 2, c = 4, d = 8}

    print("a + b = " .. t.a + t.b)
    1
    2
    3
    4

    or...
    t = {"a" = 1, "b" = "yes", "c" = true}

    print("c = " .. t["c"])
    1
    2
    3
    4

    If you are willing to share your .ved & any required resources that go with it, I can see if I can pinpoint the problem & provide a solution. As you mentioned: it could be something on your end or it could be some bloody buggy nonsense in 3.7.1.

    Imperator

    6819 Posts

  • #7, by cr34m3Wednesday, 12. March 2014, 14:44 6 years ago
    I'm doing explicit calls to define the tables at the start of the puzzles, so it's working and I'm running with it for now.

    Regarding the .ved -- the work in progress is a bit big, so sharing it right now is too much effort. wink
    I'll put together a small game to illustrate the problem when I've got some time.

    But thanks for all the tips and assistance.

    Newbie

    72 Posts

  • #8, by afrlmeWednesday, 12. March 2014, 15:42 6 years ago
    ok, no problem. smile

    Imperator

    6819 Posts

Write post