Page 1 of 1
Need some help with scripting.
Posted: Wed Nov 07, 2012 5:43 pm
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.
Re: Need some help with scripting.
Posted: Wed Nov 07, 2012 5:51 pm
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.
Re: Need some help with scripting.
Posted: Wed Nov 07, 2012 8:17 pm
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.
Re: Need some help with scripting.
Posted: Wed Nov 07, 2012 8:51 pm
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
Re: Need some help with scripting.
Posted: Wed Nov 07, 2012 10:04 pm
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.
Re: Need some help with scripting.
Posted: Wed Nov 07, 2012 11:16 pm
by zadkielmodeler
Thank you so much. It works so well.