Change [a lot] conditions via Lua

  • #1, by eldakanSunday, 17. November 2019, 11:20 5 years ago
    Hey there, 

    I am working on a riddle where items have to be put on a 6x5 grid in a certain way to solve it. 
    On  each part of the grid an item can be dropped. The items have different sizes and can (and do) occupy more than one space. 
    To make this work properly I figured I'd have to disable the parts of the grid, when they are occupied.

    To do so I got one condition for each field, which I can change via Lua script. 

    Now to do this manually would be possible but it would take ages (8 items on 30 fields)

    Is there a way to store the conditions in an array and to disable them via a equation

    e.g: I place a 4x4 item on the Field X and thus want to disable X, X+1, X+6 and X+7, so those cant be used anymore. 

    I hope this explains my issue and that there is a solution smile Thanks for any tips and help!

    Newbie

    11 Posts


  • #2, by afrlmeSunday, 17. November 2019, 12:04 5 years ago
    here this might help...
    sliding puzzle (3x3). I created it ages ago, so it's probably a little out of date, but I believe you can use it to figure out what you are wanting to do as I used it to block/check which grids were filled/empty to determine where the clicked piece could slide to.

    Imperator

    7285 Posts

  • #3, by eldakanSunday, 17. November 2019, 12:52 5 years ago
    Yeah I tried to understand that code/ that puzzle earlier already and didnt really get it...
    I am very new to Lua and Scripting overall... 

    I will try to copy and use it to understand it and maybe then I can use the parts I need.

    Thanks though!

    Newbie

    11 Posts

  • #4, by afrlmeMonday, 18. November 2019, 02:59 5 years ago
    It would help if you had an image or diagram of some kind to help explain exactly what it is that you are trying to do. It sounds quite complicated based on what you have written.

    Imperator

    7285 Posts

  • #5, by tudor-stamateMonday, 18. November 2019, 09:51 5 years ago
    I think it would be easier if you'd use a 2d table. Essentially having an array for each row/column, this way you use the same indexes instead of having to figure out how to jump from x+2 to x+6.

    To load the conditions in you could try using a for loop and the string.format function to enter the name of the conditions. For example, if you'd have the conditions written as: condition_[rownumber]_[columnnumber], you could do this:

    local conditions = {}
    local sceneConditions = game.currentScene.sceneConditions

    for r = 1, 6, +1 do
      for c = 1, 5, +1 do
        conditions[r][c] = sceneConditions[string.format("condition_%d_%d", r, c)]
      end
    end
    Note, the code was written on the fly so it'll need some debugging to work, but hopefully you get the idea.

    Good luck!

    Newbie

    27 Posts

  • #6, by eldakanMonday, 18. November 2019, 09:54 5 years ago
    Yeah I might have just set my sights too high... 

    The riddle is story-wise that you have to sort dishes into a dishwasher and they only fit in a certain way. You cannot turn the dishes...

    So far I tried to solve this by using a custom inventory, so that the items are draggable and Objects that are placed at x=0,y=0 and are hidden behind the interface. 

    All my Conditions and Objects are either in German, English or a weird mix, sorry for that

    And thanks for the help!

    Pic on the left is what the scene currently looks like in the player

    Newbie

    11 Posts

  • #7, by eldakanMonday, 18. November 2019, 10:00 5 years ago
    local conditions = {}
    local sceneConditions = game.currentScene.sceneConditions

    for r = 1, 6, +1 do
      for c = 1, 5, +1 do
        conditions[r][c] = sceneConditions[string.format("condition_%d_%d", r, c)]
      end
    end

    That sounds like a pretty smart solution! Thanks I'll try to use it, although, as stated earlier my Lua knowledge is nearly equal zero... 

    Newbie

    11 Posts