Page 29 of 396
Re: Ask a simple question, get a simple answer
Posted: Tue Dec 09, 2014 4:37 am
by GoldenShadowGS
Grimfan wrote:Not quite. Each button is on a 30 second timer. If the button isn't pressed in time it and all previously spawned buttons are destroyed.
Is this repeatable? or a one off?
Re: Ask a simple question, get a simple answer
Posted: Tue Dec 09, 2014 4:45 am
by Grimfan
Not repeatable ATM. Having it be repeatable would be great but it was a little too much for my simple lua brain.
I was destroying the buttons individually with separate timers but I didn't want a lot of timers going all at once. Trouble is I'm so used to the old ways of destroying objects I'm finding the transition difficult.
Re: Ask a simple question, get a simple answer
Posted: Tue Dec 09, 2014 4:56 am
by GoldenShadowGS
Grimfan wrote:Not repeatable ATM. Having it be repeatable would be great but it was a little too much for my simple lua brain.
I was destroying the buttons individually with separate timers but I didn't want a lot of timers going all at once. Trouble is I'm so used to the old ways of destroying objects I'm finding the transition difficult.
Here is something I whipped up real quick, I removed some of your lines, but you can add them back in where the comments show. I haven't tested it, so it may not work without some tweaks if I messed up a syntax.
Code: Select all
count = 0
runonce = false
stopcount = false
function pressButton(button)
if button.go.id == "button_0" then
--do stuff here if button 0 was pressed
spawn("wall_button", 8, 11, 11, 2, 0, "button_1").clickable:addConnector("onClick", "self.go.id", "pressButton")
count = 0
if runonce == false then
runonce = true
counter()
end
elseif button.go.id == "button_1" then
--do stuff here if button 1 was pressed
count = 0
spawn("wall_button", 8, 5, 17, 3, 0, "button_2").clickable:addConnector("onClick", "script_entity_25", "pressButton")
elseif button.go.id == "button_2" then
--do stuff here if button 2 was pressed
count = 0
spawn("wall_button", 8, 22, 3, 3, 0, "button_3").clickable:addConnector("onClick", "script_entity_25", "pressButton")
elseif button.go.id == "button_3" then
--do stuff here if button 3 was pressed
count = 0
spawn("wall_button", 8, 7, 5, 2, -1, "button_4").clickable:addConnector("onClick", "script_entity_25", "pressButton")
elseif button.go.id == "button_4" then
--do stuff here if button 4 was pressed
count = 0
spawn("wall_button", 8, 1, 17, 1, 0, "button_5").clickable:addConnector("onClick", "script_entity_25", "pressButton")
elseif button.go.id == "button_5" then
--do stuff here if button 5 was pressed
count = 0
stopcount = true
end
end
function counter()
--script timer increments once per second
if stopcount == false then
delayedCall(self.go.id, 1, "counter")
counter = counter + 1
if counter == 30 then
stopcount == true
if wall_button_1 ~= nil then
wall_button_1:destroy()
end
if wall_button_2 ~= nil then
wall_button_2:destroy()
end
if wall_button_3 ~= nil then
wall_button_3:destroy()
end
if wall_button_4 ~= nil then
wall_button_4:destroy()
end
if wall_button_4 ~= nil then
wall_button_4:destroy()
end
if wall_button_5 ~= nil then
wall_button_5:destroy()
end
end
end
end
Re: Ask a simple question, get a simple answer
Posted: Tue Dec 09, 2014 5:07 am
by Grimfan
Thanks a lot GoldenShadow. I will try out your code.
Re: Ask a simple question, get a simple answer
Posted: Tue Dec 09, 2014 5:44 am
by Grimfan
Tried the script.
Code: Select all
function counter()
--script timer increments once per second
if stopcount == false then
delayedCall(self.go.id, 1, "counter")
counter = counter + 1
Unfortunately, it's telling me that it can't perform arithmetic on a global counter (a function value). I'm assuming that has something to do with the function name being counter?
Of course, if I change function counter to function counterButton or something else I get a different error -- attempt to call a global counter.
Code: Select all
count = 0
runonce = false
stopcount = false
function pressButton(button)
if button.go.id == "button_0" then
dd_1.door:open()
spawn("wall_button", 8, 11, 11, 2, 0, "button_1").clickable:addConnector("onClick", "self.go.id", "pressButton")
count = 0
if runonce == false then
runonce = true
counter() -- this line here causes the error
end
Re: Ask a simple question, get a simple answer
Posted: Tue Dec 09, 2014 5:54 am
by GoldenShadowGS
you're right, change all instance of "counter" to count except for the function, counter()
Code: Select all
function counter()
--script timer increments once per second
if stopcount == false then
delayedCall(self.go.id, 1, "counter")
count = count + 1
if count == 30 then
stopcount == true
if wall_button_1 ~= nil then
wall_button_1:destroy()
end
if wall_button_2 ~= nil then
wall_button_2:destroy()
end
if wall_button_3 ~= nil then
wall_button_3:destroy()
end
if wall_button_4 ~= nil then
wall_button_4:destroy()
end
if wall_button_4 ~= nil then
wall_button_4:destroy()
end
if wall_button_5 ~= nil then
wall_button_5:destroy()
end
end
end
end
Re: Ask a simple question, get a simple answer
Posted: Tue Dec 09, 2014 8:33 am
by Grimfan
Thanks a lot GoldenShadow. With a little bit of fiddling I've got it working fantastically.
Yet another credit on my mod list. It's growing a bit.
Re: Ask a simple question, get a simple answer
Posted: Tue Dec 09, 2014 8:46 am
by TheLastOrder
GoldenShadowGS wrote:You can remove the connectors from the alcove.
Fill in the correct details and place this in the function somewhere
Code: Select all
alcove_1.surface:removeConnector("onRemoveItem", "Script_entity_1", "function")
alcove_1 is whatever your alcove ID is named
"Script_entity_1" is what entity the connector is connected to
"function" is a script function, if targeting a script, or an action like "close" if its targeting a door. Just put here what the connector shows.
Epic solution. So it was a way to do it... another credit,as Grimfan said
Re: Ask a simple question, get a simple answer
Posted: Wed Dec 10, 2014 2:51 am
by Grimfan
I thought something was a little fishy while testing this script so set the count to 5 seconds. I found that the script works, but only works once.
Can someone with better coding eyes than me tell me what's stopping it from running more than once? It's probably one line I'm overlooking because I'm a newbie scripter.
Code: Select all
count = 0
runonce = false
stopcount = false
function pressButton(button)
if button.go.id == "button_0" then
dd_1.door:open()
daemon_head_speaking_1.walltext:setWallText(" ")
spawn("wall_button", 8, 11, 11, 2, 0, "button_1").clickable:addConnector("onClick", "script_entity_25", "pressButton")
button_0.clickable:disable()
count = 0
if runonce == false then
runonce = true
counter()
end
elseif button.go.id == "button_1" then
dd_2.door:open()
daemon_head_speaking_1.walltext:setWallText(" ")
count = 0
spawn("wall_button", 8, 5, 17, 3, 0, "button_2").clickable:addConnector("onClick", "script_entity_25", "pressButton")
button_1.clickable:disable()
elseif button.go.id == "button_2" then
dd_3.door:open()
daemon_head_speaking_1.walltext:setWallText(" ")
count = 0
spawn("wall_button", 8, 22, 3, 3, 0, "button_3").clickable:addConnector("onClick", "script_entity_25", "pressButton")
button_2.clickable:disable()
elseif button.go.id == "button_3" then
dd_4.door:open()
daemon_head_speaking_1.walltext:setWallText(" ")
count = 0
spawn("wall_button", 8, 7, 5, 2, -1, "button_4").clickable:addConnector("onClick", "script_entity_25", "pressButton")
button_3.clickable:disable()
elseif button.go.id == "button_4" then
dd_5.door:open()
daemon_head_speaking_1.walltext:setWallText(" ")
count = 0
spawn("wall_button", 8, 1, 17, 1, 0, "button_5").clickable:addConnector("onClick", "script_entity_25", "pressButton")
button_4.clickable:disable()
elseif button.go.id == "button_5" then
dd_6.door:open()
button_5.clickable:disable()
count = 0
stopcount = true
end
end
function counter()
--script timer increments once per second
if stopcount == false then
delayedCall(self.go.id, 1, "counter")
count = count + 1
if count == 5 then
stopcount = true
if button_0.clickable ~= nil then
button_0.clickable:enable()
end
if button_1 ~= nil then
button_1:destroy()
end
if button_2 ~= nil then
button_2:destroy()
end
if button_3 ~= nil then
button_3:destroy()
end
if button_4 ~= nil then
button_4:destroy()
end
if button_5 ~= nil then
button_5:destroy()
end
end
end
end
Thanks in advance!
By the way, I think this is supposed to run more than once but now I'm not so sure.
Re: Ask a simple question, get a simple answer
Posted: Wed Dec 10, 2014 8:38 am
by GoldenShadowGS
Grimfan wrote:I thought something was a little fishy while testing this script so set the count to 5 seconds. I found that the script works, but only works once.
Can someone with better coding eyes than me tell me what's stopping it from running more than once? It's probably one line I'm overlooking because I'm a newbie scripter.
Code: Select all
count = 0
runonce = false
stopcount = false
function pressButton(button)
if button.go.id == "button_0" then
dd_1.door:open()
daemon_head_speaking_1.walltext:setWallText(" ")
spawn("wall_button", 8, 11, 11, 2, 0, "button_1").clickable:addConnector("onClick", "script_entity_25", "pressButton")
button_0.clickable:disable()
count = 0
if runonce == false then
runonce = true
counter()
end
elseif button.go.id == "button_1" then
dd_2.door:open()
daemon_head_speaking_1.walltext:setWallText(" ")
count = 0
spawn("wall_button", 8, 5, 17, 3, 0, "button_2").clickable:addConnector("onClick", "script_entity_25", "pressButton")
button_1.clickable:disable()
elseif button.go.id == "button_2" then
dd_3.door:open()
daemon_head_speaking_1.walltext:setWallText(" ")
count = 0
spawn("wall_button", 8, 22, 3, 3, 0, "button_3").clickable:addConnector("onClick", "script_entity_25", "pressButton")
button_2.clickable:disable()
elseif button.go.id == "button_3" then
dd_4.door:open()
daemon_head_speaking_1.walltext:setWallText(" ")
count = 0
spawn("wall_button", 8, 7, 5, 2, -1, "button_4").clickable:addConnector("onClick", "script_entity_25", "pressButton")
button_3.clickable:disable()
elseif button.go.id == "button_4" then
dd_5.door:open()
daemon_head_speaking_1.walltext:setWallText(" ")
count = 0
spawn("wall_button", 8, 1, 17, 1, 0, "button_5").clickable:addConnector("onClick", "script_entity_25", "pressButton")
button_4.clickable:disable()
elseif button.go.id == "button_5" then
dd_6.door:open()
button_5.clickable:disable()
count = 0
stopcount = true
end
end
function counter()
--script timer increments once per second
if stopcount == false then
delayedCall(self.go.id, 1, "counter")
count = count + 1
if count == 5 then
stopcount = true
if button_0.clickable ~= nil then
button_0.clickable:enable()
end
if button_1 ~= nil then
button_1:destroy()
end
if button_2 ~= nil then
button_2:destroy()
end
if button_3 ~= nil then
button_3:destroy()
end
if button_4 ~= nil then
button_4:destroy()
end
if button_5 ~= nil then
button_5:destroy()
end
end
end
end
Thanks in advance!
By the way, I think this is supposed to run more than once but now I'm not so sure.
What are the reset conditions? when the timer elaspes or when the last button is pressed?