Need some help with scripting.

Talk about creating Grimrock 1 levels and mods here. Warning: forum contains spoilers!
Post Reply
zadkielmodeler
Posts: 43
Joined: Sat Sep 15, 2012 6:34 am

Need some help with scripting.

Post by zadkielmodeler »

Originally I had an idea for a puzzle where I was going to have a timer activate levers or pressure plates. And the party would have to find the secret button or something to stop the timer so that they could use the levers normally. But apparently connecting a timer node to a lever (not lever to timer) does not work or do anything.

So I need a work around in lua scripting. But I don't really know how to begin. I have done some programming and I have edited lua scripts, but I don't really know how to make one from scratch.
User avatar
Komag
Posts: 3659
Joined: Sat Jul 28, 2012 4:55 pm
Location: Boston, USA

Re: Need some help with scripting.

Post by Komag »

scripts can toggle levers, but can't directly affect pressure plates in like manner. You could spawn in and later destroy invisible objects to weigh down the plates, I suppose.
Finished Dungeons - complete mods to play
zadkielmodeler
Posts: 43
Joined: Sat Sep 15, 2012 6:34 am

Re: Need some help with scripting.

Post by zadkielmodeler »

I could figure this out if I knew all the action triggers. I can use the scripting reference to make something happen.
But I need to know how to set it to happen.

Like the
onTurn
onMove

a list of these sorts of triggers would be super useful.
zadkielmodeler
Posts: 43
Joined: Sat Sep 15, 2012 6:34 am

Re: Need some help with scripting.

Post by zadkielmodeler »

Komag wrote:scripts can toggle levers, but can't directly affect pressure plates in like manner. You could spawn in and later destroy invisible objects to weigh down the plates, I suppose.
That's cool, how would you toggle a lever or multiple levers with a lua script on a timer?
I am sure there is a for loop of some kind involved.

okay I am going to try to code it. double check my work here. Again keyword here is TRY.

function1()
for i = 5, 10, 0 do
Lever1:Toggle()
Lever2:Toggle()
if Secret_button1:push() then
i = 10
else
end
end
User avatar
crisman
Posts: 305
Joined: Sat Sep 22, 2012 9:23 pm
Location: Italy

Re: Need some help with scripting.

Post by crisman »

zadkielmodeler wrote:
Komag wrote:scripts can toggle levers, but can't directly affect pressure plates in like manner. You could spawn in and later destroy invisible objects to weigh down the plates, I suppose.
That's cool, how would you toggle a lever or multiple levers with a lua script on a timer?
I am sure there is a for loop of some kind involved.

okay I am going to try to code it. double check my work here. Again keyword here is TRY.

function1()
for i = 5, 10, 0 do
Lever1:Toggle()
Lever2:Toggle()
if Secret_button1:push() then
i = 10
else
end
end
I can try to give you some help.
about the pressure plate, I think Komag is right, you cannot operate them via script - so the spawned object are a good way-, but you can operate levers and buttons with the script lever:toggle() and button:push()
For the secret button, as far as I know, the game can't tell if a button has been pushed or not, so you must connect it to a counter and use its value to tell (0 = not pushed, 1 = pushed).
The script you wrote... well, I bet the game will freeze and you will get a stack overflow error. You use the for loop but it will never ends - at least not in cpu time. ;)
A way to do it is to create a timer and connect it to a script.
the script should be something like:

Code: Select all

function leveraction()

lever1:toggle()
lever2:toggle()

end
or, if you have a lot of lever, like 10, it can be something like this

Code: Select all

function leveraction()

for i = 1, 10 do
findEntity("lever"..i):toggle()
end

end
(but this is a bit much more complicated)

And the secret button is connected to the timer, and when is pressed, it must stop it.
zadkielmodeler
Posts: 43
Joined: Sat Sep 15, 2012 6:34 am

Re: Need some help with scripting.

Post by zadkielmodeler »

Thank you so much. It works so well.
Post Reply