This was posted on the OneRoom challenge thread. Copying here as it's relevant to this discussion.
I don't know if I have understood the problem properly, so I resume what I understand of it first:
- You want to do a maze-kind-of-thing where you have secret doors all around
- Some kind of activator (plates, levers, etc) do change the secret doors to a number of configurations
If this is the case you probably can do as following.
1) Define a table of tables for configurations:
Code: Select all
DOORSPATTERNS =
{
["config1"] = { "secret_door_1", "secret_door_5", "secret_door_7" },
["config2"] = { "secret_door_11", "secret_door_25", "secret_door_37" },
["config4"] = { "secret_door_2", "secret_door_5", "secret_door_7" },
}
ALLDOORS = { "secret_door_1", "secret_door_5", "secret_door_7", ....... etc etc etc }
2) Have an activate configuration method:
Code: Select all
function activatePattern(patternName)
for _, doorName in ipairs(ALLDOORS) do
local door = findEntity(doorName)
door:close()
end
for _, doorName in ipairs(DOORSPATTERNS[patternName]) do
local door = findEntity(doorName)
door:open()
end
end
3) find some way (whatever you want) to call activatePattern("config1") etc. etc.
Notes:
- There is no need to stay all-lower-case inside a scripting entity. Use whatever makes the code clearer (I usually stay with the convention that read-only values are all-upper-case).
- The code above is NOT TESTED.
- Never put objects inside table, always put the id of the objects - otherwise GrimRock crashes when saving.
- Always test the code in the game at regular intervals in time (say, once a day), including saving and reloading.
--
Edited for various fixes.