Page 1 of 1

Help needed with setting up Puzzle (lua based)

Posted: Sat Jan 31, 2009 5:26 pm
by Sky_216
Well, once again I need help with lua stuff for campaign.
Here's what I'm trying to achieve:

For the 'commando' part of my campaign, I'm trying to set up a 'puzzle with four high intensity scanners. They can't be passed unless you hack the corresponding terminal.
There are four scanner arrays. Each one consisits of prop objects, a damageregion (eg 'scanner1'), a bunch of effect objects (1 for each beam, eg called 's1_b1', 's1_b2', 's1_b3' , 's1_b4', 's1_b5').

Each scanner has a terminal that when 'hacked' (actually destroyed with a fusion cutter), disables it - removes the s1_b1-5 effect objects and the damageregion.

The tricky bit is getting the 'puzzle' part to work - only one scanner can be disabled at any one time. So hacking a terminal not only disables the scanner connected to it, but also respawns (if possible) all the other scanner's effect objects and regions.

Anywy, any help on the lua coding I should use (and even how to 'nest' it properly, I'm not very good at that) would be appreciated.

Re: Help needed with setting up Puzzle (lua based)

Posted: Sat Jan 31, 2009 8:07 pm
by Grev
I'm using a similar type of code for a gamemode I'm making, and while I don't have the script on hand, look at the space assault scripts, they will have the code for disabling something when an object it destroyed: (like the ngines inside and outside a capital ship).

Re: Help needed with setting up Puzzle (lua based)

Posted: Sat Jan 31, 2009 8:38 pm
by Maveritchell
Rather than write it out for you, I'll suggest that you download my Spira script. It's got a lot of examples for different types of puzzle setups (and I refer to it regularly, too). I uploaded it with a lot of other assets from Spira, and it can be found in the Assets forum; if you prefer to just download the script (I know you're on a download budget), use this link:
http://files.filefront.com/FFXg+elilua/ ... einfo.html

Re: Help needed with setting up Puzzle (lua based)

Posted: Sun Feb 01, 2009 12:27 am
by [RDH]Zerted
Maveritchell wrote:...my Spira script...
Wow, 5820 lines. Programming Tip: When you find yourself copying and pasting code, you can generally change your design slightly (like by using tables) and remove all the copied code.

The best way to design your puzzle is to use tables of all things that change and functions that do one type of action for a given table. However without knowing exactly how you want everything, that is hard to correctly describe over a few forum posts.

Instead, create functions for everything you want to do. You would have a function to disable scanner 1, enable scanner 1, disable scanner 2, etc... The disable/enable scanner functions would change all of that scanner's effects. (that table method would be like having only one function to disable a scanner and only one to enable a scanner. Then you would pass the table of scanner 2 into the enable scanner function to enable scanner 2. But i'm not telling you to do it that way.)

At the next 'higher level', create a function that takes the 'name' of a scanner. When you call this function, it should call the functions to enable all the other scanners and the function to disable the named scanner.

At the next 'higher/top level', you have your event call-back. When a scanner object is destroyed, call the 'lower function' with the name of the scanner that was destroyed.

Note: The 'higher level' and 'lower level' are just ideas and have no effect on code placement within the script file itself.

Re: Help needed with setting up Puzzle (lua based)

Posted: Sun Feb 01, 2009 12:33 am
by Maveritchell
[RDH]Zerted wrote:
Maveritchell wrote:...my Spira script...
Wow, 5820 lines. Programming Tip: When you find yourself copying and pasting code, you can generally change your design slightly (like by using tables) and remove all the copied code.
I know it's inefficient code - at the time, though, it was easier. You'd know better than I, but as far as learning goes, I feel that it was easier to learn how to actually make happen what I wanted to happen first, and then learn how to make my code less bulky second.

However, I like to use that fat script as a demonstration because all the code is written out - I think it makes reading single sections at a time easier (if perhaps more difficult to find).

Re: Help needed with setting up Puzzle (lua based)

Posted: Sun Feb 01, 2009 12:48 am
by Sky_216
Thanks Mav, didn't realise you released the script. And you're right, it'll help more than you spelling out what I should do (help's me learn + saves you time). Thanks again.