Previous Thread
Next Thread
Print Thread
Using lua scripts within layout #117739 08/27/20 06:57 PM
Joined: Nov 2006
Posts: 12
E
elcondor Offline OP
Member
OP Offline
Member
E
Joined: Nov 2006
Posts: 12
As part of my attempt to make some of these new gambling games actually playable, I'm trying to use LUA scripting to take the lamp data used as segments for an LED display and convert it. I've seen the one example that features, and I thought I was doing what should work, but it seems to have no effect.

Taking the example of Double Take (v4dbltak)

Code
<script>
	local layout = {}

	local ledlamps = { 	{ 88, 89, 90, 91, 92, 93, 94, -1 },
						{ 80, 81, 82, 93, 84, 85, 86, 87 },
						{ 72, 73, 74, 75, 76, 77, 78, -1 },
						{ 64, 65, 66, 67, 68, 69, 70, -1 }  }

	function layout.reset()
		for led=0,3 do
			machine:outputs():set_indexed_value("compoundled", led, 0)
			return
		end
	end

	function layout.frame()
		for led=0,3 do
			local temp_state = 0
			for lamp=0,7 do
				local lampval = ledlamps[led][lamp] 
				if (lampval > -1) then do
					local lampstate = machine:outputs():get_indexed_value("lamp", lampval)
					if (lampstate > 0) then do
						temp_state = temp_state | (1 &lt;&lt; lamp)
					end
				end
			end
			machine:outputs():set_indexed_value("compoundled", led, temp_state)
			return
		end
	end
end
return layout, "v4dbltak"
</script>


This uses the ledlamps as a multi dimensional table, and is meant to be reading whether the relevant lamps have been set, using that to set bits for an element called compoundled0,1,2 or 3 accoedingly. It might be that the segments are in the wrong order, but currently it seems to not run at all.
I'm finding it very hard to find any primer on this, so it may be that I'm overdoing what is available (obviously the layout continues beyond here, but I just wanted to show the LUA portion).

Re: Using lua scripts within layout [Re: elcondor] #117740 08/27/20 07:42 PM
Joined: Feb 2014
Posts: 484
G
Golden Child Offline
Senior Member
Offline
Senior Member
G
Joined: Feb 2014
Posts: 484
I can't remember (since I haven't messed with it for awhile) but

Did you activate the layout plugin?

-plugin layout

Try sticking in a print statement to see if anything happens on the console.

Re: Using lua scripts within layout [Re: elcondor] #117743 08/28/20 02:30 PM
Joined: Nov 2006
Posts: 12
E
elcondor Offline OP
Member
OP Offline
Member
E
Joined: Nov 2006
Posts: 12
I have a feeling I may not have compiled the plugin in, I was testing with an incomplete build. If that is all it is, that makes a lot more sense than what I was thinking of.

Re: Using lua scripts within layout [Re: elcondor] #117744 08/28/20 03:30 PM
Joined: Mar 2001
Posts: 16,594
R
R. Belmont Offline
Very Senior Member
Offline
Very Senior Member
R
Joined: Mar 2001
Posts: 16,594
You don't have to compile Lua plugins, you just "-plugin layout" as GC said.

Re: Using lua scripts within layout [Re: elcondor] #117745 08/28/20 06:57 PM
Joined: Nov 2006
Posts: 12
E
elcondor Offline OP
Member
OP Offline
Member
E
Joined: Nov 2006
Posts: 12
Ah, I see what was going wrong before, because I wasn't calling the plugin it wasn't loading anything. it all works now, so I might be able to put together this as a tech demo at least.


Who's Online Now
0 registered members (), 49 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
ShoutChat Box
Comment Guidelines: Do post respectful and insightful comments. Don't flame, hate, spam.
Forum Statistics
Forums9
Topics8,820
Posts116,117
Members4,921
Most Online890
Jan 17th, 2020
Powered by UBB.threads™ PHP Forum Software 7.7.3