Page 2 of 4
Re: Script: Make Multiple Buttons/Levers
Posted: Sat Nov 15, 2014 9:25 pm
by cromcrom
Great Scripting Lark, thanks a lot
I have a question, what calls makeControls(caller, control, base, size, space, omit) if I want the buttons or things like that to appear somewhere? Could you provide a quick short installation guide please ?
Re: Script: Make Multiple Buttons/Levers
Posted: Mon Nov 17, 2014 12:13 am
by Lark
Sorry I wasn't clear on that - here's what you do:
- Create a LUA script entity in the square that is to have the buttons/levers. Let's say buttons for the examples. The buttons will appear in the same square as the LUA script. The wall on which the buttons appear will depend upon which direction the script is facing.
- Three functions and one initialization call were included in the original example.
- makeControls - actually places the controls
- buttonPress - gets called when any button is pressed; button ID is passed as a parameter
- leverFlip - gets called when any lever is flipped; lever ID is passed as a parameter
- The buttons are actually created by the last line in the script: makeControls(self, "wall_button", self.go.id .."_button_", {3, 3}, {.4, -.4, .4, -.4}, {21, 23, 12, 32}) is one included example.
So, in summary, just create a LUA script in the square where you want the buttons, copy and paste the script I wrote into your script entity. Change the script's facing direction to get your controls on the wall you desire, change the very last line to define your buttons/levers. Duplicate this line and alter it for every group of controls you want on the same wall - see my button and lever example at the beginning. Then alter the
buttonPress and
leverFlip routines to do whatever you want when the controls are activated. Alternately, you can alter the
addConnector statements in the main function.
Does this answer your questions? Take care,
-Lark
Re: Script: Make Multiple Buttons/Levers
Posted: Sat Nov 29, 2014 1:44 pm
by cromcrom
You sure did. This is amazing, and so helpfull. Hello, crafting station
Thank you so much for sharing
Oh, and I credited you oc

Re: Script: Make Multiple Buttons/Levers
Posted: Thu Jan 08, 2015 5:00 pm
by THOM
Well, I am not very smart in scripting, so this is some kind of miracle for me, Lark.
I could get this running in my mod and I could alter the appearance. But I do not understand how to make the buttons to do something.
So - what I have are three buttons in a vertical row and I want button A to trigger script A, button B to trigger script B and so...
Can someone give me a clue how to script that?
Re: Script: Make Multiple Buttons/Levers
Posted: Sun Jan 11, 2015 7:06 pm
by THOM
Bump..

Re: Script: Make Multiple Buttons/Levers
Posted: Sun Jan 11, 2015 10:29 pm
by Isaac
THOM wrote:So - what I have are three buttons in a vertical row and I want button A to trigger script A, button B to trigger script B and so...
Can someone give me a clue how to script that?
The function buttonPress() is where the button or lever's action originates. The variable *pressed* is a local numerical id derived for the button; use it to script a block in the buttonPress() function, that either contains or calls your scripted action for each button.
Here is one method:
Replace Lark's buttonPress(), and the call to makeControls() [at the very end of the script] with these snippets. It will setup three [centered] buttons, and will call the function myFunc() in script_A, script_B, and script_C; which have to exist on the map.
Or... You can replace either or each *script_#.script.myFunc(pushed)* call with something like my_door_1.door:toggle() to have the button open and close the my_door object.
Code: Select all
function buttonPress(my)
local pushed = tonumber(string.sub(my.go.id, string.len(my.go.id) - 1))
--=|--------------------------------------------------------------------------------------------------------
local buttonAction = { [12] = function() script_A.script.myFunc(pushed) end,
[22] = function() script_B.script.myFunc(pushed) end,
[32] = function() script_C.script.myFunc(pushed) end,
}
buttonAction[pushed]()
--=|--------------------------------------------------------------------------------------------------------
end
Code: Select all
--=|----place below leverFlip()------------------------------------------------------------------------------------
makeControls(self, "wall_button", self.go.id .."_button_", {3, 3}, {.4, -.4, .4, -.4}, {11,21,33,13,23,31,33})
--=|--------------------------------------------------------------------------------------------------------
A simple template for script_A:
Code: Select all
--name object script_A
function myFunc(pushed)
playSound("secret") hudPrint("Button Pressed "..pushed)
end
If you want to change the arrangement of the buttons, look at the last parameter in the call to makeControls() [omit]; this removes buttons that you don't want. In the above script... the {11,21,33,13,23,31,33} table lists all the buttons not down the center in the 3x3 grid; seen as {3, 3} in the script. The numbers in the omit table are the rows & columns; so the first [top left] button is 11 ~for column 1, row 1.
Re: Script: Make Multiple Buttons/Levers
Posted: Sun Jan 11, 2015 10:44 pm
by THOM
thanks, Isaac. That helps a lot.
Re: Script: Make Multiple Buttons/Levers
Posted: Sun Jan 11, 2015 10:47 pm
by Isaac
It's a neat script; I'm still looking at it. I've not tried using levers yet. The hoops one had to jump through for multiple levers in LoG1 were insane.
Re: Script: Make Multiple Buttons/Levers
Posted: Fri Apr 10, 2015 12:26 am
by Duncan1246
Lark wrote: makeControls(self, "wall_button", self.go.id .."_button_", {3, 3}, {.4, -.4, .4, -.4}, {21, 23, 12, 32})
Hi Lark,
I use your script in my mod, it works fine, thanks you for this nice work!
I needs to use runes-buttons (same as "wall_button" but with a rune instead of the LOG1 logo, named "wall_button_fire", ..., etc. I understand that I have to modify the function "makeControls", but I don't know if it's actually possible without a more complex script. What do you think?
Duncan
Re: Script: Make Multiple Buttons/Levers
Posted: Fri Apr 10, 2015 3:34 am
by Isaac
Duncan1246 wrote:I needs to use runes-buttons (same as "wall_button" but with a rune instead of the LOG1 logo, named "wall_button_fire", ..., etc.
The best way to have the runes, is to change the texture on the material... but that's not the easiest way. The second best
, is to edit the model in blender an add the rune as a plane, one unit in front of the button face. It will cover the logo, rather than replace it.
To alter the textures, you could use Blender to bake the changes to the material(s); or you could use Photoshop/Gimp along with the normal map plug-in; to fake the baked results.