Page 3 of 3

Re: LED Wall Display: 0 - 99

Posted: Fri Dec 05, 2014 10:44 pm
by trancelistic
Isaac wrote:Fixed. Image

Code: Select all

  ---[[
  ---------------------------------------------------------------------------------------
    ---  LED display:  version 1.4.1  10-10-2012     Written by Lark                    ---
    ---                                              Much thanks to:  Lmaoboat          ---
    ---------------------------------------------------------------------------------------

    ---
    ---  Light Parameters
    ---
    displayed = self.level       --the initial number displayed by the script
    wall = self.facing           --adjust wall used for display from script's facing; i.e. opposite = (self.facing + 2) % 4
    initallyOn = true            --specify if the light is initially on

    vertical_spacing = .17       --vertical LED spacing
    horizontal_spacing = .15     --horizontal LED spacing; center, left, & right values are based on this number being .15
    height = 3                   --height above the floor for the top row of LEDs
    center = -.3                 --start of row offset for single digit displays
    left = -.85                  --start of row offset for left digit
    right = .25                  --start of row offset for right digit

    ---  Usage:
    --- 
    ---  1.  drop this script into a square facing the wall where the display is desired (or adjust "wall" above)
    ---  2.  set parameters to suit:  displayed, wall, and initiallyOn for basic parameters
    ---  3.  on() to display the initial value
    ---  4.  off() to turn off lights
    ---  5.  add() to increment by one
    ---  6.  sub() to decrement by one
    ---  7.  display(number) to set the display to a new number
    ---  8.  do not call digit() directly

    ---
    ---  Create a LED panel for numbers 0 - 99.  LED grid is:
    ---

    --   00 01 02 03 04
    --   05 06 07 08 09
    --   10 11 12 13 14
    --   15 16 17 18 19
    --   20 21 22 23 24
    --   25 26 27 28 29
    --   30 31 32 33 34

    digits = 
	{
      {1,2,3,5,9,10,14,15,19,20,24,25,29,31,32,33},
      {6,2,7,12,17,22,27,31,32,33},
      {5,1,2,3,9,14,18,22,26,30,31,32,33,34},
      {5,1,2,3,9,14,18,17,16,24,29,33,32,31,25},
      {0,5,10,15,16,17,18,19,3,8,13,23,28,33},
      {4,3,2,1,0,5,10,15,16,17,18,24,29,33,32,31,30},
      {9,3,2,1,5,10,15,20,25,31,32,33,29,24,18,17,16},
      {5,0,1,2,3,4,9,14,18,22,27,32},
      {10,5,1,2,3,9,14,18,17,16,20,25,31,32,33,29,24},
      {25,31,32,33,29,24,19,14,9,3,2,1,5,10,16,17,18}
	}


    led = {nil}
    cos = math.cos(1.5707963267949 * wall)
    sin = math.sin(1.5707963267949 * wall)
    tz = 1.3

    ---
    ---  divide into digits and display in correct sector
    ---
    function display(number)
      if number == nil then return end
      local b = number % 10
      local a = (number - b) / 10
      off()

      if a > 0 then
        digit(a, left)
        digit(b, right)
      else
        digit(b, center)
        end
      displayed = number
      end

    ---
    ---  display a digit of the number at the given alignment and light set
    ---
    function digit(number, align)
		
		local dix = number + 1

      for ix = 1, 35 do
        local pix = digits[dix][ix]
    	
	  if pix == nil then return end
	 
        local tx = align + pix % 5 * horizontal_spacing
        lix = lix + 1

  -- Fixed ======[ You cannot serialize a table of objects; but you can with a table of names. ]===================================================
	     	led[lix] = spawn("fx", self.level, self.x, self.y, 3, self.id..lix).id
  		findEntity(led[lix]):setLight(1, 0, 0, 1500, 0.24, 360000, false)
         	findEntity(led[lix]):translate(tx * cos + tz * sin, height - math.floor(pix / 5) * vertical_spacing - 1, tz * cos + tx * sin * (1 - wall%2 * 2))
  --=====================================================================================================================================     
 		end

      end

    ---
    ---  add one to the current display w/ wrap
    ---
    function add()
      display((displayed + 1)%100)
      end

    ---
    ---  subtract one from the current display w/ wrap
    ---
    function sub()
      display((displayed + 99)%100)
      end

    ---
    ---  turn lights off
    ---
    function off()
      if lix ~= nil then
        for dix = 1, lix do
          led[dix]:destroy()
          end
        end
      lix = 0
      led = {nil}
     end

    ---
    ---  turn lights on
    ---
    function on()
      display(displayed)
      end

    ---
    ---  turn lights on if specified in parameters
    ---
    if initallyOn then on() end
--]]

Dude you''re a genius. How did you manage to see my problem and how did you fixed it?

Respect and greetz from me<3

Re: LED Wall Display: 0 - 99

Posted: Tue Dec 09, 2014 11:05 pm
by Lark
I've been gone too long, sorry about that. Thanks Isaac for fixing the blunder - it's a novice mistake that I should have caught, but this was one of my first big scripts. I updated your code to remove unneeded findEntity calls by using a local light variable and I added a findEntity call to the off routine.

[EDIT]
This is code was exported in a real dungeon and tested across saves and it works - almost. The game does not crash and everything is good, except that the LEDs are off. The script isn't rerun, apparently, so the initiallyOn value doesn't cause on() to be called again, so the LEDs are off. When I get time, I'll try to solve that as all is needed is another call to on() when the game is reloaded. Work, family, church, exercise, and LoG2 are taking most of my time. :)

SIncerely, -Lark

Code: Select all

---------------------------------------------------------------------------------------
---  LED display:  version 1.4.3  12-9-2014      Written by Lark                    ---
---                                              Much thanks to:  Lmaoboat          ---
---------------------------------------------------------------------------------------

---
---  Light Parameters
---
displayed = self.level       --the initial number displayed by the script
wall = self.facing           --adjust wall used for display from script's facing; i.e. opposite = (self.facing + 2) % 4
initallyOn = true            --specify if the light is initially on

vertical_spacing = .17       --vertical LED spacing
horizontal_spacing = .15     --horizontal LED spacing; center, left, & right values are based on this number being .15
height = 3                   --height above the floor for the top row of LEDs
center = -.3                 --start of row offset for single digit displays
left = -.85                  --start of row offset for left digit
right = .25                  --start of row offset for right digit

---  Usage:
---
---  1.  drop this script into a square facing the wall where the display is desired (or adjust "wall" above)
---  2.  set parameters to suit:  displayed, wall, and initiallyOn for basic parameters
---  3.  on() to display the initial value
---  4.  off() to turn off lights
---  5.  add() to increment by one
---  6.  sub() to decrement by one
---  7.  display(number) to set the display to a new number
---  8.  do not call digit() directly
---
---  Version 1.4.3:   
---    * Fixed issue of storing objects in a non-local table; now just store the object name (Thanks Isaac)
---    * Updated "off" routine to handle names instead of objects.
---    * Removed bad "null" and replaced with "nil" - mixed up LUA and another language...
---    * Improved error checking in the "off" routine - avoids crashes in strange circumstances

---
---  Create a LED panel for numbers 0 - 99.  LED grid is:
---

--   00 01 02 03 04
--   05 06 07 08 09
--   10 11 12 13 14
--   15 16 17 18 19
--   20 21 22 23 24
--   25 26 27 28 29
--   30 31 32 33 34

digits = {
    {1,2,3,5,9,10,14,15,19,20,24,25,29,31,32,33},
    {6,2,7,12,17,22,27,31,32,33},
    {5,1,2,3,9,14,18,22,26,30,31,32,33,34},
    {5,1,2,3,9,14,18,17,16,24,29,33,32,31,25},
    {0,5,10,15,16,17,18,19,3,8,13,23,28,33},
    {4,3,2,1,0,5,10,15,16,17,18,24,29,33,32,31,30},
    {9,3,2,1,5,10,15,20,25,31,32,33,29,24,18,17,16},
    {5,0,1,2,3,4,9,14,18,22,27,32},
    {10,5,1,2,3,9,14,18,17,16,20,25,31,32,33,29,24},
    {25,31,32,33,29,24,19,14,9,3,2,1,5,10,16,17,18}
  }

led = {nil}
cos = math.cos(1.5707963267949 * wall)
sin = math.sin(1.5707963267949 * wall)
tz = 1.3

---
---  divide into digits and display in correct sector
---
function display(number)
  if number == nil then return end
  local b = number % 10
  local a = (number - b) / 10
  off()

  if a > 0 then
    digit(a, left)
    digit(b, right)
  else
    digit(b, center)
    end
  displayed = number
  end

---
---  display a digit of the number at the given alignment and light set
---
function digit(number, align)
  local dix = number + 1
  for ix = 1, 35 do
    local pix = digits[dix][ix]
    if pix == nil then return end
    local tx = align + pix % 5 * horizontal_spacing
    lix = lix + 1

    local light = spawn("fx", self.level, self.x, self.y, 3, self.id.."_"..lix)
    led[lix] = light.id
    light:setLight(1, 0, 0, 1500, 0.24, 360000, false)
    light:translate(tx * cos + tz * sin, height - math.floor(pix / 5) * vertical_spacing - 1, tz * cos + tx * sin * (1 - wall%2 * 2))    
    
    end
  end

---
---  add one to the current display w/ wrap
---
function add()
  display((displayed + 1)%100)
  end

---
---  subtract one from the current display w/ wrap
---
function sub()
  display((displayed + 99)%100)
  end

---
---  turn lights off
---
function off()
  if lix ~= nil and led ~= {nil} then
    for dix = 1, lix do
      local light = findEntity(led[dix])
      if light ~= nil then light:destroy() end
      end
    end
  lix = 0
  led = {nil}
 end

---
---  turn lights on
---
function on()
  display(displayed)
  end

---
---  turn lights on if specified in parameters
---
if initallyOn then on() end

Re: LED Wall Display: 0 - 99

Posted: Thu Dec 11, 2014 12:44 am
by trancelistic
Hah, I thank you both. You 2 are very nice and awesome people.

The leds on /off would be awesome ofcourse but for the moment I just like it on the on value for now.

I do not plan to make a super complicated dungeon, although hearing this do gets me motivated haha.:P

Greetz me<3

Re: LED Wall Display: 0 - 99

Posted: Mon Jun 08, 2015 10:37 pm
by trancelistic
I now. understand this.

The begin of my dungeon ( a bit later on) All work right with each floor having a led light, or 2.
So.. yeah. I though it works.
I go continue on my dugeon and pre-test it. The leds-light by your lark. Work fine. But making more floors.. or more scripts. the leds keeps more and more disapearing. Now only 2 levels work with you led light. ( it was 7 before). I have no idea why. But I think ur led light really deserve to be in a log1 mod.

Anyhows. I love it and <3 many thanks to you.
if only it woudl work on any level. I think a script of mine or some 1 has killed your led script...
I have no idea what causes the leds to go "off"... short said.
I do know your script it stable. It won't crash my mod in any way. ( I have it an all the floors.. sometimes 2 x, it used to work. in the editor and in the exported mod... now it doesnt:|( ))..

Well that is kinda it. I just want to say thank you for making the leds. You are truely awesome.
Sadly, as you've stated it doesnt always work.

Bummer:(

Re: LED Wall Display: 0 - 99

Posted: Thu Jul 16, 2015 12:15 am
by trancelistic
I have no clue what I've did. Now it doesn't work at all. Haha. Not even on the first level.
I've only worked on later levels (floors) and it stopt all together:( I really loved the led lights. Such a pro code.

In the editor it also doesn't show up anymore. Aahh. what Have I done.

ps: It doesn't crash or gives an error. Its simply not showing the leds anymore. What could interfear with this....if you got time to answer me.


Edit: I might of used Isaac's modivication ( sry my English).. I think the last script does work.


Sorry for this post. I think it works now. At least I see it again on the first level:) ( hope it works on certain spots I want it to be. Then I could use my old puzzels again)
Love you Lark and ofcourse Isaac.<3